From 8df4da9b8c25df43450995aee638b9e05aaccc0a Mon Sep 17 00:00:00 2001 From: Yasodha Dollu Date: Wed, 18 Mar 2026 16:48:06 +0530 Subject: [PATCH] chore: split version bump script to create a tag on merge --- .github/workflows/tag-on-release-pr-merge.yml | 48 +++++++++++++++++++ .github/workflows/version-bump.yml | 17 +++---- 2 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/tag-on-release-pr-merge.yml diff --git a/.github/workflows/tag-on-release-pr-merge.yml b/.github/workflows/tag-on-release-pr-merge.yml new file mode 100644 index 0000000..3fc30ed --- /dev/null +++ b/.github/workflows/tag-on-release-pr-merge.yml @@ -0,0 +1,48 @@ +name: Tag Release After Merge + +on: + pull_request: + types: + - closed + branches: + - main + +permissions: + contents: write + +concurrency: + group: tag-release-${{ github.event.pull_request.number }} + cancel-in-progress: false + +jobs: + create-tag: + name: Create Version Tag + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/') + steps: + - name: Checkout merged main + uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + + - name: Configure git + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + - name: Create and push tag + run: | + VERSION=$(node -p "require('./package.json').version") + TAG="v$VERSION" + + # Ensure local tags are up to date before existence check. + git fetch --tags + + if git rev-parse "$TAG" >/dev/null 2>&1; then + echo "Tag $TAG already exists, skipping." + exit 0 + fi + + git tag "$TAG" + git push origin "$TAG" diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 4b2cad1..5a89bb3 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -4,9 +4,9 @@ on: workflow_dispatch: inputs: version_type: - description: "Version bump type" + description: 'Version bump type' required: true - default: "patch" + default: 'patch' type: choice options: - major @@ -17,7 +17,7 @@ on: - prepatch - prerelease prerelease_id: - description: "Prerelease identifier (only used for prerelease versions)" + description: 'Prerelease identifier (only used for prerelease versions)' required: false type: choice options: @@ -58,8 +58,8 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4.0.2 with: - node-version: "20" - cache: "pnpm" + node-version: '20' + cache: 'pnpm' - name: Configure git run: | @@ -199,9 +199,6 @@ jobs: echo "release_branch=$RELEASE_BRANCH" >> $GITHUB_OUTPUT - - name: Authenticate GitHub CLI - run: gh auth setup-git - - name: Create Pull Request env: GH_TOKEN: ${{ github.token }} @@ -225,7 +222,7 @@ jobs: ### Next steps 1. Review and merge this PR - 2. Create and push tag \`$NEW_VERSION\` from \`main\` - 3. Publish workflow will run from tag push + 2. Tag is created automatically after merge + 3. Publish workflow runs from the tag push EOF )"