-
Notifications
You must be signed in to change notification settings - Fork 40
fix(ci): land release version-bump via PR to satisfy main's branch ruleset #161
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
Changes from all commits
6643746
785fae5
57d046b
56ea91e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ concurrency: | |
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| publish-rust: | ||
|
|
@@ -107,16 +108,30 @@ jobs: | |
| perl -0pi -e 's/(\[package\][\s\S]*?\nversion = ")[^"]+(")/$1$ENV{NEXT_VERSION}$2/' Cargo.toml | ||
| cargo update -p "$CRATE_NAME" --precise "$NEXT_VERSION" | ||
|
|
||
| - name: Commit version bump and tag | ||
| # `main` is protected by a repository ruleset that requires all | ||
| # changes to land through a pull request (no direct pushes), and the | ||
| # workflow's GITHUB_TOKEN is not on that ruleset's bypass list. So the | ||
| # version-bump commit is pushed to a throwaway release branch and | ||
| # landed on `main` via an auto-merged PR instead of `git push`ing | ||
| # `HEAD` straight at `main` (which the ruleset rejects with GH013). | ||
| - name: Commit version bump | ||
| id: commit | ||
| env: | ||
| NEXT_VERSION: ${{ steps.version.outputs.next_version }} | ||
| RELEASE_TAG: ${{ steps.version.outputs.tag }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| release_branch="release/${RELEASE_TAG}" | ||
| git checkout -b "${release_branch}" | ||
| git add Cargo.toml Cargo.lock | ||
| git commit -m "Release ${RELEASE_TAG}" | ||
| git tag -a "${RELEASE_TAG}" -m "Release ${RELEASE_TAG}" | ||
| git push origin "${release_branch}" | ||
|
|
||
| echo "branch=${release_branch}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| # `$CRATE_NAME` (and its path dependency `tinycortex-api`) both carry | ||
| # `publish = false` right now: `tinycortex-api` depends on `tinymemory-api` | ||
|
|
@@ -144,11 +159,36 @@ jobs: | |
| if: steps.publishable.outputs.publishable == 'true' | ||
| run: cargo package --locked -p "$CRATE_NAME" | ||
|
|
||
| - name: Push release commit and tag | ||
| - name: Open and merge release PR | ||
| id: merge | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| RELEASE_TAG: ${{ steps.version.outputs.tag }} | ||
| RELEASE_BRANCH: ${{ steps.commit.outputs.branch }} | ||
| run: | | ||
| git push origin "HEAD:${GITHUB_REF_NAME}" | ||
| set -euo pipefail | ||
|
|
||
| pr_url="$(gh pr create \ | ||
| --base "${GITHUB_REF_NAME}" \ | ||
| --head "${RELEASE_BRANCH}" \ | ||
| --title "Release ${RELEASE_TAG}" \ | ||
| --body "Automated version bump for ${RELEASE_TAG}.")" | ||
| # This repository allows merge commits only (squash and rebase are | ||
| # both disabled), so the release PR must be merged with --merge. | ||
| gh pr merge "${pr_url}" --merge --delete-branch | ||
|
|
||
| git fetch origin "${GITHUB_REF_NAME}" | ||
| merge_sha="$(git rev-parse "origin/${GITHUB_REF_NAME}")" | ||
| echo "sha=${merge_sha}" >> "$GITHUB_OUTPUT" | ||
|
Comment on lines
+178
to
+180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When another PR lands between the release PR merge and this fetch, Useful? React with 👍 / 👎. |
||
|
|
||
| - name: Tag and push release | ||
| env: | ||
| RELEASE_TAG: ${{ steps.version.outputs.tag }} | ||
| MERGE_SHA: ${{ steps.merge.outputs.sha }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| git tag -a "${RELEASE_TAG}" -m "Release ${RELEASE_TAG}" "${MERGE_SHA}" | ||
| git push origin "${RELEASE_TAG}" | ||
|
|
||
| - name: Publish to crates.io | ||
|
|
||
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.
If any step fails after this push but before the PR is merged—for example, packaging or a transient
gh pr createfailure—the remoterelease/vX.Y.Zbranch remains whilemainretains the old version. A rerun therefore computes the same branch name, creates a new commit with a different timestamp/SHA, and fails here with a non-fast-forward rejection, requiring manual branch deletion before the release can be retried. Delete or safely replace a stale unmerged release branch, or make the branch name unique per run.Useful? React with 👍 / 👎.