diff --git a/.github/scripts/extract-version.sh b/.github/scripts/extract-version.sh new file mode 100644 index 0000000..1daabcd --- /dev/null +++ b/.github/scripts/extract-version.sh @@ -0,0 +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" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f2000d3..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 @@ -74,3 +71,22 @@ 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: Create PR and enable auto-merge + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR_URL=$(gh pr create \ + --repo "$GITHUB_REPOSITORY" \ + --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 new file mode 100644 index 0000000..ccc3011 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,33 @@ +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: | + VERSION=$(bash .github/scripts/extract-version.sh "${{ github.event.pull_request.head.ref }}") + 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 }}"