From 4beee54a608f7a25f186c5d03545fe5285e7619f Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Wed, 27 Aug 2025 17:49:43 -0700 Subject: [PATCH] feat: add auto-tagging workflow - Automatically creates tags when package.json version changes - Builds the action and commits dist files if needed - Creates both specific version tags (v0.0.x) and major version tags (v0) - Creates GitHub releases with usage examples --- .github/workflows/auto-tag-release.yml | 108 +++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 .github/workflows/auto-tag-release.yml diff --git a/.github/workflows/auto-tag-release.yml b/.github/workflows/auto-tag-release.yml new file mode 100644 index 0000000..3de81e3 --- /dev/null +++ b/.github/workflows/auto-tag-release.yml @@ -0,0 +1,108 @@ +name: Auto-tag Action Release + +on: + push: + branches: [main] + paths: + - 'package.json' + +permissions: + contents: write + +jobs: + auto-tag: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: latest + + - name: Get package version + id: version + run: | + VERSION=$(node -p "require('./package.json').version") + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "tag=v$VERSION" >> $GITHUB_OUTPUT + + # Extract major version (e.g., "0" from "0.0.1") + MAJOR_VERSION=$(echo $VERSION | cut -d. -f1) + echo "major_tag=v$MAJOR_VERSION" >> $GITHUB_OUTPUT + + - name: Check if tag already exists + id: check_tag + run: | + if git rev-parse "refs/tags/${{ steps.version.outputs.tag }}" >/dev/null 2>&1; then + echo "exists=true" >> $GITHUB_OUTPUT + echo "Tag ${{ steps.version.outputs.tag }} already exists" + else + echo "exists=false" >> $GITHUB_OUTPUT + echo "Tag ${{ steps.version.outputs.tag }} does not exist" + fi + + - name: Install dependencies and build + if: steps.check_tag.outputs.exists == 'false' + run: | + pnpm install + pnpm run build + + - name: Commit built files if changed + if: steps.check_tag.outputs.exists == 'false' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + if [[ -n $(git status --porcelain) ]]; then + git add dist/ + git commit -m "chore: rebuild action for v${{ steps.version.outputs.version }}" + git push + fi + + - name: Create and push tags + if: steps.check_tag.outputs.exists == 'false' + run: | + # Create specific version tag + git tag ${{ steps.version.outputs.tag }} + git push origin ${{ steps.version.outputs.tag }} + + # Create/update major version tag (moving tag) + git tag -f ${{ steps.version.outputs.major_tag }} + git push origin ${{ steps.version.outputs.major_tag }} --force + + - name: Create GitHub Release + if: steps.check_tag.outputs.exists == 'false' + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.version.outputs.tag }} + release_name: Action Release ${{ steps.version.outputs.tag }} + body: | + Automated release for action version ${{ steps.version.outputs.version }} + + ## Usage + + ```yaml + - uses: pullfrog/pullfrog@${{ steps.version.outputs.major_tag }} + with: + message: "Your message here" + ``` + + Or use the specific version: + ```yaml + - uses: pullfrog/pullfrog@${{ steps.version.outputs.tag }} + with: + message: "Your message here" + ``` + draft: false + prerelease: false