|
3 | 3 | push: |
4 | 4 | branches: |
5 | 5 | - main |
| 6 | + # allow other workflows to call this one (for snapshots) |
| 7 | + workflow_call: |
| 8 | + inputs: |
| 9 | + branch: |
| 10 | + description: 'Branch or ref to publish from' |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + default: 'main' |
| 14 | + dist_tag: |
| 15 | + description: 'npm dist-tag' |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + default: 'beta' |
| 19 | + prerelease: |
| 20 | + description: 'changesets prerelease tag (e.g., beta, canary)' |
| 21 | + required: false |
| 22 | + type: string |
| 23 | + default: 'beta' |
| 24 | + access: |
| 25 | + description: 'npm access' |
| 26 | + required: false |
| 27 | + type: string |
| 28 | + default: 'public' |
| 29 | + |
6 | 30 | env: |
7 | 31 | NX_CLOUD_ENCRYPTION_KEY: ${{ secrets.NX_CLOUD_ENCRYPTION_KEY }} |
8 | 32 | NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} |
9 | 33 | NX_CLOUD_DISTRIBUTED_EXECUTION: true |
10 | 34 | PNPM_CACHE_FOLDER: .pnpm-store |
11 | | - NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} |
12 | 35 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
13 | 36 | CI: true |
14 | 37 |
|
15 | 38 | jobs: |
16 | 39 | publish-or-pr: |
| 40 | + if: github.event_name == 'push' |
17 | 41 | permissions: |
18 | | - contents: write # to create release (changesets/action) |
19 | | - issues: write # to post issue comments (changesets/action) |
20 | | - pull-requests: write # to create pull request (changesets/action) |
21 | | - id-token: write # give id token write for provenance |
| 42 | + contents: write # changesets/action |
| 43 | + issues: write |
| 44 | + pull-requests: write |
| 45 | + id-token: write # OIDC for provenance if npm publish happens here |
22 | 46 | runs-on: ubuntu-latest |
23 | 47 | steps: |
24 | 48 | - uses: actions/checkout@v4 |
|
36 | 60 |
|
37 | 61 | - run: pnpm install --frozen-lockfile |
38 | 62 |
|
39 | | - # This line enables distribution |
40 | | - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested |
41 | 63 | - run: pnpm dlx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yml" --stop-agents-after="e2e-ci" --with-env-vars="CODECOV_TOKEN" |
42 | 64 |
|
43 | 65 | - name: Cache Playwright browsers |
|
77 | 99 | commit: 'chore: version-packages' |
78 | 100 | setupGitUser: true |
79 | 101 | env: |
80 | | - # See https://github.com/changesets/action/issues/147 |
81 | 102 | HOME: ${{ github.workspace }} |
82 | 103 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
83 | | - NPM_CONFIG_PROVENANCE: 'true' |
84 | | - NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} |
85 | 104 |
|
86 | 105 | - name: Send GitHub Action data to a Slack workflow |
87 | 106 | if: steps.changesets.outputs.published == 'true' |
@@ -119,26 +138,85 @@ jobs: |
119 | 138 | with: |
120 | 139 | folder: docs |
121 | 140 | commit-message: 'chore: release-api-docs-beta' |
122 | | - target-folder: 'beta' # we push to beta folder when we are updating "main" |
| 141 | + target-folder: 'beta' |
123 | 142 |
|
124 | | - # Calculate and save baseline bundle sizes |
125 | 143 | - name: Calculate baseline bundle sizes |
126 | 144 | run: | |
127 | 145 | chmod +x ./scripts/bundle-sizes.sh |
128 | | -
|
129 | | - # Don't use any previous baseline for main branch - always create fresh |
130 | 146 | rm -f previous_sizes.json |
131 | | -
|
132 | 147 | echo "📊 Calculating fresh baseline bundle sizes for main branch" |
133 | 148 | ./scripts/bundle-sizes.sh |
134 | | -
|
135 | 149 | echo "✅ Baseline bundle sizes calculated" |
136 | 150 | cat previous_sizes.json |
137 | 151 |
|
138 | | - # Save baseline for PR comparisons |
139 | 152 | - name: Upload baseline bundle sizes |
140 | 153 | uses: actions/upload-artifact@v4 |
141 | 154 | with: |
142 | 155 | name: bundle-size-baseline |
143 | 156 | path: previous_sizes.json |
144 | | - retention-days: 30 # Keep baseline for 30 days |
| 157 | + retention-days: 30 |
| 158 | + |
| 159 | + # --- new reusable job used by the snapshot wrapper --- |
| 160 | + trusted-publish: |
| 161 | + if: ${{ github.event_name == 'workflow_call' }} |
| 162 | + name: Trusted Snapshot Publish |
| 163 | + permissions: |
| 164 | + contents: write # read+write repo (okay for artifacts/logs) |
| 165 | + id-token: write # REQUIRED: OIDC for npm Trusted Publishers |
| 166 | + issues: write |
| 167 | + pull-requests: write |
| 168 | + runs-on: ubuntu-latest |
| 169 | + env: |
| 170 | + HUSKY: 0 |
| 171 | + steps: |
| 172 | + - uses: actions/checkout@v4 |
| 173 | + with: |
| 174 | + fetch-depth: 0 |
| 175 | + ref: ${{ inputs.branch }} |
| 176 | + - uses: pnpm/action-setup@v4 |
| 177 | + with: |
| 178 | + run_install: false |
| 179 | + - uses: actions/setup-node@v4 |
| 180 | + with: |
| 181 | + node-version-file: '.node-version' |
| 182 | + cache: 'pnpm' |
| 183 | + |
| 184 | + - run: pnpm install --frozen-lockfile |
| 185 | + |
| 186 | + - run: pnpm dlx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yml" --stop-agents-after="e2e-ci" --with-env-vars="CODECOV_TOKEN" |
| 187 | + |
| 188 | + - name: Cache Playwright browsers |
| 189 | + uses: actions/cache@v4 |
| 190 | + with: |
| 191 | + path: ~/.cache/ms-playwright |
| 192 | + key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 193 | + restore-keys: | |
| 194 | + ${{ runner.os }}-playwright- |
| 195 | +
|
| 196 | + - run: pnpm exec playwright install |
| 197 | + |
| 198 | + - uses: nrwl/nx-set-shas@v4 |
| 199 | + with: |
| 200 | + main-branch-name: main |
| 201 | + |
| 202 | + - name: setup pnpm config |
| 203 | + run: pnpm config set store-dir $PNPM_CACHE_FOLDER |
| 204 | + |
| 205 | + - run: pnpm exec nx run-many -t build test e2e-ci |
| 206 | + |
| 207 | + - uses: actions/upload-artifact@v4 |
| 208 | + if: ${{ !cancelled() }} |
| 209 | + with: |
| 210 | + name: playwright-report |
| 211 | + path: | |
| 212 | + ./**/.playwright/** |
| 213 | + retention-days: 30 |
| 214 | + |
| 215 | + - name: Version Packages as prerelease |
| 216 | + run: pnpm changeset version --snapshot ${{ inputs.prerelease }} |
| 217 | + env: |
| 218 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
| 219 | + |
| 220 | + # The actual npm publish that must occur in the authorized file |
| 221 | + - name: Publish packages with dist-tag |
| 222 | + run: pnpm publish -r --tag ${{ inputs.dist_tag }} --no-git-checks --access ${{ inputs.access }} |
0 commit comments