diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml new file mode 100644 index 0000000..7eec4b2 --- /dev/null +++ b/.github/workflows/auto-tag.yml @@ -0,0 +1,28 @@ +name: Auto Tag on Release PR Merge + +on: + pull_request: + types: [closed] + branches: [main] + +jobs: + tag: + if: > + github.event.pull_request.merged == true && + startsWith(github.event.pull_request.title, 'Release v') + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - name: Extract version from PR title + id: version + run: | + VERSION=$(echo "${{ github.event.pull_request.title }}" | sed 's/^Release //') + echo "tag=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Create and push tag + run: | + git tag "${{ steps.version.outputs.tag }}" + git push origin "${{ steps.version.outputs.tag }}" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d9cd61e..0a4a2c1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,6 +19,16 @@ jobs: - run: npm ci - run: npm run build - run: npm test - - run: npm publish + - name: Determine npm tag + id: npm-tag + run: | + VERSION="${GITHUB_REF#refs/tags/v}" + if echo "$VERSION" | grep -qE '(alpha|beta|rc|next)'; then + echo "tag=next" >> "$GITHUB_OUTPUT" + else + echo "tag=latest" >> "$GITHUB_OUTPUT" + fi + + - run: npm publish --tag ${{ steps.npm-tag.outputs.tag }} env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}