Skip to content
Merged
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
32 changes: 32 additions & 0 deletions .github/workflows/publish-merged-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish merged release

on:
pull_request:
branches: [main]
types: [closed]

permissions:
contents: write

jobs:
publish:
if: "${{ github.event.pull_request.merged && startsWith(github.event.pull_request.title, 'chore(release): ') }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
fetch-depth: 0
- name: Publish tag and release
env:
GH_TOKEN: ${{ github.token }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
set -euo pipefail
version="${PR_TITLE#chore(release): }"
version="${version%% *}"
python3 scripts/release.py validate-prepared --version "$version"
git tag "v$version"
git push origin "v$version"
python3 scripts/release.py release-notes --version "$version" > release-notes.md
gh release create "v$version" --title "v$version" --notes-file release-notes.md
16 changes: 11 additions & 5 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ jobs:
if git rev-parse -q --verify "refs/tags/v$RELEASE_VERSION" >/dev/null; then
tag_commit=$(git rev-list -n 1 "v$RELEASE_VERSION")
subject=$(git show -s --format=%s "$tag_commit")
if [ "$tag_commit" != "$(git rev-parse HEAD)" ] || [ "$subject" != "chore(release): $RELEASE_VERSION" ]; then
expected="chore(release): $RELEASE_VERSION"
if [ "$tag_commit" != "$(git rev-parse HEAD)" ] || { [ "$subject" != "$expected" ] && [ "${subject%% (#*}" != "$expected" ]; }; then
echo '::error::Existing tag does not match this default-branch release commit; recover manually.'
exit 1
fi
echo 'resuming=true' >> "$GITHUB_OUTPUT"
gh release view "v$RELEASE_VERSION" --json url --jq '.url' 2>/dev/null | xargs -r -I{} echo "release-url={}" >> "$GITHUB_OUTPUT" || true
elif [ "$(git show -s --format=%s HEAD)" = "chore(release): $RELEASE_VERSION" ]; then
elif subject=$(git show -s --format=%s HEAD) && { [ "$subject" = "chore(release): $RELEASE_VERSION" ] || [ "${subject%% (#*}" = "chore(release): $RELEASE_VERSION" ]; }; then
python3 .shared-workflows/scripts/release.py validate-prepared --version "$RELEASE_VERSION"
echo 'resuming=true' >> "$GITHUB_OUTPUT"
fi
Expand Down Expand Up @@ -98,9 +99,14 @@ jobs:
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"
branch="release/v$RELEASE_VERSION"
git ls-remote --exit-code --heads origin "$branch" && exit 1 || true
git push origin "HEAD:refs/heads/$branch"
gh pr create --base "$DEFAULT_BRANCH" --head "$branch" --title "chore(release): $RELEASE_VERSION" --body 'Prepared release; review and merge before publishing the tag.'
remote_commit=$(git ls-remote origin "refs/heads/$branch" | cut -f1)
if [ -n "$remote_commit" ]; then
test "$remote_commit" = "$(git rev-parse HEAD)"
else
git push origin "HEAD:refs/heads/$branch"
fi
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 }}
id: release
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ All notable changes to these reusable GitHub Actions workflows are recorded here
### Fixed

- Prepare releases through a pull request before publishing their tag and GitHub Release.
- Publish the tag and GitHub Release automatically when a release PR merges.
Loading