|
9 | 9 | permissions: |
10 | 10 | contents: write |
11 | 11 |
|
12 | | -# This action requires a GitHub app with content write access installed |
| 12 | +# This action requires a GitHub app with content write access installed |
13 | 13 | # to bypass the main branch protection rule and dispatch the event to a different repo |
14 | 14 |
|
15 | 15 | jobs: |
16 | 16 | release: |
17 | 17 | runs-on: ubuntu-latest |
18 | | - outputs: |
| 18 | + outputs: |
19 | 19 | no_commit: ${{ steps.git-release.outputs.NO_COMMIT }} |
20 | 20 | steps: |
21 | 21 | - name: Generate a token |
|
53 | 53 | node-version: ${{ env.NODE }} |
54 | 54 | registry-url: https://registry.npmjs.org/ |
55 | 55 | - run: yarn |
| 56 | + # Clean up any stale version tags left from failed release runs. |
| 57 | + # Context: |
| 58 | + # - Each release run uses release-it to bump package.json, create a new Git tag (e.g., v7.0.0), |
| 59 | + # and then publish to NPM. If the run fails after the tag is created but before publish, |
| 60 | + # that tag remains both locally in the local repo (inside the GitHub Actions runner) and remotely on GitHub. |
| 61 | + # - "Locally" refers to the temporary clone created by actions/checkout@v4 inside the workflow runner. |
| 62 | + # - "Remotely" refers to the GitHub repository itself ("origin" on GitHub.com). |
| 63 | + # The command `git push origin :refs/tags/v7.0.0` deletes the remote tag. |
| 64 | + # - On the next run, if that stale tag still exists, release-it detects no version change |
| 65 | + # and fails with “Version not changed”. |
| 66 | + # This step checks whether the tag for the current package.json version already exists, |
| 67 | + # and deletes it locally and remotely so release-it can safely recreate it during this run. |
| 68 | + - name: Clean stale tags from failed releases |
| 69 | + run: | |
| 70 | + CURRENT_VERSION=$(node -p "require('./package.json').version") |
| 71 | + echo "Checking for existing tag v$CURRENT_VERSION..." |
| 72 | + if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then |
| 73 | + echo "Removing stale tag v$CURRENT_VERSION" |
| 74 | + git tag -d "v$CURRENT_VERSION" || true |
| 75 | + git push origin ":refs/tags/v$CURRENT_VERSION" || true |
| 76 | + fi |
56 | 77 | - name: Release through Git |
57 | 78 | id: git-release |
58 | 79 | run: yarn release --ci --verbose |
|
83 | 104 | client-payload: '{"ref": "${{ github.ref }}", "VERSION_NUMBER": ${{ env.VERSION }}}' |
84 | 105 | notify: |
85 | 106 | # If any of job fails |
86 | | - if: failure() |
| 107 | + if: failure() |
87 | 108 | runs-on: ubuntu-latest |
88 | 109 | needs: |
89 | 110 | - release |
|
0 commit comments