Skip to content

Commit a88bb6b

Browse files
Copilotaspiers
authored andcommitted
chore: migrate release workflows to npm Trusted Publishers
Because the Trusted Publishers mechanism only supports one publishing workflow per repo, this requires unifying the two release workflows into a single one, with a beta parameter to distinguish between them. Co-authored-by: [email protected]
1 parent 98ecd47 commit a88bb6b

File tree

3 files changed

+92
-92
lines changed

3 files changed

+92
-92
lines changed

.github/workflows/release-beta.yml

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

.github/workflows/release.yml

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Release
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
beta:
7+
description: "Release as beta prerelease"
8+
required: false
9+
default: true
10+
type: boolean
511

612
concurrency: ${{ github.workflow }}-${{ github.ref }}
713

@@ -11,26 +17,75 @@ jobs:
1117
permissions:
1218
contents: write
1319
pull-requests: write
20+
# Required for npm Trusted Publishers via GitHub OIDC
21+
# See: https://docs.npmjs.com/trusted-publishers
1422
id-token: write
1523

1624
steps:
25+
# Beta-specific: Check RELEASE_PAT secret exists (only for beta releases)
26+
- name: Check RELEASE_PAT secret exists
27+
if: inputs.beta
28+
run: |
29+
if [ -z "${{ secrets.RELEASE_PAT }}" ]; then
30+
echo "Error: RELEASE_PAT secret is required but not set for beta releases."
31+
echo "This workflow requires a Personal Access Token to bypass branch protection rules."
32+
echo "See PUBLISHING.md."
33+
exit 1
34+
fi
35+
1736
- uses: actions/checkout@v6
1837
with:
1938
fetch-depth: 0
39+
# Beta releases use PAT to bypass branch protection rules when committing and pushing
40+
token: ${{ inputs.beta && secrets.RELEASE_PAT || secrets.GITHUB_TOKEN }}
41+
42+
# Beta-specific: Branch check is necessary for manual triggers (workflow_dispatch) to ensure
43+
# we only push version changes to main. If using automatic push triggers,
44+
# the trigger itself would enforce the branch, but manual triggers can run
45+
# from any branch.
46+
- name: Check branch is main
47+
if: inputs.beta
48+
run: |
49+
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
50+
echo "Error: Beta releases must be run on the main branch"
51+
exit 1
52+
fi
53+
2054
- uses: actions/setup-node@v6
2155
with:
2256
node-version: 20
2357
cache: "npm"
58+
# registry-url is required for npm Trusted Publishers
2459
registry-url: "https://registry.npmjs.org"
60+
2561
- run: npm ci
2662
- run: npm run check
2763

28-
- name: Create .npmrc
64+
# Beta-specific: Enter prerelease mode (if not already)
65+
- name: Enter prerelease mode (if not already)
66+
if: inputs.beta
2967
run: |
30-
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
31-
echo "@hypercerts-org:registry=https://registry.npmjs.org/" >> .npmrc
68+
if [ ! -f .changeset/pre.json ]; then
69+
npx changeset pre enter beta
70+
git config user.name "github-actions[bot]"
71+
git config user.email "github-actions[bot]@users.noreply.github.com"
72+
git add .changeset/pre.json
73+
git commit -m "chore: enter beta prerelease mode"
74+
fi
3275
76+
# Beta-specific: Version packages manually
77+
- name: Version packages
78+
if: inputs.beta
79+
run: npm run version-packages
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
83+
# No .npmrc creation needed - npm Trusted Publishers uses GitHub OIDC tokens
84+
# automatically via the id-token: write permission and registry-url configuration
85+
86+
# Stable release: Use changesets/action which handles versioning and publishing
3387
- name: Create Release Pull Request or Publish
88+
if: ${{ !inputs.beta }}
3489
id: changesets
3590
uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba # v1.5.3
3691
with:
@@ -42,6 +97,26 @@ jobs:
4297
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4398
NPM_CONFIG_PROVENANCE: true
4499

100+
# Beta-specific: Publish beta packages directly
101+
- name: Publish beta packages
102+
if: inputs.beta
103+
# Use npm run release to match regular releases - it runs check before publishing
104+
# to ensure validation after versioning (package.json/changelog changes)
105+
run: npm run release
106+
env:
107+
NPM_CONFIG_PROVENANCE: true
108+
109+
# Beta-specific: Commit and push version changes
110+
- name: Commit and push version changes
111+
if: inputs.beta
112+
run: |
113+
git config user.name "github-actions[bot]"
114+
git config user.email "github-actions[bot]@users.noreply.github.com"
115+
git add -A
116+
git diff --staged --quiet || git commit -m "chore: version packages (beta)"
117+
git push
118+
119+
# Stable release: Log published packages
45120
- name: Log published packages
46-
if: steps.changesets.outputs.published == 'true'
121+
if: ${{ !inputs.beta && steps.changesets.outputs.published == 'true' }}
47122
run: echo "Published - ${{ steps.changesets.outputs.publishedPackages }}"

PUBLISHING.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@ Before publishing, ensure you have:
2626
- **Note:** Ensure branch protection rules allow the token to bypass
2727
protection (uncheck "Do not allow bypassing the above settings" or
2828
add the token as an allowed actor)
29-
- `NPM_TOKEN`: npm access token with publish permissions for
30-
`@hypercerts-org` scope
29+
30+
2. **npm Trusted Publisher configured:**
31+
- The workflow uses npm Trusted Publishers via GitHub OIDC for secure,
32+
token-less publishing
33+
- Configure on npmjs.com: Package settings → Publishing access → Add a
34+
GitHub Actions publisher
35+
- Workflow name: `Release`
36+
- See: <https://docs.npmjs.com/trusted-publishers>
37+
- No `NPM_TOKEN` secret is required
3138

3239
## Adding Changesets
3340

@@ -65,6 +72,7 @@ To publish a stable release to npm:
6572
3. **Run the workflow:**
6673
- Click "Run workflow"
6774
- Select the branch (typically `main`)
75+
- **Uncheck "Release as beta prerelease" (it is checked by default)**
6876
- Click "Run workflow" to start
6977

7078
4. **What happens:**
@@ -81,11 +89,12 @@ To publish a beta/prerelease version:
8189
- Go to the "Actions" tab
8290

8391
2. **Select the workflow:**
84-
- Choose "Release Beta"
92+
- Choose "Release" from the workflow list
8593

8694
3. **Run the workflow:**
8795
- Click "Run workflow"
8896
- Select the branch (must be `main`)
97+
- **Leave "Release as beta prerelease" checked (it is checked by default)**
8998
- Click "Run workflow"
9099

91100
4. **What happens:**
@@ -95,7 +104,7 @@ To publish a beta/prerelease version:
95104
- Version format: `0.9.0-beta.1`, `0.9.0-beta.2`, etc.
96105
- Commits and pushes version changes back to the repository
97106

98-
**Note:** This workflow requires the `RELEASE_PAT` secret to bypass
107+
**Note:** Beta releases require the `RELEASE_PAT` secret to bypass
99108
branch protection rules when pushing version changes.
100109

101110
## Validating Releases (PRs)

0 commit comments

Comments
 (0)