|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write # create the "Version Packages" PR + commits + tags |
| 10 | + pull-requests: write # open + update the "Version Packages" PR |
| 11 | + id-token: write # npm provenance |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +jobs: |
| 18 | + release: |
| 19 | + name: Version + publish |
| 20 | + runs-on: ubuntu-latest |
| 21 | + # Don't run on forks — they'd hit "no NPM_TOKEN" anyway, but skipping |
| 22 | + # early keeps the Actions tab clean for fork PR runs. |
| 23 | + if: github.repository == 'level0x40/react-git' |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + # Full history so changesets can read tag history when |
| 29 | + # generating the changelog. |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Install pnpm |
| 33 | + uses: pnpm/action-setup@v4 |
| 34 | + with: |
| 35 | + run_install: false |
| 36 | + |
| 37 | + - name: Setup Node.js |
| 38 | + uses: actions/setup-node@v4 |
| 39 | + with: |
| 40 | + node-version-file: ".nvmrc" |
| 41 | + cache: "pnpm" |
| 42 | + registry-url: "https://registry.npmjs.org" |
| 43 | + |
| 44 | + - name: Install dependencies |
| 45 | + run: pnpm install --frozen-lockfile |
| 46 | + |
| 47 | + # The dual-mode of changesets/action: |
| 48 | + # |
| 49 | + # 1. If there are unreleased changeset files in `.changeset/`, the |
| 50 | + # action runs `pnpm version` (which calls `changeset version`) |
| 51 | + # and opens / updates a "Version Packages" PR with the bumped |
| 52 | + # versions and CHANGELOG entries. |
| 53 | + # |
| 54 | + # 2. If those changeset files are GONE (because the previous |
| 55 | + # Version Packages PR was just merged), the action runs |
| 56 | + # `pnpm release` — which is `pnpm publish -r --provenance` — |
| 57 | + # and ships the bumped packages to npm with provenance |
| 58 | + # attestations. `id-token: write` (granted at the workflow |
| 59 | + # level above) is what authenticates the OIDC step npm needs |
| 60 | + # to sign the provenance statement. |
| 61 | + # |
| 62 | + # Two distinct outcomes, one trigger — same workflow handles both. |
| 63 | + - name: Create Release Pull Request or publish |
| 64 | + uses: changesets/action@v1 |
| 65 | + with: |
| 66 | + version: pnpm version |
| 67 | + publish: pnpm release |
| 68 | + commit: "chore: version packages" |
| 69 | + title: "chore: version packages" |
| 70 | + env: |
| 71 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments