From 246367cca32439b3429e4b6ec64e6852c99606be Mon Sep 17 00:00:00 2001 From: Joshua Zillwood Date: Thu, 21 May 2026 13:07:22 -0500 Subject: [PATCH 1/3] ci(release): add auto-merge PR and tag-on-main workflows After a successful publish, opens a PR from the release branch to main with auto-merge enabled. A separate tag.yml creates the vX.Y.Z git tag on main once the PR merges. --- .github/workflows/release.yml | 30 +++++++++++++++++++++++++++ .github/workflows/tag.yml | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f2000d3..eb4123e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -74,3 +74,33 @@ jobs: --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate + + merge: + name: Open PR to Main + runs-on: ubuntu-latest + needs: publish + permissions: + pull-requests: write + steps: + - name: Extract version from branch name + id: version + run: | + BRANCH="${GITHUB_REF#refs/heads/}" + VERSION="${BRANCH#release/v}" + if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "Invalid version format in branch name: $BRANCH" + exit 1 + fi + echo "value=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Create PR and enable auto-merge + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR_URL=$(gh pr create \ + --repo "$GITHUB_REPOSITORY" \ + --title "Release v${{ steps.version.outputs.value }}" \ + --body "Automated release PR for v${{ steps.version.outputs.value }}. Package published to NuGet successfully." \ + --base main \ + --head "${{ github.ref_name }}") + gh pr merge "$PR_URL" --merge --auto diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..3a604c5 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,38 @@ +name: Tag Release + +on: + pull_request: + types: [closed] + branches: + - main + +jobs: + tag: + name: Create Release Tag + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/') + permissions: + contents: write + steps: + - uses: actions/checkout@v6 + with: + ref: main + fetch-depth: 0 + + - name: Extract version from branch name + id: version + run: | + BRANCH="${{ github.event.pull_request.head.ref }}" + VERSION="${BRANCH#release/v}" + if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "Invalid version format: $BRANCH" + exit 1 + fi + echo "value=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Create and push tag + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag "v${{ steps.version.outputs.value }}" + git push origin "v${{ steps.version.outputs.value }}" From c889ba5b9f43ea989fa42ba31b721e16a8d3dca9 Mon Sep 17 00:00:00 2001 From: Joshua Zillwood Date: Thu, 21 May 2026 17:32:54 -0500 Subject: [PATCH 2/3] refactor(release): extract version parsing to script, use job outputs --- .github/scripts/extract-version.sh | 9 +++++++++ .github/workflows/release.yml | 24 +++++------------------- .github/workflows/tag.yml | 7 +------ 3 files changed, 15 insertions(+), 25 deletions(-) create mode 100644 .github/scripts/extract-version.sh diff --git a/.github/scripts/extract-version.sh b/.github/scripts/extract-version.sh new file mode 100644 index 0000000..ce22593 --- /dev/null +++ b/.github/scripts/extract-version.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail +BRANCH="$1" +VERSION="${BRANCH#release/v}" +if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "Invalid version format: $BRANCH (expected release/vX.Y.Z)" >&2 + exit 1 +fi +echo "$VERSION" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb4123e..ee9dca4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,6 +36,8 @@ jobs: name: Pack and Publish runs-on: ubuntu-latest needs: test + outputs: + version: ${{ steps.version.outputs.value }} steps: - uses: actions/checkout@v6 with: @@ -44,12 +46,7 @@ jobs: - name: Extract version from branch name id: version run: | - BRANCH="${GITHUB_REF#refs/heads/}" - VERSION="${BRANCH#release/v}" - if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then - echo "Invalid version format in branch name: $BRANCH (expected release/vX.Y.Z)" - exit 1 - fi + VERSION=$(bash .github/scripts/extract-version.sh "${GITHUB_REF#refs/heads/}") echo "value=$VERSION" >> "$GITHUB_OUTPUT" - name: Setup .NET @@ -82,25 +79,14 @@ jobs: permissions: pull-requests: write steps: - - name: Extract version from branch name - id: version - run: | - BRANCH="${GITHUB_REF#refs/heads/}" - VERSION="${BRANCH#release/v}" - if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then - echo "Invalid version format in branch name: $BRANCH" - exit 1 - fi - echo "value=$VERSION" >> "$GITHUB_OUTPUT" - - name: Create PR and enable auto-merge env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | PR_URL=$(gh pr create \ --repo "$GITHUB_REPOSITORY" \ - --title "Release v${{ steps.version.outputs.value }}" \ - --body "Automated release PR for v${{ steps.version.outputs.value }}. Package published to NuGet successfully." \ + --title "Release v${{ needs.publish.outputs.version }}" \ + --body "Automated release PR for v${{ needs.publish.outputs.version }}. Package published to NuGet successfully." \ --base main \ --head "${{ github.ref_name }}") gh pr merge "$PR_URL" --merge --auto diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 3a604c5..ccc3011 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -22,12 +22,7 @@ jobs: - name: Extract version from branch name id: version run: | - BRANCH="${{ github.event.pull_request.head.ref }}" - VERSION="${BRANCH#release/v}" - if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then - echo "Invalid version format: $BRANCH" - exit 1 - fi + VERSION=$(bash .github/scripts/extract-version.sh "${{ github.event.pull_request.head.ref }}") echo "value=$VERSION" >> "$GITHUB_OUTPUT" - name: Create and push tag From a552a3a4d20833def7a2095106fd949377ffba68 Mon Sep 17 00:00:00 2001 From: Joshua Zillwood Date: Thu, 21 May 2026 17:34:37 -0500 Subject: [PATCH 3/3] style(release): add spacing to extract-version script --- .github/scripts/extract-version.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/scripts/extract-version.sh b/.github/scripts/extract-version.sh index ce22593..1daabcd 100644 --- a/.github/scripts/extract-version.sh +++ b/.github/scripts/extract-version.sh @@ -1,9 +1,13 @@ #!/usr/bin/env bash + set -euo pipefail + BRANCH="$1" VERSION="${BRANCH#release/v}" + if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then echo "Invalid version format: $BRANCH (expected release/vX.Y.Z)" >&2 exit 1 fi + echo "$VERSION"