Skip to content

Commit f045a45

Browse files
authored
chore: enable trusted publishing for npm packages (#4039)
1 parent 889091e commit f045a45

File tree

4 files changed

+77
-20
lines changed

4 files changed

+77
-20
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 18
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '18'
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: 26 additions & 18 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-
run: |
36-
corepack prepare [email protected] --activate
37-
corepack enable
38-
3935
- name: Setup Node.js 18
40-
uses: actions/setup-node@v3
36+
uses: actions/setup-node@v4
4137
with:
4238
node-version: '18'
4339
cache: 'pnpm'
4440

41+
# Update npm to the latest version to enable OIDC
42+
# Use corepack to install pnpm
43+
- name: Setup Package Managers
44+
run: |
45+
npm install -g npm@latest
46+
npm --version
47+
npm install -g corepack@latest --force
48+
corepack prepare [email protected] --activate
49+
corepack enable
50+
4551
- name: Install deps
4652
run: pnpm install
4753

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