|
1 | 1 | name: publish |
2 | 2 |
|
| 3 | +# All npm-publishing flows live in this single file. npm's trusted-publisher |
| 4 | +# config for every `@stacks/*` package points at `publish.yml` — renaming this |
| 5 | +# file requires updating that config on npmjs.com per package. |
| 6 | +# |
| 7 | +# release — push to main / workflow_dispatch. |
| 8 | +# changesets/action opens/updates the "chore: version packages" |
| 9 | +# PR. When that PR is merged, the same action publishes the |
| 10 | +# bumped packages to npm under `latest`. `commitMode: github-api` |
| 11 | +# gives commits a Verified badge without signing keys in CI. |
| 12 | +# |
| 13 | +# beta — push to main. |
| 14 | +# Snapshot-publishes every push to `@beta`, with versions of the |
| 15 | +# form `<next-release>-beta.<N>` (counter scoped to the base |
| 16 | +# version, queried from npm). |
| 17 | +# |
| 18 | +# pr — pull_request. |
| 19 | +# Same as `beta` but `@pr` dist-tag and versions of the form |
| 20 | +# `<next-release>-pr.<PR#>.<N>`. Sticky-header'd into the PR |
| 21 | +# description so reviewers can install the canary build. |
| 22 | +# |
| 23 | +# Forks never reach the publish step (`is-not-fork` gate from pre-run). |
| 24 | + |
3 | 25 | on: |
4 | 26 | push: |
5 | 27 | branches: |
6 | 28 | - main |
7 | 29 | tags-ignore: |
8 | | - - "**" |
| 30 | + - '**' |
9 | 31 | paths-ignore: |
10 | | - - "**.md" |
| 32 | + - '**.md' |
11 | 33 |
|
12 | 34 | workflow_dispatch: |
| 35 | + inputs: |
| 36 | + pr-number: |
| 37 | + description: 'PR number to publish a canary build for (leave blank for a normal release dispatch)' |
| 38 | + type: string |
| 39 | + required: false |
| 40 | + default: '' |
13 | 41 |
|
14 | 42 | permissions: |
15 | | - id-token: write # Required for OIDC |
16 | | - contents: read |
| 43 | + contents: write |
| 44 | + pull-requests: write |
| 45 | + id-token: write # npm OIDC trusted publishing |
| 46 | + |
| 47 | +concurrency: ${{ github.workflow }}-${{ github.ref }} |
17 | 48 |
|
18 | 49 | jobs: |
19 | 50 | pre-run: |
20 | 51 | uses: ./.github/workflows/pre-run.yml |
21 | 52 | secrets: inherit |
22 | 53 |
|
23 | | - publish: |
| 54 | + release: |
| 55 | + runs-on: ubuntu-latest |
| 56 | + needs: pre-run |
| 57 | + if: needs.pre-run.outputs.is-not-fork == 'true' && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.pr-number == '')) |
| 58 | + steps: |
| 59 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 60 | + with: |
| 61 | + fetch-depth: 0 |
| 62 | + |
| 63 | + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 64 | + with: |
| 65 | + node-version: 24 |
| 66 | + cache: npm |
| 67 | + |
| 68 | + - run: npm ci |
| 69 | + |
| 70 | + - name: Create release PR or publish |
| 71 | + uses: changesets/action@63a615b9cd06ba9a3e6d13796c7fbcb080a60a0b # v1.8.0 |
| 72 | + with: |
| 73 | + version: npm run version |
| 74 | + publish: npm run release |
| 75 | + title: 'chore: version packages' |
| 76 | + commit: 'chore: version packages' |
| 77 | + commitMode: github-api |
| 78 | + env: |
| 79 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + |
| 81 | + beta: |
24 | 82 | runs-on: ubuntu-latest |
25 | 83 | needs: pre-run |
26 | | - if: "needs.pre-run.outputs.is-not-fork == 'true' && (github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'chore: version packages'))" |
| 84 | + if: needs.pre-run.outputs.is-not-fork == 'true' && github.event_name == 'push' |
27 | 85 | steps: |
28 | 86 | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
29 | 87 | with: |
30 | 88 | fetch-depth: 0 |
| 89 | + |
31 | 90 | - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
32 | 91 | with: |
33 | 92 | node-version: 24 |
34 | 93 | cache: npm |
35 | 94 |
|
36 | 95 | - run: npm ci |
37 | | - - run: npm run build |
38 | 96 |
|
39 | | - - run: git config --local user.email 'action@github.com' |
40 | | - - run: git config --local user.name 'GitHub Action' |
| 97 | + - name: Seed dummy changeset if none present |
| 98 | + run: | |
| 99 | + if ! ls .changeset/*.md 2>/dev/null | grep -vqi readme; then |
| 100 | + cat > .changeset/__snapshot.md <<'EOF' |
| 101 | + --- |
| 102 | + "@stacks/common": patch |
| 103 | + --- |
| 104 | +
|
| 105 | + snapshot |
| 106 | + EOF |
| 107 | + fi |
41 | 108 |
|
42 | | - - name: Publish |
| 109 | + - run: npx changeset version |
| 110 | + - run: node .github/scripts/snapshot-version.mjs beta |
| 111 | + |
| 112 | + - name: Build packages |
43 | 113 | run: | |
44 | | - npx lerna publish from-package --no-verify-access --yes |
45 | | - RELEASE=$(cat lerna.json | jq -r '.version') |
46 | | - git tag -a v$RELEASE -m v$RELEASE |
47 | | - git push origin v$RELEASE |
| 114 | + npm run clean --workspaces --if-present |
| 115 | + npm run build:cjs --workspaces --if-present |
| 116 | + npm run build:esm --workspaces --if-present |
| 117 | + npm run build:umd --workspaces --if-present |
| 118 | +
|
| 119 | + # NPM_CONFIG_IGNORE_SCRIPTS skips each package's prepublishOnly hook, |
| 120 | + # avoiding duplicate test/build work during publish. |
| 121 | + - run: npx changeset publish --tag beta --no-git-tag |
| 122 | + env: |
| 123 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 124 | + NPM_CONFIG_IGNORE_SCRIPTS: 'true' |
48 | 125 |
|
49 | | - publish-beta: |
| 126 | + pr: |
50 | 127 | runs-on: ubuntu-latest |
51 | 128 | needs: pre-run |
52 | | - if: "needs.pre-run.outputs.is-not-fork == 'true' && !contains(github.event.head_commit.message, 'chore: version packages')" |
| 129 | + if: needs.pre-run.outputs.is-not-fork == 'true' && github.event_name == 'workflow_dispatch' && inputs.pr-number != '' |
53 | 130 | steps: |
54 | 131 | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
55 | 132 | with: |
56 | 133 | fetch-depth: 0 |
57 | 134 |
|
58 | | - # pulls all tags (needed for lerna to correctly version) |
59 | | - - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
60 | | - |
61 | 135 | - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
62 | 136 | with: |
63 | 137 | node-version: 24 |
64 | 138 | cache: npm |
65 | 139 |
|
66 | 140 | - run: npm ci |
67 | 141 |
|
68 | | - - run: git config --local user.email 'action@github.com' |
69 | | - - run: git config --local user.name 'GitHub Action' |
| 142 | + - name: Seed dummy changeset if none present |
| 143 | + run: | |
| 144 | + if ! ls .changeset/*.md 2>/dev/null | grep -vqi readme; then |
| 145 | + cat > .changeset/__snapshot.md <<'EOF' |
| 146 | + --- |
| 147 | + "@stacks/common": patch |
| 148 | + --- |
| 149 | +
|
| 150 | + snapshot |
| 151 | + EOF |
| 152 | + fi |
| 153 | +
|
| 154 | + - run: npx changeset version |
| 155 | + - id: snapshot |
| 156 | + run: node .github/scripts/snapshot-version.mjs pr --pr ${{ inputs.pr-number }} |
70 | 157 |
|
71 | | - - name: Version & Publish |
| 158 | + - name: Build packages |
72 | 159 | run: | |
73 | | - LATEST=$(git describe --tags --abbrev=0) |
74 | | - npx lerna version $LATEST --force-publish --no-changelog --no-push --no-git-tag-version --yes |
75 | | - git commit -a -m 'DONT PUSH: fast-forward to latest npm release' --allow-empty --no-verify |
76 | | - npx lerna version --force-publish --no-changelog --conventional-commits --conventional-prerelease --preid beta --no-push --no-git-tag-version --yes |
77 | | - git commit -a -m 'DONT PUSH: version beta release' --allow-empty --no-verify |
78 | | - RELEASE=$(cat lerna.json | jq -r '.version') |
79 | | - npx lerna publish from-package --no-verify-access --pre-dist-tag beta --yes |
80 | | - git reset HEAD~2 --hard |
81 | | - git tag v$RELEASE |
82 | | - git push origin v$RELEASE |
| 160 | + npm run clean --workspaces --if-present |
| 161 | + npm run build:cjs --workspaces --if-present |
| 162 | + npm run build:esm --workspaces --if-present |
| 163 | + npm run build:umd --workspaces --if-present |
| 164 | +
|
| 165 | + - run: npx changeset publish --tag pr --no-git-tag |
| 166 | + env: |
| 167 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 168 | + NPM_CONFIG_IGNORE_SCRIPTS: 'true' |
| 169 | + |
| 170 | + - name: Update PR sticky header |
| 171 | + uses: janniks/pull-request-fixed-header@57bc082ecbd040df344747d5b8644af5fad02c95 # v1.2.0 |
| 172 | + with: |
| 173 | + header: | |
| 174 | + > This PR was published to npm with the version `${{ steps.snapshot.outputs.version }}` (dist-tag `pr`). |
| 175 | + > e.g. `npm install @stacks/common@${{ steps.snapshot.outputs.version }} --save-exact` |
| 176 | + pr-number: ${{ inputs.pr-number }} |
| 177 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments