Skip to content

Commit

Permalink
wip: Add autoroller to update_deps.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mikes-lunarg committed Mar 5, 2024
1 parent 5807ddc commit e3c87c5
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 7 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/header-update.yml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 40 additions & 7 deletions scripts/update_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -568,25 +579,36 @@ 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.
The known-good file is expected to be in the same
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.
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e3c87c5

Please sign in to comment.