Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions .github/workflows/check_release_candidate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: check release candidate

on:
workflow_call:
inputs:
branch:
required: true
type: string
commit:
required: true
type: string
version:
required: true
type: string
checkName:
required: true
type: string
checkAppId:
required: true
type: number
timeoutMinutes:
required: false
default: 90
type: number

jobs:
check:
runs-on: ubuntu-latest
timeout-minutes: 130
permissions:
contents: read
checks: read
steps:
- name: validate candidate and wait for the trusted result
env:
GH_TOKEN: ${{ github.token }}
CANDIDATE_REPOSITORY: ${{ github.repository }}
CANDIDATE_BRANCH: ${{ inputs.branch }}
CANDIDATE_COMMIT: ${{ inputs.commit }}
CANDIDATE_VERSION: ${{ inputs.version }}
REQUIRED_CHECK_NAME: ${{ inputs.checkName }}
REQUIRED_CHECK_APP_ID: ${{ inputs.checkAppId }}
CHECK_TIMEOUT_MINUTES: ${{ inputs.timeoutMinutes }}
run: |
python3 - <<'PY'
import json
import os
import re
import subprocess
import time
from urllib.parse import quote

def api(endpoint, paginate=False):
command = ['gh', 'api', '--method', 'GET', endpoint]
if paginate:
command.extend(['--paginate', '--slurp'])
try:
result = subprocess.run(command, check=True, capture_output=True, text=True, timeout=60)
except subprocess.CalledProcessError as error:
raise RuntimeError(f'GitHub API request failed: {error.stderr}') from error
return json.loads(result.stdout)

def verify_branch(repository, branch, commit):
ref = api(f'repos/{repository}/git/ref/heads/{quote(branch, safe="/")}')
if ref['object']['type'] != 'commit' or ref['object']['sha'] != commit:
raise ValueError('Release branch no longer matches the candidate commit')

def wait_for_check(repository, branch, commit, name, app_id, timeout):
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
verify_branch(repository, branch, commit)
pages = api(
f'repos/{repository}/commits/{commit}/check-runs?check_name={quote(name, safe="")}&filter=all&per_page=100',
paginate=True,
)
matching = [
check for page in pages for check in page['check_runs']
if check['name'] == name and check['head_sha'] == commit
and (check.get('app') or {}).get('id') == app_id
]
if matching:
latest = max(matching, key=lambda check: check['id'])
if latest['status'] == 'completed':
if latest['conclusion'] != 'success':
raise ValueError(f"Required check concluded {latest['conclusion']}: {latest['html_url']}")
verify_branch(repository, branch, commit)
return latest['html_url']
remaining = deadline - time.monotonic()
if remaining > 0:
time.sleep(min(30, remaining))
raise TimeoutError('No successful trusted check arrived for the candidate commit')

def main():
repository = os.environ['CANDIDATE_REPOSITORY']
branch = os.environ['CANDIDATE_BRANCH']
commit = os.environ['CANDIDATE_COMMIT']
version = os.environ['CANDIDATE_VERSION']
name = os.environ['REQUIRED_CHECK_NAME'].strip()
app = os.environ['REQUIRED_CHECK_APP_ID']
minutes = os.environ['CHECK_TIMEOUT_MINUTES']
if not re.fullmatch(r'v\d+\.\d+\.\d+', version):
raise ValueError('The private-cluster gate requires a stable vX.Y.Z release')
if branch != f'releases/{version}' or not re.fullmatch(r'[0-9a-f]{40}', commit):
raise ValueError('Expected the release branch and a full candidate commit SHA')
if not name or not re.fullmatch(r'[1-9][0-9]*', app):
raise ValueError('A gated release requires a check name and trusted GitHub App ID')
if not re.fullmatch(r'[1-9][0-9]*', minutes) or int(minutes) > 120:
raise ValueError('Check timeout must be between 1 and 120 minutes')

verify_branch(repository, branch, commit)
result = wait_for_check(repository, branch, commit, name, int(app), int(minutes) * 60)
with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as summary:
summary.write(f'Release candidate: `{branch}` at `{commit}`\n\n{result}\n')

if __name__ == '__main__':
main()
PY
19 changes: 19 additions & 0 deletions .github/workflows/create_js_branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ on:
required: true
type: string
description: The version of the release
outputs:
branch:
description: The prepared release branch
value: ${{ jobs.branch.outputs.branch }}
commit:
description: The final release commit containing the built artifacts
value: ${{ jobs.branch.outputs.commit }}

