|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version to release (x.y.z or x.y.z-tag)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + id-token: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + name: Publish to npm and GitHub Releases |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + |
| 25 | + - uses: pnpm/action-setup@v4 |
| 26 | + with: |
| 27 | + version: 9 |
| 28 | + |
| 29 | + - uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + node-version: 22 |
| 32 | + cache: pnpm |
| 33 | + registry-url: https://registry.npmjs.org |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: pnpm install --frozen-lockfile |
| 37 | + |
| 38 | + - name: Validate version input |
| 39 | + run: | |
| 40 | + echo "${{ inputs.version }}" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.\-]+)?$' || { |
| 41 | + echo "::error::version must look like x.y.z or x.y.z-tag" |
| 42 | + exit 1 |
| 43 | + } |
| 44 | +
|
| 45 | + - name: Lint |
| 46 | + run: pnpm lint |
| 47 | + |
| 48 | + - name: Typecheck |
| 49 | + run: pnpm typecheck |
| 50 | + |
| 51 | + - name: Test |
| 52 | + run: pnpm test |
| 53 | + |
| 54 | + - name: Build |
| 55 | + run: pnpm build |
| 56 | + |
| 57 | + - name: Set package version |
| 58 | + id: bump |
| 59 | + run: | |
| 60 | + npm pkg set version="${{ inputs.version }}" |
| 61 | + echo "version=${{ inputs.version }}" >> "$GITHUB_OUTPUT" |
| 62 | + echo "tag=v${{ inputs.version }}" >> "$GITHUB_OUTPUT" |
| 63 | +
|
| 64 | + - name: Determine npm dist-tag |
| 65 | + id: tag |
| 66 | + run: | |
| 67 | + if echo "${{ steps.bump.outputs.version }}" | grep -q '-'; then |
| 68 | + echo "dist=next" >> "$GITHUB_OUTPUT" |
| 69 | + else |
| 70 | + echo "dist=latest" >> "$GITHUB_OUTPUT" |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: Commit version bump |
| 74 | + run: | |
| 75 | + git config user.name "github-actions[bot]" |
| 76 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 77 | + git add package.json |
| 78 | + git diff --staged --quiet || git commit -m "chore(release): ${{ steps.bump.outputs.tag }}" |
| 79 | + git tag "${{ steps.bump.outputs.tag }}" |
| 80 | + git push origin HEAD:${{ github.ref_name }} --follow-tags |
| 81 | +
|
| 82 | + - name: Publish to npm |
| 83 | + run: npm publish --provenance --access public --tag ${{ steps.tag.outputs.dist }} |
| 84 | + env: |
| 85 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 86 | + |
| 87 | + - name: Create GitHub Release |
| 88 | + uses: softprops/action-gh-release@v2 |
| 89 | + with: |
| 90 | + tag_name: ${{ steps.bump.outputs.tag }} |
| 91 | + name: ${{ steps.bump.outputs.tag }} |
| 92 | + generate_release_notes: true |
| 93 | + prerelease: ${{ steps.tag.outputs.dist == 'next' }} |
0 commit comments