Skip to content

Commit 789ccb4

Browse files
authored
chore(workflow): enable trusted publishing (#46)
1 parent fabd518 commit 789ccb4

File tree

4 files changed

+11
-134
lines changed

4 files changed

+11
-134
lines changed

.github/workflows/release.yml

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: Release Full
32

43
on:
@@ -29,25 +28,22 @@ on:
2928
- latest
3029
- beta
3130
- alpha
32-
31+
3332
dry_run:
3433
type: boolean
3534
description: "DryRun release"
3635
required: true
3736
default: false
3837

3938
permissions:
39+
contents: write
4040
# To publish packages with provenance
4141
id-token: write
4242

4343
jobs:
4444
release:
4545
name: Release
4646
environment: npm
47-
permissions:
48-
contents: write
49-
# To publish packages with provenance
50-
id-token: write
5147
runs-on: ubuntu-latest
5248

5349
steps:
@@ -63,41 +59,21 @@ jobs:
6359
node-version: 20
6460
cache: "pnpm"
6561

62+
# Update npm to the latest version to enable OIDC
63+
- name: Update npm
64+
run: |
65+
npm install -g npm@latest
66+
npm --version
67+
6668
- name: Install Dependencies
6769
run: pnpm install
6870

6971
- name: Run Test
7072
run: pnpm run test
71-
- name: Obtain OIDC token
72-
id: oidc
73-
run: |
74-
token=$(curl --fail -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
75-
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=cfa.rspack.dev" | jq -r '.value')
76-
echo "::add-mask::${token}"
77-
echo "token=${token}" >> $GITHUB_OUTPUT
78-
shell: bash
79-
- name: Obtain GitHub credentials
80-
id: github_creds
81-
run: |
82-
token=$(curl --fail "https://cfa.rspack.dev/api/request/${{ secrets.CFA_PROJECT_ID }}/github/credentials" \
83-
-X POST \
84-
-H "Content-Type: application/json" \
85-
-H "Authorization: bearer ${{ secrets.CFA_SECRET }}" \
86-
--data "{\"token\":\"${{ steps.oidc.outputs.token }}\"}" | jq -r '.GITHUB_TOKEN')
87-
echo "::add-mask::${token}"
88-
echo "token=${token}" >> $GITHUB_OUTPUT
89-
shell: bash
73+
9074
- name: Try release to npm
9175
run: pnpm run release
9276
env:
9377
DRY_RUN: ${{ inputs.dry_run }}
9478
TAG: ${{ inputs.tag }}
9579
VERSION: ${{ inputs.version }}
96-
CFA_HOST: https://cfa.rspack.dev
97-
GITHUB_TOKEN: ${{ steps.github_creds.outputs.token }}
98-
GITHUB_OIDC_TOKEN: ${{ steps.oidc.outputs.token }}
99-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
100-
CFA_PROJECT_ID: ${{ secrets.CFA_PROJECT_ID }}
101-
CFA_SECRET: ${{ secrets.CFA_SECRET }}
102-
103-

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
},
4242
"devDependencies": {
4343
"@biomejs/biome": "^1.9.4",
44-
"@continuous-auth/client": "2.3.2",
4544
"@rslib/core": "^0.11.0",
4645
"@rspack/core": "1.4.11",
4746
"@types/jest": "29.5.14",
@@ -76,7 +75,6 @@
7675
"packageManager": "[email protected]",
7776
"publishConfig": {
7877
"access": "public",
79-
"registry": "https://registry.npmjs.org/",
80-
"provenance": true
78+
"registry": "https://registry.npmjs.org/"
8179
}
8280
}

pnpm-lock.yaml

Lines changed: 0 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/release.mjs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import path from 'path';
22
import * as url from 'url';
3-
import { getOtp } from '@continuous-auth/client';
43
import { $ } from 'execa';
54
import fs from 'fs-extra';
65
import { inc } from 'semver';
76

87
const RELEASE_TAG = process.env.TAG || 'beta';
98
const RELEASE_DRY_RUN = process.env.DRY_RUN || 'true';
109
const RELEASE_VERSION_TYPE = process.env.VERSION || 'prerelease';
11-
const RELEASE_NPM_TOKEN = process.env.NPM_TOKEN || '';
1210

1311
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
1412
const PKG_PATH = path.resolve(__dirname, '../package.json');
@@ -28,29 +26,16 @@ console.info(`Updating version from ${currentVersion} to ${nextVersion}`);
2826
pkg.version = nextVersion;
2927
fs.writeJsonSync(PKG_PATH, pkg, { spaces: 2 });
3028

31-
// Write npmrc
32-
const npmrcPath = `${process.env.HOME}/.npmrc`;
33-
console.info(`Writing npmrc to ${npmrcPath}`);
34-
fs.writeFileSync(
35-
npmrcPath,
36-
`//registry.npmjs.org/:_authToken=${RELEASE_NPM_TOKEN}`,
37-
);
38-
3929
// Publish to npm
4030
console.info(`Publishing to npm with tag ${RELEASE_TAG}`);
4131
const dryRun = RELEASE_DRY_RUN === 'true' ? ['--dry-run'] : [];
42-
console.log('Getting OTP code');
43-
let otp = await getOtp();
44-
console.log('OTP code get, continuing...');
4532

4633
try {
47-
await $`pnpm publish ${dryRun} --tag ${RELEASE_TAG} --otp ${otp} --no-git-checks --provenance`;
34+
await $`pnpm publish ${dryRun} --tag ${RELEASE_TAG} --no-git-checks`;
4835
console.info(`Published successfully`);
4936
} catch (e) {
5037
console.error(`Publish failed: ${e.message}`);
5138
process.exit(1);
52-
} finally {
53-
fs.removeSync(npmrcPath);
5439
}
5540

5641
// Push tag to github

0 commit comments

Comments
 (0)