diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 07b40e3..faecc5a 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -90,6 +90,7 @@ jobs: run: python3 .shared-workflows/scripts/release.py rollover --version "$RELEASE_VERSION" --date "$RELEASE_DATE" - name: Update project version and commit release if: ${{ !steps.state.outputs.resuming }} + id: prepare env: DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} GH_TOKEN: ${{ github.token }} @@ -103,6 +104,12 @@ jobs: git add CHANGELOG.md "$VERSION_FILE" git diff --cached --quiet && { echo '::error::No release changes to commit'; exit 1; } git -c user.name='github-actions[bot]' -c user.email='41898282+github-actions[bot]@users.noreply.github.com' commit -m "chore(release): $RELEASE_VERSION" + # Unprotected default branch: push and publish in this run. Protected: fall back to a release PR. + if git push origin "HEAD:refs/heads/$DEFAULT_BRANCH"; then + echo 'direct=true' >> "$GITHUB_OUTPUT" + exit 0 + fi + echo '::notice::Default branch rejected the push; opening a release PR instead.' branch="release/v$RELEASE_VERSION" remote_commit=$(git ls-remote origin "refs/heads/$branch" | cut -f1) if [ -n "$remote_commit" ]; then @@ -113,7 +120,7 @@ jobs: gh pr list --head "$branch" --state open --json url --jq '.[0].url' | grep -q . || \ gh pr create --base "$DEFAULT_BRANCH" --head "$branch" --title "chore(release): $RELEASE_VERSION" --body 'Prepared release; review and merge before publishing the tag.' - name: Create GitHub Release from changelog notes - if: ${{ steps.state.outputs.resuming }} + if: ${{ steps.state.outputs.resuming || steps.prepare.outputs.direct }} id: release env: GH_TOKEN: ${{ github.token }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 386f162..69f0867 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to these reusable GitHub Actions workflows are recorded here ## [Unreleased] +### Changed + +- Publish in a single run when the default branch accepts the release commit; open a release PR only when branch protection rejects the push. + ## [0.1.1] - 2026-10-31 ### Fixed diff --git a/README.md b/README.md index 3b5e077..01836bf 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,10 @@ caller responsible for events, permissions, checks, and branch protection. Release callers pass the same SHA as `workflows-ref`: inside `workflow_call`, `github.workflow_sha` is the caller's commit, not this repository's. -Release callers dispatch `X.Y.Z`: first run opens a release PR; after merging -it, run the same version again to publish the tag and GitHub Release. +Release callers dispatch `X.Y.Z`. If the default branch accepts the bot's push, +the same run commits, tags, and publishes the GitHub Release. If branch +protection rejects it, the run opens a release PR; after merging it, run the same +version again to publish. ## Development