Tag for catbee-technologies/catbee-utils on v2 #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tag | |
| run-name: Tag for ${{ github.repository }} on ${{ github.ref_name }} | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - v2 | |
| paths: | |
| - "package.json" | |
| permissions: | |
| contents: write | |
| statuses: write | |
| jobs: | |
| detect: | |
| name: Detect Version Changes | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version_changed: ${{ steps.check.outputs.version_changed }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if version changed | |
| id: check | |
| run: | | |
| old=$(git show HEAD~1:package.json | jq -r '.version') | |
| new=$(jq -r '.version' package.json) | |
| echo "Root package.json version check → old=$old new=$new" | |
| if [ "$old" != "$new" ]; then | |
| echo "version_changed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "version_changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Summary | |
| run: | | |
| echo "Version changed? ${{ steps.check.outputs.version_changed }}" | |
| no-version-changes: | |
| name: Report No Version Changes | |
| needs: detect | |
| if: needs.detect.outputs.version_changed != 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Report no version changes | |
| uses: actions/github-script@v7 | |
| env: | |
| TARGET_SHA: ${{ github.sha }} | |
| with: | |
| script: | | |
| const targetUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; | |
| await github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha: process.env.TARGET_SHA, | |
| state: "success", | |
| context: "Tag", | |
| description: "No version changes", | |
| target_url: targetUrl | |
| }); | |
| auto-tag: | |
| name: Create Tag for Version Bump | |
| needs: detect | |
| if: needs.detect.outputs.version_changed == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Create tag | |
| run: | | |
| new_version=$(jq -r '.version' package.json) | |
| tag="v${new_version}" | |
| echo "Creating tag: $tag" | |
| if git tag "$tag"; then | |
| echo "CREATED=1" >> $GITHUB_ENV | |
| echo "CREATED_TAG=$tag" >> $GITHUB_ENV | |
| else | |
| echo "Tag exists or failed" | |
| echo "CREATED=0" >> $GITHUB_ENV | |
| fi | |
| - name: Push tag | |
| if: env.CREATED == '1' | |
| run: git push --tags | |
| - name: Notify commit about tag | |
| if: success() | |
| uses: actions/github-script@v7 | |
| env: | |
| TARGET_SHA: ${{ github.sha }} | |
| CREATED_TAG: ${{ env.CREATED_TAG }} | |
| with: | |
| script: | | |
| const tag = (process.env.CREATED_TAG || "").trim(); | |
| const description = tag ? `Created tag: ${tag}` : "No tag created"; | |
| const targetUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; | |
| await github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha: process.env.TARGET_SHA, | |
| state: "success", | |
| context: "Tag", | |
| description, | |
| target_url: targetUrl | |
| }); | |
| - name: Trigger publish workflow when tag exists | |
| if: env.CREATED != '0' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.repos.createDispatchEvent({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| event_type: "publish_packages", | |
| client_payload: { | |
| tag: process.env.CREATED_TAG, | |
| sha: process.env.GITHUB_SHA | |
| } | |
| }); |