Skip to content

Commit d34b51a

Browse files
committed
Integrate post-release workflow witth update-release-status workflow
1 parent 18e4196 commit d34b51a

2 files changed

Lines changed: 40 additions & 32 deletions

File tree

.github/workflows/post-release.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@ name: Finalize Release
33
on:
44
workflow_dispatch:
55
inputs:
6-
version:
6+
head-sha:
77
description: |
8-
The version to release (MUST follow semantic versioning).
8+
The head SHA of the release PR to use for finalizing the release.
99
required: true
10+
workflow_call:
11+
inputs:
12+
head-sha:
13+
type: string
14+
description: |
15+
The head SHA of the release PR to use for finalizing the release.
16+
required: true
17+
18+
env:
19+
HEAD_SHA: ${{ inputs.head-sha }}
20+
1021
jobs:
1122
update-release:
1223
name: "Update release"
@@ -15,15 +26,7 @@ jobs:
1526
- name: Checkout
1627
uses: actions/checkout@v4
1728
with:
18-
ref: rc/${{ inputs.version }}
19-
20-
- name: Checkout PR
21-
env:
22-
GITHUB_TOKEN: ${{ github.token }}
23-
RELEASE_VERSION: ${{ inputs.version }}
24-
run: |
25-
pr_number=$(gh pr list --json number,title --jq "map(select(.title == \"Release v$RELEASE_VERSION\")) | .[].number")
26-
gh pr checkout $pr_number
29+
ref: ${{ inputs.head-sha }}
2730

2831
- name: Install Python
2932
uses: actions/setup-python@v4
@@ -35,12 +38,11 @@ jobs:
3538

3639
- name: Update release assets
3740
env:
38-
RELEASE_VERSION: ${{ inputs.version }}
3941
GITHUB_TOKEN: ${{ github.token }}
4042
RELEASE_ENGINEERING_TOKEN: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
4143
run: |
4244
python scripts/release/update-release-assets.py \
43-
--version $RELEASE_VERSION \
45+
--head-sha $HEAD_SHA \
4446
--layout scripts/release/release-layout.yml \
4547
--repo "$GITHUB_REPOSITORY" \
4648
--github-token "$GITHUB_REPOSITORY:$GITHUB_TOKEN" "github/codeql-coding-standards-release-engineering:$RELEASE_ENGINEERING_TOKEN" \

scripts/release/update-release-assets.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,6 @@ def make(self, directory: Path) -> Path:
225225
return Path(shutil.make_archive(str(directory / self.name.with_suffix("")), ext_format_map[extension], root_dir=temp_dir_path))
226226

227227
def main(args: 'argparse.Namespace') -> int:
228-
229-
try:
230-
semantic_version.Version.parse(args.version) # type: ignore
231-
except ValueError as e:
232-
print(f"Error: invalid version: {e}", file=sys.stderr)
233-
return 1
234-
235228
monkey_patch_github()
236229

237230
import github
@@ -246,27 +239,40 @@ def main(args: 'argparse.Namespace') -> int:
246239
repos[nwo] = github.Github(auth=github.Auth.Token(token)).get_repo(nwo)
247240

248241
repo = repos[args.repo]
249-
releases = [release for release in repo.get_releases() if release.title == f"v{args.version}"]
250-
if len(releases) != 1:
251-
print(f"Error: expected exactly one release with title {args.version}, but found {len(releases)}", file=sys.stderr)
252-
return 1
253-
release = releases[0]
254242

255-
pull_candidates = [pr for pr in repo.get_pulls(state="open") if pr.title == f"Release v{args.version}"]
243+
pull_candidates = [pr for pr in repo.get_pulls(state="open") if pr.head.sha == args.head_sha]
256244
if len(pull_candidates) != 1:
257-
print(f"Error: expected exactly one PR for version {args.version}, but found {len(pull_candidates)}", file=sys.stderr)
245+
print(f"Error: expected exactly one PR for SHA {args.head_sha}, but found {len(pull_candidates)}", file=sys.stderr)
258246
return 1
259247

260248
pull_request = pull_candidates[0]
261249

262250
if pull_request.state != "open":
263251
print(f"Error: PR for version {args.version} is not open", file=sys.stderr)
264252
return 1
253+
254+
rc_branch_regex = r"^rc/(?P<version>.*)$"
255+
rc_branch_match = re.match(rc_branch_regex, pull_request.base.ref)
256+
if not rc_branch_match:
257+
print(f"Error: PR {pull_request.url} is not based on a release candidate branch", file=sys.stderr)
258+
return 1
259+
260+
release_version = rc_branch_match.group("version")
261+
262+
try:
263+
semantic_version.Version.parse(release_version) # type: ignore
264+
except ValueError as e:
265+
print(f"Error: invalid version {release_version} use by release branch. Reason {e}", file=sys.stderr)
266+
return 1
265267

266-
head_sha = pull_request.head.sha
268+
releases = [release for release in repo.get_releases() if release.title == f"v{release_version}"]
269+
if len(releases) != 1:
270+
print(f"Error: expected exactly one release with title {args.version}, but found {len(releases)}", file=sys.stderr)
271+
return 1
272+
release = releases[0]
267273

268-
print(f"Collecting workflow runs for ref {head_sha}")
269-
check_runs: List[CheckRun.CheckRun] = repo.get_check_runs(head_sha) # type: ignore
274+
print(f"Collecting workflow runs for ref {args.head_sha}")
275+
check_runs: List[CheckRun.CheckRun] = repo.get_check_runs(args.head_sha) # type: ignore
270276

271277
action_workflow_run_url_regex = r"^https://(?P<github_url>[^/]+)/(?P<owner>[^/]+)/(?P<repo>[^/]+)/actions/runs/(?P<run_id>\d+)$"
272278
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+)$"
@@ -302,7 +308,7 @@ def main(args: 'argparse.Namespace') -> int:
302308
latests_workflow_runs = list(workflow_runs_per_id.values())
303309

304310
if not args.skip_checks:
305-
print(f"Checking that all workflow runs for ref {head_sha} succeeded")
311+
print(f"Checking that all workflow runs for ref {args.head_sha} succeeded")
306312
for workflow_run in latests_workflow_runs:
307313
if workflow_run.status != "completed":
308314
print(f"Error: workflow run {workflow_run.name} with id {workflow_run.id} is not completed", file=sys.stderr)
@@ -336,7 +342,7 @@ def main(args: 'argparse.Namespace') -> int:
336342
from sys import exit
337343

338344
parser = argparse.ArgumentParser()
339-
parser.add_argument('--version', help="The version to release (MUST be a valid semantic version)", required=True)
345+
parser.add_argument('--head-sha', help="The head SHA of the release PR for which we update it's corresponding release", required=True)
340346
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")
341347
parser.add_argument('--github-token', help="The github token to use for the release PR", required=True, nargs="+")
342348
parser.add_argument('--layout', help="The layout to use for the release", required=True)

0 commit comments

Comments
 (0)