From ec620411507ce01735e3fb4bc2a4898cca12fef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Sat, 19 Sep 2026 17:23:00 +0200 Subject: [PATCH 1/4] Add a release workflow that raises the version and publishes --- .github/workflows/release-prepare.yml | 88 +++++++++++++++++++++++++++ .github/workflows/release.yml | 36 ++++++++--- 2 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/release-prepare.yml diff --git a/.github/workflows/release-prepare.yml b/.github/workflows/release-prepare.yml new file mode 100644 index 0000000..e5108e3 --- /dev/null +++ b/.github/workflows/release-prepare.yml @@ -0,0 +1,88 @@ +name: Prepare a release + +on: + workflow_dispatch: + inputs: + bump: + description: Which part of the version to raise + type: choice + required: true + default: patch + options: [major, minor, patch] + +permissions: + contents: write + pull-requests: write + +concurrency: + group: release-prepare + cancel-in-progress: false + +jobs: + prepare: + name: Open the version bump pull request + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BUMP: ${{ inputs.bump }} + steps: + - uses: actions/checkout@v4 + + - name: Compute the new version + id: version + run: | + current="$(sed -n 's/^;; Version: \(.*\)$/\1/p' magit-standup.el)" + IFS=. read -r major minor patch <<< "${current}" + case "${BUMP}" in + major) major=$((major + 1)); minor=0; patch=0 ;; + minor) minor=$((minor + 1)); patch=0 ;; + patch) patch=$((patch + 1)) ;; + *) echo "Unknown bump: ${BUMP}" >&2; exit 1 ;; + esac + new="${major}.${minor}.${patch}" + echo "current=${current}" >> "${GITHUB_OUTPUT}" + echo "new=${new}" >> "${GITHUB_OUTPUT}" + + - name: Raise the version + env: + NEW: ${{ steps.version.outputs.new }} + run: | + sed -i "s/^;; Version: .*/;; Version: ${NEW}/" magit-standup.el + sed -i "2s/\"[0-9][0-9.]*\"/\"${NEW}\"/" Easkfile + grep -qx ";; Version: ${NEW}" magit-standup.el + grep -qx " \"${NEW}\"" Easkfile + git --no-pager diff + + - uses: jcs090218/setup-emacs@master + with: + version: '28.1' + + - uses: emacs-eask/setup-eask@master + with: + version: 'snapshot' + + - name: Check the raised version + run: | + eask package + eask install-deps + eask compile + eask lint package + eask test buttercup + + - name: Open the pull request + env: + CURRENT: ${{ steps.version.outputs.current }} + NEW: ${{ steps.version.outputs.new }} + run: | + branch="release/v${NEW}" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git switch -c "${branch}" + git commit -am "Bump the version to ${NEW}" + git push -u origin "${branch}" + gh pr create \ + --base main \ + --head "${branch}" \ + --label chore \ + --title "Bump the version to ${NEW}" \ + --body "This pull request raises the version from ${CURRENT} to ${NEW}. The checks ran on the raised version before this pull request was opened. When you merge it, a workflow creates the tag v${NEW} and publishes the release with the generated notes." diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad33d66..acc51a1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,19 +4,20 @@ on: push: branches: [main] tags: ['v*'] + pull_request: + types: [closed] permissions: contents: write -concurrency: - group: release - cancel-in-progress: false - jobs: draft: name: Update the draft release - if: startsWith(github.ref, 'refs/heads/') + if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/') runs-on: ubuntu-latest + concurrency: + group: release-draft + cancel-in-progress: false env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} @@ -32,18 +33,35 @@ jobs: --title "Unreleased" \ --generate-notes - release: + publish: name: Publish the release - if: startsWith(github.ref, 'refs/tags/') + if: >- + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || + (github.event_name == 'pull_request' && + github.event.pull_request.merged && + startsWith(github.event.pull_request.head.ref, 'release/')) runs-on: ubuntu-latest + concurrency: + group: release-publish + cancel-in-progress: false env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event_name == 'pull_request' && 'main' || github.ref }} + - name: Create the release run: | - gh release create "${{ github.ref_name }}" \ - --title "${{ github.ref_name }}" \ + if [ "${{ github.event_name }}" = "pull_request" ]; then + tag="v$(sed -n 's/^;; Version: \(.*\)$/\1/p' magit-standup.el)" + else + tag="${{ github.ref_name }}" + fi + gh release create "${tag}" \ + --target "$(git rev-parse HEAD)" \ + --title "${tag}" \ --generate-notes - name: Remove the stale draft release From e37261b3ac6a8a17bad439523383b921984a11e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Sat, 19 Sep 2026 17:48:27 +0200 Subject: [PATCH 2/4] Open the release pull request as the user who runs the workflow --- .github/workflows/release-prepare.yml | 45 +++++++++++---------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/.github/workflows/release-prepare.yml b/.github/workflows/release-prepare.yml index e5108e3..9a107f4 100644 --- a/.github/workflows/release-prepare.yml +++ b/.github/workflows/release-prepare.yml @@ -11,8 +11,7 @@ on: options: [major, minor, patch] permissions: - contents: write - pull-requests: write + contents: read concurrency: group: release-prepare @@ -23,10 +22,19 @@ jobs: name: Open the version bump pull request runs-on: ubuntu-latest env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.RELEASE_TOKEN }} BUMP: ${{ inputs.bump }} steps: + - name: Check the token + run: | + if [ -z "${GH_TOKEN}" ]; then + echo "Add a personal access token as the RELEASE_TOKEN secret." >&2 + exit 1 + fi + - uses: actions/checkout@v4 + with: + token: ${{ secrets.RELEASE_TOKEN }} - name: Compute the new version id: version @@ -53,36 +61,21 @@ jobs: grep -qx " \"${NEW}\"" Easkfile git --no-pager diff - - uses: jcs090218/setup-emacs@master - with: - version: '28.1' - - - uses: emacs-eask/setup-eask@master - with: - version: 'snapshot' - - - name: Check the raised version - run: | - eask package - eask install-deps - eask compile - eask lint package - eask test buttercup - - name: Open the pull request env: CURRENT: ${{ steps.version.outputs.current }} NEW: ${{ steps.version.outputs.new }} run: | - branch="release/v${NEW}" - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git switch -c "${branch}" + actor_id="$(gh api "users/${GITHUB_ACTOR}" --jq '.id')" + actor_name="$(gh api "users/${GITHUB_ACTOR}" --jq '.name // .login')" + git config user.name "${actor_name}" + git config user.email "${actor_id}+${GITHUB_ACTOR}@users.noreply.github.com" + git switch -c "release/v${NEW}" git commit -am "Bump the version to ${NEW}" - git push -u origin "${branch}" + git push -u origin "release/v${NEW}" gh pr create \ --base main \ - --head "${branch}" \ + --head "release/v${NEW}" \ --label chore \ --title "Bump the version to ${NEW}" \ - --body "This pull request raises the version from ${CURRENT} to ${NEW}. The checks ran on the raised version before this pull request was opened. When you merge it, a workflow creates the tag v${NEW} and publishes the release with the generated notes." + --body "This pull request raises the version from ${CURRENT} to ${NEW}. When you merge it, a workflow creates the tag v${NEW} and publishes the release with the generated notes." From 964e377049f74a89beef2f55d005ded99a82c3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Sat, 19 Sep 2026 17:52:56 +0200 Subject: [PATCH 3/4] Author the version bump as the user who runs the workflow --- .github/workflows/release-prepare.yml | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release-prepare.yml b/.github/workflows/release-prepare.yml index 9a107f4..6c18e5b 100644 --- a/.github/workflows/release-prepare.yml +++ b/.github/workflows/release-prepare.yml @@ -11,7 +11,8 @@ on: options: [major, minor, patch] permissions: - contents: read + contents: write + pull-requests: write concurrency: group: release-prepare @@ -22,19 +23,10 @@ jobs: name: Open the version bump pull request runs-on: ubuntu-latest env: - GH_TOKEN: ${{ secrets.RELEASE_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BUMP: ${{ inputs.bump }} steps: - - name: Check the token - run: | - if [ -z "${GH_TOKEN}" ]; then - echo "Add a personal access token as the RELEASE_TOKEN secret." >&2 - exit 1 - fi - - uses: actions/checkout@v4 - with: - token: ${{ secrets.RELEASE_TOKEN }} - name: Compute the new version id: version @@ -68,10 +60,13 @@ jobs: run: | actor_id="$(gh api "users/${GITHUB_ACTOR}" --jq '.id')" actor_name="$(gh api "users/${GITHUB_ACTOR}" --jq '.name // .login')" - git config user.name "${actor_name}" - git config user.email "${actor_id}+${GITHUB_ACTOR}@users.noreply.github.com" + export GIT_AUTHOR_NAME="${actor_name}" + export GIT_AUTHOR_EMAIL="${actor_id}+${GITHUB_ACTOR}@users.noreply.github.com" + export GIT_COMMITTER_NAME="github-actions[bot]" + export GIT_COMMITTER_EMAIL="41898282+github-actions[bot]@users.noreply.github.com" git switch -c "release/v${NEW}" git commit -am "Bump the version to ${NEW}" + git --no-pager log -1 --format='author: %an <%ae>%ncommitter: %cn <%ce>' git push -u origin "release/v${NEW}" gh pr create \ --base main \ From 55658a900bf383131625c9d46beb945c9e8bb69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Sat, 19 Sep 2026 17:54:51 +0200 Subject: [PATCH 4/4] Split the commit step from the pull request step --- .github/workflows/release-prepare.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-prepare.yml b/.github/workflows/release-prepare.yml index 6c18e5b..e1c7b10 100644 --- a/.github/workflows/release-prepare.yml +++ b/.github/workflows/release-prepare.yml @@ -53,9 +53,8 @@ jobs: grep -qx " \"${NEW}\"" Easkfile git --no-pager diff - - name: Open the pull request + - name: Commit the raised version env: - CURRENT: ${{ steps.version.outputs.current }} NEW: ${{ steps.version.outputs.new }} run: | actor_id="$(gh api "users/${GITHUB_ACTOR}" --jq '.id')" @@ -68,6 +67,12 @@ jobs: git commit -am "Bump the version to ${NEW}" git --no-pager log -1 --format='author: %an <%ae>%ncommitter: %cn <%ce>' git push -u origin "release/v${NEW}" + + - name: Open the pull request + env: + CURRENT: ${{ steps.version.outputs.current }} + NEW: ${{ steps.version.outputs.new }} + run: | gh pr create \ --base main \ --head "release/v${NEW}" \