From e3c87c5934e4f99b72695011c3569a426a8f5ba5 Mon Sep 17 00:00:00 2001 From: Mike Schuchardt Date: Thu, 29 Feb 2024 21:27:56 -0800 Subject: [PATCH] wip: Add autoroller to update_deps.py --- .github/workflows/header-update.yml | 73 +++++++++++++++++++++++++++++ scripts/update_deps.py | 47 ++++++++++++++++--- 2 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/header-update.yml diff --git a/.github/workflows/header-update.yml b/.github/workflows/header-update.yml new file mode 100644 index 00000000000..c000e9f9fb9 --- /dev/null +++ b/.github/workflows/header-update.yml @@ -0,0 +1,73 @@ +name: Header Update + +on: + workflow_dispatch: + pull_request: + types: + - closed + branches: + - main + +jobs: + header-update: + if: github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + + - name: Update known-good + id: update + run: | + python scripts/update_deps.py --no-build --dir external --roll-mode latest-tag --roll Vulkan-Headers Vulkan-Loader Vulkan-Utility-Libraries Vulkan-Tools + echo HEADER_VERSION=$(jq -r '.["repos"][] | select(.name=="Vulkan-Headers").commit' scripts/known_good.json) >> $GITHUB_ENV + grep -q -P '^v\d\.\d\.\d+$' <<< "$HEADER_VERSION" + + - name: Generate source + id: generate + continue-on-error: true + run: | + python scripts/generate_source.py external/Vulkan-Headers/registry external/SPIRV-Headers/include/spirv/unified1 + python scripts/vk_validation_stats.py external/Vulkan-Headers/registry/validusage.json -spirvtools external/SPIRV-Tools -summary -c + + - name: Commit + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + git checkout -b gha-header-update-$HEADER_VERSION + git commit -a -m "build: Update to header $HEADER_VERSION" + git push --force origin gha-header-update-$HEADER_VERSION + + - name: Open PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr create --fill --body-file - << EOF + ### Update known-good.json + ~~~ + ${{join(steps.update.outputs.*, '\n')}} + ~~~ + ### Generate source + ~~~ + ${{join(steps.generate.outputs.*, '\n')}} + ~~~ + header-tag:$HEADER_VERSION + EOF + + header-tag: + if: | + github.event_name == 'pull_request' && + github.event.pull_request.merged && + contains(github.event.pull_request.body, 'header-tag:') + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: read + steps: + - name: Tag repo + run: | + HEADER_TAG=$(grep -oP 'header-tag:\K.*') <<< '${{github.event.pull_request.body}}' + git tag $HEADER_TAG ${{github.event.pull_request.merge_commit_sha}} + git push origin $HEADER_TAG diff --git a/scripts/update_deps.py b/scripts/update_deps.py index d9dcff7123c..368f0960820 100755 --- a/scripts/update_deps.py +++ b/scripts/update_deps.py @@ -428,6 +428,17 @@ def Checkout(self): if not os.path.exists(os.path.join(self.repo_dir, '.git')): self.Clone() self.Fetch() + + if self._args.roll and self.name in self._args.roll: + if self._args.roll_mode == 'latest-tag': + new_commit = command_output(['git', 'describe', '--tags', '--abbrev=0', 'origin/HEAD'], self.repo_dir).strip() + elif self._args.roll_mode == 'latest': + new_commit = command_output(['git', 'rev-parse', 'origin/HEAD'], self.repo_dir).strip() + if new_commit != self.commit: + print(f"Rolling {self.name} from {self.commit} to {new_commit}", flush=True) + UpdateRepoCommit(self._args, self.name, new_commit) + self.commit = new_commit + if len(self._args.ref): command_output(['git', 'checkout', self._args.ref], self.repo_dir) else: @@ -568,6 +579,12 @@ def Build(self, repos, repo_dict): def IsOptional(self, opts): return len(self.optional.intersection(opts)) > 0 +def GetKnownGoodFile(args): + if args.known_good_dir: + return os.path.join(os.path.abspath(args.known_good_dir), KNOWN_GOOD_FILE_NAME) + else: + return os.path.join(os.path.dirname(os.path.abspath(__file__)), KNOWN_GOOD_FILE_NAME) + def GetGoodRepos(args): """Returns the latest list of GoodRepo objects. @@ -575,18 +592,23 @@ def GetGoodRepos(args): directory as this script unless overridden by the 'known_good_dir' parameter. """ - if args.known_good_dir: - known_good_file = os.path.join( os.path.abspath(args.known_good_dir), - KNOWN_GOOD_FILE_NAME) - else: - known_good_file = os.path.join( - os.path.dirname(os.path.abspath(__file__)), KNOWN_GOOD_FILE_NAME) - with open(known_good_file) as known_good: + with open(GetKnownGoodFile(args)) as known_good: return [ GoodRepo(repo, args) for repo in json.loads(known_good.read())['repos'] ] +def UpdateRepoCommit(args, name, commit): + """Updates the commit id for the given repo""" + with open(GetKnownGoodFile(args)) as known_good_file: + known_good_json = json.load(known_good_file) + for repo in known_good_json['repos']: + if repo['name'] == name: + repo['commit'] = commit + break + with open(GetKnownGoodFile(args), 'w') as known_good_file: + json.dump(known_good_json, known_good_file, indent=4) + known_good_file.write('\n') def GetInstallNames(args): """Returns the install names list. @@ -732,6 +754,17 @@ def main(): action='store_true', help="Build dependencies with ASAN enabled", default=False) + parser.add_argument( + '--roll', + dest='roll', + nargs='+', + help='Help!') + parser.add_argument( + '--roll-mode', + dest='roll_mode', + choices=['latest', 'latest-tag'], + default='latest', + help='Help!') args = parser.parse_args() save_cwd = os.getcwd()