Skip to content

Commit 49e34e2

Browse files
binoy14claude
andcommitted
refactor: use OIDC publishing and remove alpha tag handling
Switch to OIDC-based npm trusted publishing (provenance) instead of static NPM_TOKEN for publishing. This matches the sanity-io/.github shared workflow pattern used by next-sanity. Changes: - Use id-token: write permission for OIDC npm provenance - Set NPM_CONFIG_PROVENANCE for public repos - Update npm to latest for trusted publishing support - Setup git user from GitHub App bot identity - Remove scripts/publish.mjs (no more per-package tag handling) - Use changeset publish directly (all packages publish as latest) - Remove pre-release/alpha references from docs Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d4ef204 commit 49e34e2

File tree

4 files changed

+42
-62
lines changed

4 files changed

+42
-62
lines changed

.github/workflows/release.yml

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@ concurrency:
1616
cancel-in-progress: false
1717

1818
permissions:
19-
contents: write
20-
pull-requests: write
19+
contents: read # for checkout
20+
id-token: write # to enable use of OIDC for npm provenance
2121

2222
jobs:
2323
release:
2424
name: Release
2525
runs-on: ubuntu-latest
26+
permissions:
27+
contents: read # for checkout
28+
id-token: write # to enable use of OIDC for npm provenance
2629
outputs:
2730
published: ${{ steps.changesets.outputs.published }}
2831
publishedPackages: ${{ steps.changesets.outputs.publishedPackages }}
2932
hasChangesets: ${{ steps.changesets.outputs.hasChangesets }}
33+
env:
34+
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
35+
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
3036
steps:
3137
- name: Generate GitHub App Token
3238
id: generate_token
@@ -37,35 +43,59 @@ jobs:
3743

3844
- name: Checkout
3945
uses: actions/checkout@v6
46+
with:
47+
fetch-depth: 0
48+
token: ${{ steps.generate_token.outputs.token }}
49+
persist-credentials: false
50+
51+
- name: Get app token user id
52+
id: get-user-id
53+
run: echo "user-id=$(gh api "/users/${{ steps.generate_token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
54+
env:
55+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
56+
57+
- name: Setup git user
58+
run: |
59+
git config --global user.name '${{ steps.generate_token.outputs.app-slug }}[bot]'
60+
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.generate_token.outputs.app-slug }}[bot]@users.noreply.github.com'
4061
4162
- name: Setup Environment
4263
uses: ./.github/actions/setup
4364
with:
4465
node-version: 20
4566

46-
- name: Set publishing config
47-
run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}"
48-
env:
49-
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
67+
- name: Update npm to use trusted publishing (OIDC)
68+
run: npm install -g npm@latest
69+
70+
- name: Authenticate with private npm
71+
if: ${{ secrets.NPM_PUBLISH_TOKEN != '' }}
72+
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_TOKEN }}" > ~/.npmrc
73+
74+
- run: pnpm install
75+
76+
- name: Remove npm auth
77+
if: ${{ secrets.NPM_PUBLISH_TOKEN != '' }}
78+
run: rm -f ~/.npmrc
5079

5180
- name: Create Release Pull Request or Publish
5281
id: changesets
53-
uses: changesets/action@v1
82+
uses: changesets/action@c48e67d110a68bc90ccf1098e9646092baacaa87 # v1.6.0
5483
with:
5584
version: pnpm version-packages
5685
publish: pnpm release
5786
title: 'chore: version packages'
5887
commit: 'chore: version packages'
5988
createGithubReleases: true
89+
setupGitUser: false
6090
env:
6191
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
62-
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
92+
NPM_CONFIG_PROVENANCE: ${{ github.event.repository.visibility == 'public' && 'true' || 'false' }}
6393

6494
- name: Force Publish
6595
if: ${{ github.event.inputs.publish == 'true' && steps.changesets.outputs.hasChangesets == 'false' }}
6696
run: pnpm release
6797
env:
68-
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
98+
NPM_CONFIG_PROVENANCE: ${{ github.event.repository.visibility == 'public' && 'true' || 'false' }}
6999

70100
- name: Summary
71101
if: ${{ steps.changesets.outputs.published == 'true' || github.event.inputs.publish == 'true' }}

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,9 @@ If you need to force-publish without new changesets:
10081008
3. Check **Force publish packages to NPM**
10091009
4. Click **Run workflow**
10101010

1011-
### Pre-releases
1011+
### npm Dist Tags
10121012

1013-
`@sanity/cli` is currently published with the `alpha` npm dist tag. Other packages (`@sanity/cli-core`, `@sanity/cli-test`, `@sanity/eslint-config-cli`) publish with the `latest` tag.
1013+
All packages publish with the `latest` npm dist tag.
10141014

10151015
## Resources
10161016

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"extract-commands": "turbo run extract-commands",
3535
"format": "prettier --write .",
3636
"prepare": "husky",
37-
"publish-packages": "node scripts/publish.mjs",
37+
"publish-packages": "changeset publish",
3838
"publint": "turbo run publint",
3939
"pretest": "pnpm run build:cli",
4040
"release": "pnpm build:cli && pnpm publish-packages",

scripts/publish.mjs

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)