|
1 | | -name: Publish Package to npmjs |
| 1 | +name: Release |
| 2 | + |
2 | 3 | on: |
3 | | - release: |
4 | | - types: [published] |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + # Manual safety valve: re-run publish for a version that was bumped but never |
| 8 | + # published. Guarded below so a dispatch can only ever publish from main. |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +concurrency: |
| 12 | + # Never cancel an in-progress release; queue concurrent runs instead. |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write # push the version PR branch, create tags + GitHub releases |
| 18 | + pull-requests: write # open/update the changesets "Release PR" |
| 19 | + id-token: write # npm Trusted Publishing (OIDC) — no long-lived NPM_TOKEN needed |
| 20 | + |
5 | 21 | jobs: |
6 | | - npm-publish: |
| 22 | + release: |
| 23 | + name: Release |
| 24 | + # Don't run on forks; only ever publish from main (incl. workflow_dispatch). |
| 25 | + if: github.repository_owner == 'code-forge-io' && github.ref == 'refs/heads/main' |
7 | 26 | runs-on: ubuntu-latest |
8 | 27 | steps: |
9 | | - - uses: actions/checkout@v4 |
10 | | - # Setup .npmrc file to publish to npm |
11 | | - - uses: actions/setup-node@v4 |
| 28 | + - name: Checkout Repo |
| 29 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
12 | 30 | with: |
13 | | - node-version: "20.x" |
| 31 | + fetch-depth: 0 |
| 32 | + # Required so changesets/action can push the version PR branch. Only the |
| 33 | + # ephemeral GITHUB_TOKEN is persisted (auto-expires at job end) — no PAT. |
| 34 | + persist-credentials: true |
| 35 | + |
| 36 | + - name: Setup Node.js |
| 37 | + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 38 | + with: |
| 39 | + # Pin to Node 24 (ships npm 11.x); npm OIDC Trusted Publishing needs >= 11.5.1. |
| 40 | + node-version: "24" |
14 | 41 | registry-url: "https://registry.npmjs.org" |
15 | | - - run: npm ci |
16 | | - - run: npm publish |
| 42 | + |
| 43 | + - name: Install Dependencies |
| 44 | + run: npm ci |
| 45 | + |
| 46 | + - name: Create Release Pull Request or Publish to npm |
| 47 | + id: changesets |
| 48 | + uses: changesets/action@6a0a831ff30acef54f2c6aa1cbbc1096b066edaf # v1.7.0 |
17 | 49 | env: |
18 | | - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 50 | + # Only used to open/update the Release PR and create GitHub releases. |
| 51 | + # npm authentication is handled by OIDC Trusted Publishing (.npmrc |
| 52 | + # provenance=true + id-token:write) — there is intentionally no NPM_TOKEN. |
| 53 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + with: |
| 55 | + title: "🚀 Release PR" |
| 56 | + commit: "chore: release" |
| 57 | + version: npm run changeset:version |
| 58 | + publish: npm run changeset:publish |
| 59 | + createGithubReleases: true |
0 commit comments