jobs:
branch:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.candidate.outputs.branch }}
commit: ${{ steps.candidate.outputs.commit }}
env:
BRANCH: releases/${{ inputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -55,3 +65,12 @@ jobs:
git add .
git commit -m "build"
git push origin ${BRANCH}

- name: record release candidate
id: candidate
run: |
set -euo pipefail
commit=$(git rev-parse HEAD)
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
echo "commit=${commit}" >> "$GITHUB_OUTPUT"
printf 'Release candidate: `%s` at `%s`\n' "$BRANCH" "$commit" >> "$GITHUB_STEP_SUMMARY"
20 changes: 19 additions & 1 deletion .github/workflows/create_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ on:
default: false
type: boolean
description: Whether the release is a prerelease
expectedCommit:
required: false
default: ""
type: string
description: When set, require the branch to still point to this full commit and tag this commit

jobs:
release:
Expand All @@ -37,7 +42,20 @@ jobs:
- id: normalize
env:
INPUT_BRANCH: ${{ inputs.branch }}
run: echo "commit=${INPUT_BRANCH#refs/heads/}" >> "$GITHUB_OUTPUT"
EXPECTED_COMMIT: ${{ inputs.expectedCommit }}
RELEASE_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
branch=${INPUT_BRANCH#refs/heads/}
commit=$branch
if [[ -n "$EXPECTED_COMMIT" ]]; then
[[ "$EXPECTED_COMMIT" =~ ^[0-9a-f]{40}$ ]] || { echo "Expected a full commit SHA" >&2; exit 1; }
actual=$(git ls-remote origin "refs/heads/$branch" | cut -f1)
[[ "$actual" = "$EXPECTED_COMMIT" ]] || { echo "Release branch no longer matches the tested commit" >&2; exit 1; }
git push origin "$EXPECTED_COMMIT:refs/tags/$RELEASE_VERSION"
commit=$EXPECTED_COMMIT
fi
echo "commit=$commit" >> "$GITHUB_OUTPUT"

- uses: ncipollo/release-action@b7eabc95ff50cbeeedec83973935c8f306dfcd0b # v1.20.0
with:
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/publish_js_project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: publish prepared JS project

on:
workflow_call:
inputs:
branch:
required: true
type: string
commit:
required: true
type: string
version:
required: true
type: string
body:
required: true
type: string
checkName:
required: true
type: string
checkAppId:
required: true
type: number
timeoutMinutes:
required: false
default: 90
type: number

jobs:
checkCandidate:
permissions:
contents: read
checks: read
uses: ./.github/workflows/check_release_candidate.yaml
with:
branch: ${{ inputs.branch }}
commit: ${{ inputs.commit }}
version: ${{ inputs.version }}
checkName: ${{ inputs.checkName }}
checkAppId: ${{ inputs.checkAppId }}
timeoutMinutes: ${{ inputs.timeoutMinutes }}
createRelease:
needs: checkCandidate
permissions:
contents: write
uses: ./.github/workflows/create_release.yaml
with:
branch: ${{ inputs.branch }}
expectedCommit: ${{ inputs.commit }}
version: ${{ inputs.version }}
body: ${{ inputs.body }}
updateMajorTag:
needs: createRelease
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.commit }}
- name: replace the major tag without deleting the remote ref
env:
RELEASE_BRANCH: ${{ inputs.branch }}
CANDIDATE_COMMIT: ${{ inputs.commit }}
RELEASE_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
[[ "$CANDIDATE_COMMIT" =~ ^[0-9a-f]{40}$ ]] || { echo "Expected a full candidate commit" >&2; exit 1; }
[[ "$RELEASE_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]] || { echo "Expected a release version" >&2; exit 1; }
[[ "$RELEASE_BRANCH" = "releases/$RELEASE_VERSION" ]] || { echo "Unexpected release branch" >&2; exit 1; }

actual=$(git ls-remote --heads origin "refs/heads/$RELEASE_BRANCH" | cut -f1)
[[ "$actual" = "$CANDIDATE_COMMIT" ]] || { echo "Release branch changed after validation" >&2; exit 1; }
git fetch --no-tags origin "refs/tags/$RELEASE_VERSION"
[[ "$(git rev-parse 'FETCH_HEAD^{commit}')" = "$CANDIDATE_COMMIT" ]] || { echo "Release tag does not match the tested commit" >&2; exit 1; }

major_tag=${RELEASE_VERSION%%.*}
major_ref="refs/tags/$major_tag"
previous=$(git ls-remote --refs origin "$major_ref" | cut -f1)
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
# Checkout may contain a local tag; keep the remote ref intact.
if git show-ref --verify --quiet "$major_ref"; then
git tag --delete "$major_tag"
fi
git tag -a "$major_tag" "$CANDIDATE_COMMIT" -m "Latest $major_tag Release"
# The explicit old object also protects concurrent updates and first creation.
git push --force-with-lease="$major_ref:$previous" origin "$major_ref:$major_ref"
80 changes: 48 additions & 32 deletions .github/workflows/release_js_project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ on:
required: true
type: string
description: The path to CHANGELOG.md
prepareOnly:
required: false
default: false
type: boolean
description: Prepare the built release commit without publishing or moving tags
outputs:
branch:
description: The prepared release branch
value: ${{ jobs.createBranch.outputs.branch }}
commit:
description: The final release commit containing the built artifacts
value: ${{ jobs.createBranch.outputs.commit }}
version:
description: The release version with its v prefix
value: v${{ jobs.extractChangelog.outputs.version }}
body:
description: The release notes
value: ${{ jobs.extractChangelog.outputs.body }}

jobs:
extractChangelog:
Expand All @@ -31,45 +49,43 @@ jobs:
if: needs.checkVersion.outputs.exists == 'false'
uses: ./.github/workflows/create_js_branch.yaml
with:
version: v${{ needs.extractChangelog.outputs.version }}
version: v${{ needs.extractChangelog.outputs.version }}
createRelease:
needs: [checkVersion, extractChangelog, createBranch]
permissions:
contents: write
if: needs.checkVersion.outputs.exists == 'false'
if: needs.checkVersion.outputs.exists == 'false' && !inputs.prepareOnly
uses: ./.github/workflows/create_release.yaml
with:
branch: releases/v${{ needs.extractChangelog.outputs.version }}
version: v${{ needs.extractChangelog.outputs.version }}
body: ${{ needs.extractChangelog.outputs.body }}
updateMajorTag:
runs-on: ubuntu-latest
permissions:
contents: write
needs: [extractChangelog, createBranch, createRelease]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: releases/v${{ needs.extractChangelog.outputs.version }}
- name: get major version tag
id: major-version-tag
env:
NEW_RELEASE_TAG: ${{ needs.extractChangelog.outputs.version }}
run:
echo "MAJOR_VERSION_TAG=v${NEW_RELEASE_TAG%%.*}" >> "$GITHUB_OUTPUT"
- name: delete old major tag
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
MAJOR_VERSION_TAG: ${{ steps.major-version-tag.outputs.MAJOR_VERSION_TAG }}
run:
git push origin :refs/tags/$MAJOR_VERSION_TAG
- name: create new major tag
env:
GH_TOKEN: ${{ github.token }}
MAJOR_VERSION_TAG: ${{ steps.major-version-tag.outputs.MAJOR_VERSION_TAG }}
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git tag -a $MAJOR_VERSION_TAG -m "Latest $MAJOR_VERSION_TAG Release"
git push origin refs/tags/$MAJOR_VERSION_TAG
runs-on: ubuntu-latest
permissions:
contents: write
needs: [extractChangelog, createBranch, createRelease]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: releases/v${{ needs.extractChangelog.outputs.version }}
- name: get major version tag
id: major-version-tag
env:
NEW_RELEASE_TAG: ${{ needs.extractChangelog.outputs.version }}
run: echo "MAJOR_VERSION_TAG=v${NEW_RELEASE_TAG%%.*}" >> "$GITHUB_OUTPUT"
- name: delete old major tag
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
MAJOR_VERSION_TAG: ${{ steps.major-version-tag.outputs.MAJOR_VERSION_TAG }}
run: git push origin :refs/tags/$MAJOR_VERSION_TAG
- name: create new major tag
env:
GH_TOKEN: ${{ github.token }}
MAJOR_VERSION_TAG: ${{ steps.major-version-tag.outputs.MAJOR_VERSION_TAG }}
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git tag -a $MAJOR_VERSION_TAG -m "Latest $MAJOR_VERSION_TAG Release"
git push origin refs/tags/$MAJOR_VERSION_TAG
23 changes: 23 additions & 0 deletions .github/workflows/test_release_gate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test release gate

on:
pull_request:
paths:
- ".github/workflows/**"
- "tests/**"
push:
branches:
- main
paths:
- ".github/workflows/**"
- "tests/**"

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- run: python3 -B -m unittest discover -s tests -v
Loading