|
| 1 | +name: Build & Publish Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - released |
| 7 | + - prereleased |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: "release-${{ github.event.release.id }}" |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +permissions: |
| 14 | + id-token: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + sanity-checks: |
| 18 | + name: Sanity Checks |
| 19 | + permissions: |
| 20 | + id-token: none |
| 21 | + uses: ./.github/workflows/sanity-checks.yml |
| 22 | + |
| 23 | + add-publishing-note: |
| 24 | + name: Add Publishing Note |
| 25 | + if: github.event.release != null |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + contents: write |
| 29 | + id-token: none |
| 30 | + concurrency: |
| 31 | + group: "release-editing-${{ github.event.release.id }}" |
| 32 | + steps: |
| 33 | + - name: "Update Release Title & Description" |
| 34 | + uses: actions/github-script@v8 |
| 35 | + with: |
| 36 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + script: | |
| 38 | + github.rest.repos.updateRelease({ |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + release_id: context.payload.release.id, |
| 42 | + name: context.payload.release.name + " (Building)", |
| 43 | + body: context.payload.release.body + "\n\n<!-- ACTIONS_REMOVE_AFTER_BUILD -->\n\n---\n\n> [!NOTE]\n> ### This release is currently being built.\n> Build artifacts will be added to this release once the build is complete. For now, you can watch the build progress from [its GitHub Actions page](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).", |
| 44 | + }) |
| 45 | +
|
| 46 | + build-and-publish: |
| 47 | + name: Build & Publish |
| 48 | + needs: [sanity-checks, add-publishing-note] |
| 49 | + runs-on: ubuntu-latest |
| 50 | + permissions: |
| 51 | + id-token: write |
| 52 | + packages: write |
| 53 | + contents: write |
| 54 | + steps: |
| 55 | + - name: Checkout |
| 56 | + uses: actions/checkout@v5.0.0 |
| 57 | + with: |
| 58 | + fetch-depth: 0 |
| 59 | + |
| 60 | + - name: Setup Tools |
| 61 | + uses: tanstack/config/.github/setup@9286c261b7c25a2c0342e2a06510f9cd9e4512f6 |
| 62 | + |
| 63 | + - name: Set package.json Version Field to the Release's Tag |
| 64 | + uses: BellCubeDev/update-package-version-by-release-tag@v2 |
| 65 | + with: |
| 66 | + ignore-semver-check: "true" |
| 67 | + |
| 68 | + - name: Run Build |
| 69 | + run: pnpm run build |
| 70 | + |
| 71 | + - name: PNPM Pack |
| 72 | + run: | |
| 73 | + pnpm pack |
| 74 | +
|
| 75 | + ###################### |
| 76 | + ## ## |
| 77 | + ## NPM Registry ## |
| 78 | + ## ## |
| 79 | + ###################### |
| 80 | + |
| 81 | + - id: publish-npm |
| 82 | + name: Publish to NPM Registry |
| 83 | + # Uses OIDC token to authenticate, so no need to set up a secret for this |
| 84 | + # This does restrict us to only using base `npm`, though 🙁 |
| 85 | + run: | |
| 86 | + pnpm dlx npm publish --access public --registry https://registry.npmjs.org/ --tag ${{ github.event.release.prerelease && 'next' || 'latest' }} --provenance |
| 87 | +
|
| 88 | + - name: ON FAILURE - cat NPM debug log for "Publish to NPM Registry" |
| 89 | + if: always() && steps.publish-npm.outcome == 'failure' |
| 90 | + run: | |
| 91 | + echo "ACTIONS_ID_TOKEN_REQUEST_URL: $ACTIONS_ID_TOKEN_REQUEST_URL" |
| 92 | + echo "ACTIONS_ID_TOKEN_REQUEST_TOKEN is set: ${{ env.ACTIONS_ID_TOKEN_REQUEST_TOKEN != '' }}" |
| 93 | + echo "" |
| 94 | + echo "" |
| 95 | + cat ~/.npm/_logs/*.log || echo "No NPM log file found" |
| 96 | +
|
| 97 | + ################################# |
| 98 | + ## ## |
| 99 | + ## GitHub Package Registry ## |
| 100 | + ## ## |
| 101 | + ################################# |
| 102 | + |
| 103 | + - uses: jossef/action-set-json-field@v2.1 |
| 104 | + name: "Change Package Name for GitHub Package Registry" |
| 105 | + with: |
| 106 | + file: package.json |
| 107 | + field: name |
| 108 | + value: "@${{ github.repository_owner }}/${{ github.event.repository.name }}" |
| 109 | + |
| 110 | + - id: publish-gpr |
| 111 | + name: Publish to GitHub Package Registry |
| 112 | + env: |
| 113 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 114 | + run: | |
| 115 | + pnpm dlx npm publish --access public --registry https://npm.pkg.github.com --tag ${{ github.event.release.prerelease && 'next' || 'latest' }} --provenance |
| 116 | +
|
| 117 | + - name: ON FAILURE - cat NPM debug log for "Publish to GitHub Package Registry" |
| 118 | + if: always() && steps.publish-gpr.outcome == 'failure' |
| 119 | + run: | |
| 120 | + echo "ACTIONS_ID_TOKEN_REQUEST_URL: $ACTIONS_ID_TOKEN_REQUEST_URL" |
| 121 | + echo "ACTIONS_ID_TOKEN_REQUEST_TOKEN is set: ${{ env.ACTIONS_ID_TOKEN_REQUEST_TOKEN != '' }}" |
| 122 | + echo "" |
| 123 | + echo "" |
| 124 | + cat ~/.npm/_logs/*.log || echo "No NPM log file found" |
| 125 | +
|
| 126 | + ########################### |
| 127 | + ## ## |
| 128 | + ## Release Artifacts ## |
| 129 | + ## ## |
| 130 | + ########################### |
| 131 | + |
| 132 | + - name: "Upload Files to Release" |
| 133 | + if: github.event.release != null |
| 134 | + uses: AButler/upload-release-assets@v3.0 |
| 135 | + with: |
| 136 | + files: "*.tgz" |
| 137 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 138 | + release-id: ${{ github.event.release.id }} |
| 139 | + |
| 140 | + - name: "Update Release Title & Description" |
| 141 | + if: github.event.release != null |
| 142 | + uses: actions/github-script@v8 |
| 143 | + with: |
| 144 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + script: | |
| 146 | + github.rest.repos.updateRelease({ |
| 147 | + owner: context.repo.owner, |
| 148 | + repo: context.repo.repo, |
| 149 | + release_id: context.payload.release.id, |
| 150 | + name: context.payload.release.name.replace(/\s+\(Building\)$/, ''), |
| 151 | + body: context.payload.release.body.replace(/<!-- ACTIONS_REMOVE_AFTER_BUILD -->[\s\S]*$/, '') + "\n\n---\n\n##### Built successfully by [GitHub Actions run #${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).", |
| 152 | + }) |
| 153 | +
|
| 154 | +
|
| 155 | + note-release-build-failed: |
| 156 | + permissions: |
| 157 | + contents: write |
| 158 | + id-token: none |
| 159 | + name: "Note Release Build Failed" |
| 160 | + needs: [build-and-publish] |
| 161 | + if: failure() && github.event.release != null |
| 162 | + runs-on: ubuntu-latest |
| 163 | + concurrency: |
| 164 | + group: "release-editing-${{ github.event.release.id }}" |
| 165 | + steps: |
| 166 | + - name: "Update Release Title & Description" |
| 167 | + uses: actions/github-script@v7 |
| 168 | + with: |
| 169 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 170 | + script: | |
| 171 | + github.rest.repos.updateRelease({ |
| 172 | + owner: context.repo.owner, |
| 173 | + repo: context.repo.repo, |
| 174 | + release_id: context.payload.release.id, |
| 175 | + name: context.payload.release.name.replace(/\s+\(Building\)$/, '') + " (Failed)", |
| 176 | + body: "> [!CAUTION]\n> ### This Release's Build Failed\n> The build for this release failed. You can see where and why the build failed in [its GitHub Action page](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).\n\n---\n\n" + context.payload.release.body.replace(/<!-- ACTIONS_REMOVE_AFTER_BUILD -->[\s\S]*$/, ''), |
| 177 | + }) |
0 commit comments