Skip to content

Commit 0f8e0ca

Browse files
authored
chore: enable trusted publishing for npm packages (#4053)
1 parent eb69021 commit 0f8e0ca

File tree

4 files changed

+78
-21
lines changed

4 files changed

+78
-21
lines changed

.github/workflows/preview.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# https://github.com/stackblitz-labs/pkg.pr.new
2+
name: Preview Release
3+
4+
on:
5+
push:
6+
branches: [main]
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
preview:
14+
if: github.repository == 'module-federation/core'
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 25
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
25+
with:
26+
node-version: 22
27+
cache: 'pnpm'
28+
29+
# Update npm to the latest version to enable OIDC
30+
# Use corepack to install pnpm
31+
- name: Setup Package Managers
32+
run: |
33+
npm install -g npm@latest
34+
npm --version
35+
npm install -g corepack@latest --force
36+
corepack prepare [email protected] --activate
37+
corepack enable
38+
39+
- name: Install deps
40+
run: pnpm install
41+
42+
- name: Build and test Packages
43+
run: |
44+
git fetch origin main
45+
npx nx run-many --targets=build --projects=tag:type:pkg --skip-nx-cache
46+
ls -l packages/*/dist packages/*/package.json
47+
48+
- name: Publish Preview
49+
run: |
50+
51+
pkg-pr-new publish --compact --pnpm ./packages/*

.github/workflows/release.yml

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,29 @@ jobs:
2525
name: Release
2626
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' }}
2727
runs-on: ubuntu-latest
28+
environment: npm
2829
steps:
2930
- name: Checkout
30-
uses: actions/checkout@v3
31+
uses: actions/checkout@v4
3132
with:
3233
fetch-depth: 25
3334

34-
- name: Install Pnpm
35+
- name: Setup Node.js
36+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
37+
with:
38+
node-version: 22
39+
cache: 'pnpm'
40+
41+
# Update npm to the latest version to enable OIDC
42+
# Use corepack to install pnpm
43+
- name: Setup Package Managers
3544
run: |
45+
npm install -g npm@latest
46+
npm --version
47+
npm install -g corepack@latest --force
3648
corepack prepare [email protected] --activate
3749
corepack enable
3850
39-
- name: Setup Node.js 18
40-
uses: actions/setup-node@v3
41-
with:
42-
node-version: '18'
43-
cache: 'pnpm'
44-
4551
- name: Install deps
4652
run: pnpm install
4753

@@ -52,15 +58,17 @@ jobs:
5258
npx nx run-many --targets=build --projects=tag:type:metro
5359
ls -l packages/*/dist packages/*/package.json
5460
55-
- name: Release
56-
uses: module-federation/actions@v2
61+
- uses: actions/github-script@v7
62+
id: version_to_release
5763
with:
58-
version: ${{ github.event.inputs.version || 'next' }}
59-
branch: ${{ github.event.inputs.branch }}
60-
type: 'release'
61-
tools: 'changeset'
62-
env:
63-
GITHUB_TOKEN: ${{ secrets.REPO_SCOPED_TOKEN }}
64-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
65-
REPOSITORY: ${{ github.repository }}
66-
REF: ${{ github.ref }}
64+
result-encoding: string
65+
script: |
66+
const fs = require('fs');
67+
const packageJson = JSON.parse(fs.readFileSync('./packages/runtime/package.json', 'utf8'));
68+
return 'v' + packageJson.version;
69+
70+
- name: Publish to npm
71+
run: |
72+
git tag ${{ steps.version_to_release.outputs.result }}
73+
git push origin ${{ steps.version_to_release.outputs.result }}
74+
pnpm -r publish --tag ${{ github.event.inputs.npm_tag }} --publish-branch ${{ github.event.inputs.branch }}

packages/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
},
3838
"publishConfig": {
3939
"access": "public",
40-
"provenance": true,
4140
"registry": "https://registry.npmjs.org/"
4241
}
4342
}

packages/rsbuild-plugin/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
},
7171
"publishConfig": {
7272
"access": "public",
73-
"provenance": true,
7473
"registry": "https://registry.npmjs.org/"
7574
}
7675
}

0 commit comments

Comments
 (0)