Skip to content

Commit 22e7c3f

Browse files
committed
Retrieve head sha from PR
1 parent 2b8c069 commit 22e7c3f

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

.github/workflows/post-release.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ on:
77
description: |
88
The version to release (MUST follow semantic versioning).
99
required: true
10-
ref:
11-
description: |
12-
The git commit, branch, or tag to release from.
13-
required: true
14-
1510
jobs:
1611
update-release:
1712
name: "Update release"
@@ -20,7 +15,7 @@ jobs:
2015
- name: Checkout
2116
uses: actions/checkout@v4
2217
with:
23-
ref: ${{ inputs.ref }}
18+
ref: rc/v${{ inputs.version }}
2419
- name: Install Python
2520
uses: actions/setup-python@v4
2621
with:
@@ -32,14 +27,12 @@ jobs:
3227
- name: Update release assets
3328
env:
3429
RELEASE_VERSION: ${{ inputs.version }}
35-
RELEASE_REF: ${{ inputs.ref }}
3630
GITHUB_TOKEN: ${{ github.token }}
3731
RELEASE_ENGINEERING_TOKEN: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
3832
run: |
3933
python scripts/release/update-release-assets.py \
4034
--version $RELEASE_VERSION \
4135
--layout scripts/release/release-layout.yml \
42-
--ref $RELEASE_REF \
4336
--repo "$GITHUB_REPOSITORY" \
4437
--github-token "$GITHUB_REPOSITORY:$GITHUB_TOKEN" "github/codeql-coding-standards-release-engineering:$RELEASE_ENGINEERING_TOKEN" \
4538
--skip-checks

scripts/release/update-release-assets.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,17 @@ def main(args: 'argparse.Namespace') -> int:
252252
return 1
253253
release = releases[0]
254254

255-
pull_candidates = [pr for pr in repo.get_pulls(state="open") if pr.head.sha == args.ref]
255+
pull_candidates = [pr for pr in repo.get_pulls(state="open") if pr.title == f"Release v{args.version}"]
256256
if len(pull_candidates) != 1:
257-
print(f"Error: expected exactly one PR with head {args.ref}, but found {len(pull_candidates)}", file=sys.stderr)
257+
print(f"Error: expected exactly one PR for version {args.version}, but found {len(pull_candidates)}", file=sys.stderr)
258258
return 1
259259

260-
print(f"Collecting workflow runs for ref {args.ref}")
261-
check_runs: List[CheckRun.CheckRun] = repo.get_check_runs(args.ref) # type: ignore
260+
pull_request = pull_candidates[0]
261+
262+
head_sha = pull_request.head.sha
263+
264+
print(f"Collecting workflow runs for ref {head_sha}")
265+
check_runs: List[CheckRun.CheckRun] = repo.get_check_runs(head_sha) # type: ignore
262266

263267
action_workflow_run_url_regex = r"^https://(?P<github_url>[^/]+)/(?P<owner>[^/]+)/(?P<repo>[^/]+)/actions/runs/(?P<run_id>\d+)$"
264268
action_workflow_job_run_url_regex = r"^https://(?P<github_url>[^/]+)/(?P<owner>[^/]+)/(?P<repo>[^/]+)/actions/runs/(?P<run_id>\d+)/job/(?P<job_id>\d+)$"
@@ -294,7 +298,7 @@ def main(args: 'argparse.Namespace') -> int:
294298
latests_workflow_runs = list(workflow_runs_per_id.values())
295299

296300
if not args.skip_checks:
297-
print(f"Checking that all workflow runs for ref {args.ref} succeeded")
301+
print(f"Checking that all workflow runs for ref {head_sha} succeeded")
298302
for workflow_run in latests_workflow_runs:
299303
if workflow_run.status != "completed":
300304
print(f"Error: workflow run {workflow_run.name} with id {workflow_run.id} is not completed", file=sys.stderr)
@@ -329,7 +333,6 @@ def main(args: 'argparse.Namespace') -> int:
329333

330334
parser = argparse.ArgumentParser()
331335
parser.add_argument('--version', help="The version to release (MUST be a valid semantic version)", required=True)
332-
parser.add_argument('--ref', help="The head sha for the release PR", required=True)
333336
parser.add_argument('--repo', help="The owner and repository name. For example, 'octocat/Hello-World'. Used when testing this script on a fork", required=True, default="github/codeql-coding-standards")
334337
parser.add_argument('--github-token', help="The github token to use for the release PR", required=True, nargs="+")
335338
parser.add_argument('--layout', help="The layout to use for the release", required=True)

0 commit comments

Comments
 (0)