-
Notifications
You must be signed in to change notification settings - Fork 0
Gate release tag creation #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| name: Create release tag | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "release/v*" | ||
|
|
||
| concurrency: | ||
| group: release-tag-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| tag: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: write | ||
| contents: write | ||
| steps: | ||
| - name: Checkout the candidate | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Validate release branch, version, and main commit | ||
| id: validate | ||
| shell: bash | ||
| env: | ||
| RELEASE_BRANCH: ${{ github.ref_name }} | ||
| RELEASE_SHA: ${{ github.sha }} | ||
| run: | | ||
| set -euo pipefail | ||
| release_tag=$(python - "$RELEASE_BRANCH" <<'PY' | ||
| import pathlib | ||
| import re | ||
| import sys | ||
| import tomllib | ||
|
|
||
| branch = sys.argv[1] | ||
| match = re.fullmatch(r"release/(v[0-9]+\.[0-9]+\.[0-9]+)", branch) | ||
| if match is None: | ||
| raise SystemExit(f"invalid release branch: {branch!r}") | ||
| tag = match.group(1) | ||
| version = tomllib.loads(pathlib.Path("pyproject.toml").read_text())["project"]["version"] | ||
| if tag != f"v{version}": | ||
| raise SystemExit(f"branch tag {tag!r} does not match package version v{version}") | ||
| print(tag) | ||
| PY | ||
| ) | ||
| git fetch --no-tags origin main | ||
| main_sha=$(git rev-parse FETCH_HEAD) | ||
| if [[ "$RELEASE_SHA" != "$main_sha" ]]; then | ||
| echo "Release branch must point to current main: $RELEASE_SHA != $main_sha" >&2 | ||
| exit 1 | ||
| fi | ||
| existing_tag=$(git ls-remote origin "refs/tags/$release_tag" | awk '{print $1}') | ||
| if [[ -n "$existing_tag" && "$existing_tag" != "$RELEASE_SHA" ]]; then | ||
| echo "Tag $release_tag already points to $existing_tag, not $RELEASE_SHA" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "tag=$release_tag" >> "$GITHUB_OUTPUT" | ||
| if [[ "$existing_tag" == "$RELEASE_SHA" ]]; then | ||
| echo "tag_exists=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "tag_exists=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Create the immutable version tag | ||
| if: steps.validate.outputs.tag_exists != 'true' | ||
| shell: bash | ||
| env: | ||
| RELEASE_SHA: ${{ github.sha }} | ||
| RELEASE_TAG: ${{ steps.validate.outputs.tag }} | ||
| run: | | ||
| set -euo pipefail | ||
| git tag "$RELEASE_TAG" "$RELEASE_SHA" | ||
| git push origin "refs/tags/$RELEASE_TAG" | ||
|
|
||
| - name: Dispatch the verified publish workflow | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| RELEASE_SHA: ${{ github.sha }} | ||
| RELEASE_TAG: ${{ steps.validate.outputs.tag }} | ||
| run: | | ||
| set -euo pipefail | ||
| gh workflow run publish.yml \ | ||
| --ref main \ | ||
| --field release_tag="$RELEASE_TAG" \ | ||
| --field release_sha="$RELEASE_SHA" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a repository writer directly invokes
workflow_dispatchor pushes a matching version tag, this check accepts any tag/SHA whose checked-out package version matches, even if that commit would fail the new release branch's current-maincheck.gh workflow run --helpconfirms that--ref mainonly selects the ref containing the workflow file; it does not constrainrelease_shatomain. Consequently, publication can still bypass the claimed release gate, so this workflow should independently compare the supplied SHA with currentmainor otherwise verify that the gated workflow authorized it.Useful? React with 👍 / 👎.