From c10cb6643d4bc829df11343bccff4089118efd1e Mon Sep 17 00:00:00 2001 From: agorararmard Date: Tue, 16 Feb 2021 14:18:17 +0000 Subject: [PATCH 1/6] Add workflow for auto updating submodules and submitting a PR --- .github/workflows/auto-pr-submodules.yml | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/auto-pr-submodules.yml diff --git a/.github/workflows/auto-pr-submodules.yml b/.github/workflows/auto-pr-submodules.yml new file mode 100644 index 000000000..240758241 --- /dev/null +++ b/.github/workflows/auto-pr-submodules.yml @@ -0,0 +1,38 @@ +# This is a basic workflow to help you get started with Actions +name: Update Submodules and Submit a PR + +# Controls when the action will run. +on: + # Triggers the workflow on push only for the actions-test-branch branches + push: + branches: + - master + # Runs every day at midnight UTC + schedule: + - cron: '0 0 * * *' + +jobs: + createPullRequest: + if: ${{ contains(github.ref, 'master') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: submodules-init + uses: snickerbockers/submodules-init@v4 + + - name: Update All Submodules to Remote Latest + run: git submodule update --remote + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: Update All Submodules to remote latest + title: 'Update All Submodules to Remote Latest' + branch: create-pull-request/submodules-auto-update + base: master + delete-branch: true + body: This PR is auto-generated to update all submodules for all libraries in this repository. + labels: update submodules, automated pr + From ee1883b2dbcd5277f90ef69f3c77624d8340a9e0 Mon Sep 17 00:00:00 2001 From: agorararmard Date: Tue, 16 Feb 2021 16:18:40 +0000 Subject: [PATCH 2/6] remove comments --- .github/workflows/auto-pr-submodules.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/auto-pr-submodules.yml b/.github/workflows/auto-pr-submodules.yml index 240758241..09b710157 100644 --- a/.github/workflows/auto-pr-submodules.yml +++ b/.github/workflows/auto-pr-submodules.yml @@ -1,13 +1,9 @@ -# This is a basic workflow to help you get started with Actions name: Update Submodules and Submit a PR -# Controls when the action will run. on: - # Triggers the workflow on push only for the actions-test-branch branches push: branches: - master - # Runs every day at midnight UTC schedule: - cron: '0 0 * * *' From 4fd57662e661134ea9b1a910a01d6e008d8ac12d Mon Sep 17 00:00:00 2001 From: agorararmard Date: Tue, 16 Feb 2021 16:27:29 +0000 Subject: [PATCH 3/6] rely on checkout action to update submodules --- .github/workflows/auto-pr-submodules.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-pr-submodules.yml b/.github/workflows/auto-pr-submodules.yml index 09b710157..98f398551 100644 --- a/.github/workflows/auto-pr-submodules.yml +++ b/.github/workflows/auto-pr-submodules.yml @@ -13,9 +13,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - - name: submodules-init - uses: snickerbockers/submodules-init@v4 + with: + submodules: 'true' - name: Update All Submodules to Remote Latest run: git submodule update --remote @@ -24,7 +23,7 @@ jobs: uses: peter-evans/create-pull-request@v3 with: token: ${{ secrets.GITHUB_TOKEN }} - commit-message: Update All Submodules to remote latest + commit-message: Update All Submodules to Remote Latest title: 'Update All Submodules to Remote Latest' branch: create-pull-request/submodules-auto-update base: master From 3433fd994a480341cab2b76a541f032d8b4eca94 Mon Sep 17 00:00:00 2001 From: agorararmard Date: Tue, 16 Feb 2021 16:29:23 +0000 Subject: [PATCH 4/6] nicer looks in the auto submodule-update workflow --- .github/workflows/auto-pr-submodules.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-pr-submodules.yml b/.github/workflows/auto-pr-submodules.yml index 98f398551..79e30c2c6 100644 --- a/.github/workflows/auto-pr-submodules.yml +++ b/.github/workflows/auto-pr-submodules.yml @@ -9,7 +9,7 @@ on: jobs: createPullRequest: - if: ${{ contains(github.ref, 'master') }} + if: contains(github.ref, 'master') runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -22,7 +22,7 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@v3 with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ github.token }} commit-message: Update All Submodules to Remote Latest title: 'Update All Submodules to Remote Latest' branch: create-pull-request/submodules-auto-update From 9dda3c663595b40be367ddabb1752df6a192c071 Mon Sep 17 00:00:00 2001 From: agorararmard Date: Wed, 17 Feb 2021 19:11:38 +0200 Subject: [PATCH 5/6] Utilize Tim's script to create the commit and decide the body of the PR + add workflow_dispatch option --- .github/scripts/google-skywater-pdk-roll.py | 133 ++++++++++++++++++++ .github/workflows/auto-pr-submodules.yml | 15 +-- 2 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 .github/scripts/google-skywater-pdk-roll.py diff --git a/.github/scripts/google-skywater-pdk-roll.py b/.github/scripts/google-skywater-pdk-roll.py new file mode 100644 index 000000000..eb5fcfb46 --- /dev/null +++ b/.github/scripts/google-skywater-pdk-roll.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +# Copyright 2020 SkyWater PDK Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +# Originally written by Tim 'mithro' Ansell +# Slightly modified for Github Actions use by Amr Gouhar (agorararmard) + +import datetime +import os +import pprint +import subprocess +import sys +import tempfile +import textwrap +import argparse + +now = datetime.datetime.utcnow() +now = now.replace(microsecond=0) + +subprocess.check_call(['git', 'reset', '--hard']) +subprocess.check_call(['git', 'submodule', 'update', '--init']) + +parser = argparse.ArgumentParser( + description="Update submodules and create a commit") +parser.add_argument('--libraries_dir', '-l', action='store', default='libraries', + help="Libraries Directory") + +args = parser.parse_args() + +libdir = os.path.abspath(args.libraries_dir) + +changes = [] + +for lib in sorted(os.listdir(libdir)): + ldir = os.path.join(libdir, lib) + for v in sorted(os.listdir(ldir)): + submod = os.path.join(ldir, v) + + if v == 'latest': + branch = 'master' + else: + assert v.startswith('v'), v + branch = 'branch-'+v[1:] + + gitdir = os.path.join(submod, '.git') + assert os.path.exists(gitdir), gitdir + + print('\n\n') + print(v + " " + submod + " "+ branch) + print('\n') + subprocess.call( ['git', 'branch', '-D', branch], cwd=submod) + subprocess.call( ['git', 'branch', '-D', 'origin/'+branch], cwd=submod) + # Need unshallow and tags so git-describe works + subprocess.check_call(['git', 'remote', '-v'], cwd=submod) + subprocess.call( ['git', 'fetch', 'origin', '--prune', '--prune-tags'], cwd=submod) + subprocess.call( ['git', 'fetch', '--progress', 'origin', '--unshallow'], cwd=submod) + subprocess.check_call(['git', 'fetch', '--progress', 'origin', '--tags'], cwd=submod) + subprocess.check_call(['git', 'fetch', '--progress', 'origin', '+{0}:remotes/origin/{0}'.format(branch)], cwd=submod) + + old_version = subprocess.check_output(['git', 'describe'], cwd=submod).decode('utf-8').strip() + + subprocess.check_call(['git', 'status'], cwd=submod) + subprocess.check_call(['git', 'branch', '-av'], cwd=submod) + subprocess.check_call(['git', 'reset', '--hard', 'origin/'+branch], cwd=submod) + + new_version = subprocess.check_output(['git', 'describe'], cwd=submod).decode('utf-8').strip() + print(old_version + '-->' + new_version) + + log = subprocess.check_output(['git', 'log', '--graph', '--pretty=short', '--decorate=short', '--decorate-refs=remotes/origin', '--shortstat', old_version+'..'+new_version], cwd=submod).decode('utf-8') + + print('\n\n\n\n') + print(lib + ' ' + v) + print('\n') + print('-'*10) + print('-'*10) + print('\n') + print(subprocess.check_output(['git', 'log', '--pretty=short', '--decorate=short', '--decorate-refs=remotes/origin', old_version+'..'+new_version], cwd=submod).decode('utf-8')) + print('\n') + print('-'*10) + print('\n') + print(log) + print('-'*10) + + changes.append((lib, v, old_version, new_version)) + subprocess.check_call(['git', 'add', v], cwd=ldir) + + +def get_submod_info(): + output = subprocess.check_output(['git', 'submodule', 'summary']).decode('utf-8') + output = output.replace('\n\n\n', '\n\n') + output = output.strip() + return textwrap.indent(output, ' ') + +print('\n\n') +print('-'*75) +subprocess.check_call(['git', 'status']) +print('-'*75) +pprint.pprint(changes) +print('-'*75) + +output = ['Updating submodules on {} UTC'.format(now), ''] + +for lib, ver, ov, nv in changes: + if ov == nv: + continue + output.append('''\ + - Updating [`{lib}` {ver}](https://github.com/google/skywater-pdk-libs-{lib}/compare/{ov}..{nv}) to {nv}'''.format( + lib=lib, ver=ver, ov=ov, nv=nv)) + +output.append('') +output.append(get_submod_info()) + +print('\n'.join(output)) + + +with tempfile.NamedTemporaryFile('w') as f: + f.write('\n'.join(output)) + f.flush() + subprocess.check_call(['git', 'commit', '--signoff', '--file={}'.format(f.name)]) + diff --git a/.github/workflows/auto-pr-submodules.yml b/.github/workflows/auto-pr-submodules.yml index 79e30c2c6..893e49acc 100644 --- a/.github/workflows/auto-pr-submodules.yml +++ b/.github/workflows/auto-pr-submodules.yml @@ -1,6 +1,7 @@ name: Update Submodules and Submit a PR on: + workflow_dispatch: push: branches: - master @@ -13,21 +14,21 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - with: - submodules: 'true' - - name: Update All Submodules to Remote Latest - run: git submodule update --remote + - name: Update Submodules to Remote Latest + run: python3 .github/scripts/google-skywater-pdk-roll.py -l libraries + + - name: Export Body + run: echo "BODY=$(git log -1 --pretty=%B)" >> $GITHUB_ENV - name: Create Pull Request uses: peter-evans/create-pull-request@v3 with: token: ${{ github.token }} - commit-message: Update All Submodules to Remote Latest - title: 'Update All Submodules to Remote Latest' + title: 'Update Submodules to Remote Latest' branch: create-pull-request/submodules-auto-update base: master delete-branch: true - body: This PR is auto-generated to update all submodules for all libraries in this repository. + body: ${{ env.BODY }} labels: update submodules, automated pr From 40984ad7476e46b2e182ce8f08fedb5355d67057 Mon Sep 17 00:00:00 2001 From: agorararmard Date: Wed, 17 Feb 2021 21:47:44 +0200 Subject: [PATCH 6/6] Export the auto PR Title in a separate step --- .github/workflows/auto-pr-submodules.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto-pr-submodules.yml b/.github/workflows/auto-pr-submodules.yml index 893e49acc..1a2b098e8 100644 --- a/.github/workflows/auto-pr-submodules.yml +++ b/.github/workflows/auto-pr-submodules.yml @@ -21,11 +21,17 @@ jobs: - name: Export Body run: echo "BODY=$(git log -1 --pretty=%B)" >> $GITHUB_ENV + - name: Export First 5 Digits of Commit Hash + run: echo "COMMIT_SHA_5=$(echo ${{ github.sha }} | awk '{print substr($0,0,5)}')" >> $GITHUB_ENV + + - name: Export Title + run: echo "TITLE='Update Submodules to Remote Latest, triggered from commit ${{ env.COMMIT_SHA_5 }}'" >> $GITHUB_ENV + - name: Create Pull Request uses: peter-evans/create-pull-request@v3 with: token: ${{ github.token }} - title: 'Update Submodules to Remote Latest' + title: ${{ env.TITLE }} branch: create-pull-request/submodules-auto-update base: master delete-branch: true