From 97940dc2bc7fb4bb4c08971459b9171cad50820d Mon Sep 17 00:00:00 2001 From: Diletta Cal Date: Sat, 31 Oct 2026 10:07:40 +0100 Subject: [PATCH 1/5] docs: describe language-agnostic workflows --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index cf88710..3c4586d 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,26 @@ # github-workflows -Shared GitHub Actions policy and release workflows, maintained once and pinned by consumer repositories. +Reusable GitHub Actions workflows for repositories. -## Workflows +## Pull Request Policy -| Workflow | Purpose | -| --- | --- | -| `pull-request-policy.yml` | Checks Conventional Commit-style PR titles and requires a changed `CHANGELOG.md` for releasable work. | -| `publish-release.yml` | Prepares a versioned release PR, then publishes the tag and GitHub Release after that PR merges. | +Use `examples/pull-request-policy.yml` (pinned to a commit SHA). Requires `contents: read` and safe for forks. -## Use +Enforces: +- **PR Title**: Standard types (`feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`). +- **Changelog**: Requires `CHANGELOG.md` edits unless the type is `chore`, `ci`, `style`, `test`, or `revert`. -Copy a caller from [`examples/`](examples/), pin ``, and keep the -caller responsible for events, permissions, checks, and branch protection. +## Manual Releases -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. +Use `examples/publish-release.yml` on the default branch with `contents: write`. Enter a version (`X.Y.Z`). + +- Supports `pyproject.toml` (`version = "X.Y.Z"`) or a `VERSION` file, along with a `## [Unreleased]` changelog section. +- Automatically creates a release commit (`chore(release): X.Y.Z`), tags `vX.Y.Z`, and creates the GitHub Release. +- Safe to re-run on failure; skips if already released. ## Development +Run tests and linting: + ```sh pre-commit run --all-files && actionlint && python3 -m unittest discover -s tests -v -``` - -See [CONTRIBUTING.md](CONTRIBUTING.md) for setup. From ebce0553301727e33b63025ac59010d9f86e3974 Mon Sep 17 00:00:00 2001 From: Diletta Cal Date: Sat, 31 Oct 2026 10:10:30 +0100 Subject: [PATCH 2/5] docs: clarify shared workflow purpose --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3c4586d..cf88710 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,26 @@ # github-workflows -Reusable GitHub Actions workflows for repositories. +Shared GitHub Actions policy and release workflows, maintained once and pinned by consumer repositories. -## Pull Request Policy +## Workflows -Use `examples/pull-request-policy.yml` (pinned to a commit SHA). Requires `contents: read` and safe for forks. +| Workflow | Purpose | +| --- | --- | +| `pull-request-policy.yml` | Checks Conventional Commit-style PR titles and requires a changed `CHANGELOG.md` for releasable work. | +| `publish-release.yml` | Prepares a versioned release PR, then publishes the tag and GitHub Release after that PR merges. | -Enforces: -- **PR Title**: Standard types (`feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`). -- **Changelog**: Requires `CHANGELOG.md` edits unless the type is `chore`, `ci`, `style`, `test`, or `revert`. +## Use -## Manual Releases +Copy a caller from [`examples/`](examples/), pin ``, and keep the +caller responsible for events, permissions, checks, and branch protection. -Use `examples/publish-release.yml` on the default branch with `contents: write`. Enter a version (`X.Y.Z`). - -- Supports `pyproject.toml` (`version = "X.Y.Z"`) or a `VERSION` file, along with a `## [Unreleased]` changelog section. -- Automatically creates a release commit (`chore(release): X.Y.Z`), tags `vX.Y.Z`, and creates the GitHub Release. -- Safe to re-run on failure; skips if already released. +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. ## Development -Run tests and linting: - ```sh pre-commit run --all-files && actionlint && python3 -m unittest discover -s tests -v +``` + +See [CONTRIBUTING.md](CONTRIBUTING.md) for setup. From a9011e2ec1d2fa0dafc67ca70e44e75fa52a3d99 Mon Sep 17 00:00:00 2001 From: Diletta Cal Date: Sat, 31 Oct 2026 10:16:33 +0100 Subject: [PATCH 3/5] fix: resume prepared release branches --- .github/workflows/publish-release.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index b3c2b71..7857e9e 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -98,9 +98,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 From dc4960761151b798a2a5f1238ab6d31763732a45 Mon Sep 17 00:00:00 2001 From: Diletta Cal Date: Sat, 31 Oct 2026 10:22:30 +0100 Subject: [PATCH 4/5] fix: recognize merged release commits --- .github/workflows/publish-release.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 7857e9e..6cf5bce 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -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 From a47183d14e5b42cbadb22c09148bb11fc3b638c5 Mon Sep 17 00:00:00 2001 From: Diletta Cal Date: Sat, 31 Oct 2026 10:26:35 +0100 Subject: [PATCH 5/5] fix: publish releases after merge --- .github/workflows/publish-merged-release.yml | 32 ++++++++++++++++++++ CHANGELOG.md | 1 + 2 files changed, 33 insertions(+) create mode 100644 .github/workflows/publish-merged-release.yml diff --git a/.github/workflows/publish-merged-release.yml b/.github/workflows/publish-merged-release.yml new file mode 100644 index 0000000..19a427a --- /dev/null +++ b/.github/workflows/publish-merged-release.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 40f27bc..fb19318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.