-
Notifications
You must be signed in to change notification settings - Fork 3
ci: use-trusted-publishers #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,22 +3,46 @@ on: | |||||||||||||
| push: | ||||||||||||||
| branches: | ||||||||||||||
| - main | ||||||||||||||
| # allow other workflows to call this one (for snapshots) | ||||||||||||||
| workflow_call: | ||||||||||||||
| inputs: | ||||||||||||||
| branch: | ||||||||||||||
| description: 'Branch or ref to publish from' | ||||||||||||||
| required: false | ||||||||||||||
| type: string | ||||||||||||||
| default: 'main' | ||||||||||||||
| dist_tag: | ||||||||||||||
| description: 'npm dist-tag' | ||||||||||||||
| required: false | ||||||||||||||
| type: string | ||||||||||||||
| default: 'beta' | ||||||||||||||
| prerelease: | ||||||||||||||
| description: 'changesets prerelease tag (e.g., beta, canary)' | ||||||||||||||
| required: false | ||||||||||||||
| type: string | ||||||||||||||
| default: 'beta' | ||||||||||||||
| access: | ||||||||||||||
| description: 'npm access' | ||||||||||||||
| required: false | ||||||||||||||
| type: string | ||||||||||||||
| default: 'public' | ||||||||||||||
|
|
||||||||||||||
| env: | ||||||||||||||
| NX_CLOUD_ENCRYPTION_KEY: ${{ secrets.NX_CLOUD_ENCRYPTION_KEY }} | ||||||||||||||
| NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} | ||||||||||||||
| NX_CLOUD_DISTRIBUTED_EXECUTION: true | ||||||||||||||
| PNPM_CACHE_FOLDER: .pnpm-store | ||||||||||||||
| NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} | ||||||||||||||
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||||||||||||||
| CI: true | ||||||||||||||
|
|
||||||||||||||
| jobs: | ||||||||||||||
| publish-or-pr: | ||||||||||||||
| if: github.event_name == 'push' | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure this is only on push. |
||||||||||||||
| permissions: | ||||||||||||||
| contents: write # to create release (changesets/action) | ||||||||||||||
| issues: write # to post issue comments (changesets/action) | ||||||||||||||
| pull-requests: write # to create pull request (changesets/action) | ||||||||||||||
| id-token: write # give id token write for provenance | ||||||||||||||
| contents: write # changesets/action | ||||||||||||||
| issues: write | ||||||||||||||
| pull-requests: write | ||||||||||||||
| id-token: write # OIDC for provenance if npm publish happens here | ||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||
| steps: | ||||||||||||||
| - uses: actions/checkout@v4 | ||||||||||||||
|
|
@@ -36,8 +60,6 @@ jobs: | |||||||||||||
|
|
||||||||||||||
| - run: pnpm install --frozen-lockfile | ||||||||||||||
|
|
||||||||||||||
| # This line enables distribution | ||||||||||||||
| # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested | ||||||||||||||
| - 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" | ||||||||||||||
|
|
||||||||||||||
| - name: Cache Playwright browsers | ||||||||||||||
|
|
@@ -77,11 +99,8 @@ jobs: | |||||||||||||
| commit: 'chore: version-packages' | ||||||||||||||
| setupGitUser: true | ||||||||||||||
| env: | ||||||||||||||
| # See https://github.com/changesets/action/issues/147 | ||||||||||||||
| HOME: ${{ github.workspace }} | ||||||||||||||
| GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||||||||||||||
| NPM_CONFIG_PROVENANCE: 'true' | ||||||||||||||
| NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} | ||||||||||||||
|
|
||||||||||||||
| - name: Send GitHub Action data to a Slack workflow | ||||||||||||||
| if: steps.changesets.outputs.published == 'true' | ||||||||||||||
|
|
@@ -119,26 +138,85 @@ jobs: | |||||||||||||
| with: | ||||||||||||||
| folder: docs | ||||||||||||||
| commit-message: 'chore: release-api-docs-beta' | ||||||||||||||
| target-folder: 'beta' # we push to beta folder when we are updating "main" | ||||||||||||||
| target-folder: 'beta' | ||||||||||||||
|
|
||||||||||||||
| # Calculate and save baseline bundle sizes | ||||||||||||||
| - name: Calculate baseline bundle sizes | ||||||||||||||
| run: | | ||||||||||||||
| chmod +x ./scripts/bundle-sizes.sh | ||||||||||||||
|
|
||||||||||||||
| # Don't use any previous baseline for main branch - always create fresh | ||||||||||||||
| rm -f previous_sizes.json | ||||||||||||||
|
|
||||||||||||||
| echo "📊 Calculating fresh baseline bundle sizes for main branch" | ||||||||||||||
| ./scripts/bundle-sizes.sh | ||||||||||||||
|
|
||||||||||||||
| echo "✅ Baseline bundle sizes calculated" | ||||||||||||||
| cat previous_sizes.json | ||||||||||||||
|
|
||||||||||||||
| # Save baseline for PR comparisons | ||||||||||||||
| - name: Upload baseline bundle sizes | ||||||||||||||
| uses: actions/upload-artifact@v4 | ||||||||||||||
| with: | ||||||||||||||
| name: bundle-size-baseline | ||||||||||||||
| path: previous_sizes.json | ||||||||||||||
| retention-days: 30 # Keep baseline for 30 days | ||||||||||||||
| retention-days: 30 | ||||||||||||||
|
|
||||||||||||||
| # --- new reusable job used by the snapshot wrapper --- | ||||||||||||||
| trusted-publish: | ||||||||||||||
| if: ${{ github.event_name == 'workflow_call' }} | ||||||||||||||
| name: Trusted Snapshot Publish | ||||||||||||||
| permissions: | ||||||||||||||
| contents: write # read+write repo (okay for artifacts/logs) | ||||||||||||||
| id-token: write # REQUIRED: OIDC for npm Trusted Publishers | ||||||||||||||
| issues: write | ||||||||||||||
| pull-requests: write | ||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||
| env: | ||||||||||||||
| HUSKY: 0 | ||||||||||||||
| steps: | ||||||||||||||
| - uses: actions/checkout@v4 | ||||||||||||||
| with: | ||||||||||||||
| fetch-depth: 0 | ||||||||||||||
| ref: ${{ inputs.branch }} | ||||||||||||||
| - uses: pnpm/action-setup@v4 | ||||||||||||||
| with: | ||||||||||||||
| run_install: false | ||||||||||||||
| - uses: actions/setup-node@v4 | ||||||||||||||
| with: | ||||||||||||||
| node-version-file: '.node-version' | ||||||||||||||
| cache: 'pnpm' | ||||||||||||||
|
|
||||||||||||||
| - run: pnpm install --frozen-lockfile | ||||||||||||||
|
|
||||||||||||||
| - 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" | ||||||||||||||
|
|
||||||||||||||
| - name: Cache Playwright browsers | ||||||||||||||
| uses: actions/cache@v4 | ||||||||||||||
| with: | ||||||||||||||
| path: ~/.cache/ms-playwright | ||||||||||||||
| key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }} | ||||||||||||||
| restore-keys: | | ||||||||||||||
| ${{ runner.os }}-playwright- | ||||||||||||||
|
|
||||||||||||||
| - run: pnpm exec playwright install | ||||||||||||||
|
|
||||||||||||||
| - uses: nrwl/nx-set-shas@v4 | ||||||||||||||
| with: | ||||||||||||||
| main-branch-name: main | ||||||||||||||
|
|
||||||||||||||
| - name: setup pnpm config | ||||||||||||||
| run: pnpm config set store-dir $PNPM_CACHE_FOLDER | ||||||||||||||
|
|
||||||||||||||
| - run: pnpm exec nx run-many -t build test e2e-ci | ||||||||||||||
|
|
||||||||||||||
| - uses: actions/upload-artifact@v4 | ||||||||||||||
| if: ${{ !cancelled() }} | ||||||||||||||
| with: | ||||||||||||||
| name: playwright-report | ||||||||||||||
| path: | | ||||||||||||||
| ./**/.playwright/** | ||||||||||||||
| retention-days: 30 | ||||||||||||||
|
|
||||||||||||||
| - name: Version Packages as prerelease | ||||||||||||||
| run: pnpm changeset version --snapshot ${{ inputs.prerelease }} | ||||||||||||||
| env: | ||||||||||||||
| GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||||||||||||||
|
|
||||||||||||||
| # The actual npm publish that must occur in the authorized file | ||||||||||||||
| - name: Publish packages with dist-tag | ||||||||||||||
| run: pnpm publish -r --tag ${{ inputs.dist_tag }} --no-git-checks --access ${{ inputs.access }} | ||||||||||||||
|
Comment on lines
+221
to
+222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add npm provenance to enable Trusted Publishers (OIDC) auth. Without provenance, npm will expect a token and the publish will likely fail under Trusted Publishers. Apply this diff: - - name: Publish packages with dist-tag
- run: pnpm publish -r --tag ${{ inputs.dist_tag }} --no-git-checks --access ${{ inputs.access }}
+ - name: Publish packages with dist-tag
+ run: pnpm publish -r --tag ${{ inputs.dist_tag }} --no-git-checks --access ${{ inputs.access }} --provenanceOptionally, reinforce via env (not required if flag is present): - - name: Publish packages with dist-tag
+ - name: Publish packages with dist-tag
run: pnpm publish -r --tag ${{ inputs.dist_tag }} --no-git-checks --access ${{ inputs.access }} --provenance
+ env:
+ NPM_CONFIG_PROVENANCE: 'true'📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to allow snapshot.yml to call this workflow file.