Skip to content

Commit c434426

Browse files
authored
Configure trusted publishing (#1202)
1 parent 9e731bd commit c434426

3 files changed

Lines changed: 44 additions & 19 deletions

File tree

.github/workflows/pr.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,41 @@ jobs:
2222
build:
2323
strategy:
2424
matrix:
25-
os: [ubuntu-latest, windows-latest]
26-
npm: [8]
2725
include:
2826
- os: ubuntu-latest
2927
# npm 6 and 8 have slightly different behavior with verdaccio in publishing tests.
3028
# It's unclear if this translates to meaningful differences in behavior in actual scenarios,
3129
# but test against both versions to be safe. (Only do this on the ubuntu build for speed.)
3230
npm: 6
31+
node: 14
32+
# node 14/npm 8 on ubuntu and windows
33+
- os: ubuntu-latest
34+
npm: 8
35+
node: 14
36+
- os: windows-latest
37+
npm: 8
38+
node: 14
39+
# node 20/npm 11 on ubuntu and windows (can't use 22 for reasons described in release.yml)
40+
- os: ubuntu-latest
41+
npm: 11
42+
node: 20
43+
- os: windows-latest
44+
npm: 11
45+
node: 20
3346

34-
name: build (${{ matrix.os }}, npm ${{ matrix.npm }})
47+
name: build (${{ matrix.os }}, node ${{ matrix.node }}, npm ${{ matrix.npm }})
3548

3649
runs-on: ${{ matrix.os }}
3750

3851
steps:
3952
- name: Check out code
4053
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
4154

42-
- name: Install Node.js from .nvmrc
55+
- name: Install Node.js ${{ matrix.node }}
4356
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
4457
with:
4558
cache: yarn
46-
node-version-file: .nvmrc
59+
node-version: ${{ matrix.node }}
4760

4861
# Guarantee a predictable version of npm for the first round of tests
4962
- name: Install npm@${{ matrix.npm }}
@@ -56,7 +69,7 @@ jobs:
5669
- run: yarn checkchange --verbose
5770

5871
- run: yarn format:check
59-
if: matrix.os == 'ubuntu-latest'
72+
if: matrix.os == 'ubuntu-latest' && matrix.node == 14 && matrix.npm == 8
6073

6174
- run: yarn lint
6275

@@ -76,11 +89,11 @@ jobs:
7689
- name: Check out code
7790
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
7891

79-
- name: Install Node.js 22
92+
- name: Install Node.js
8093
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
8194
with:
8295
cache: yarn
83-
node-version: 24
96+
node-version-file: ./docs/.nvmrc
8497

8598
- run: yarn --immutable
8699
working-directory: ./docs

.github/workflows/release.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ name: Release
44
on:
55
workflow_dispatch:
66

7+
# Use newer node and npm for trusted publishing support. Can't use node 22 yet because of test issues.
8+
# (`npm login` hangs with the current verdaccio version; this is fixed in latest verdaccio, but it's
9+
# not compatible with old node)
710
env:
8-
npmVersion: 8
11+
nodeVersion: 20
12+
npmVersion: 11
913

1014
concurrency:
1115
group: ${{ github.workflow }}-${{ github.ref }}
@@ -19,21 +23,24 @@ jobs:
1923
# This environment contains secrets needed for publishing
2024
environment: release
2125

26+
permissions:
27+
# for trusted publishing
28+
id-token: write
29+
2230
steps:
2331
- name: Check out code
2432
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2533
with:
2634
# Don't save creds in the git config (so it's easier to override later)
2735
persist-credentials: false
2836

29-
- name: Install Node.js from .nvmrc
37+
- name: Install Node.js ${{ env.nodeVersion }}
3038
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
3139
with:
32-
node-version-file: .nvmrc
40+
node-version: ${{ env.nodeVersion }}
3341

34-
# Guarantee a predictable version of npm (the PR build tests against both 6 and 8)
35-
- name: Install package managers
36-
run: npm install --global npm@${{ env.npmVersion }} yarn@1
42+
- name: Install npm@${{ env.npmVersion }}
43+
run: npm install --global npm@${{ env.npmVersion }}
3744

3845
- run: yarn --frozen-lockfile
3946

@@ -58,7 +65,6 @@ jobs:
5865
# Add a token to the remote URL for auth during release
5966
git remote set-url origin "https://$REPO_PAT@github.com/$GITHUB_REPOSITORY"
6067
61-
yarn release -y -n "$NPM_AUTHTOKEN"
68+
yarn release -y
6269
env:
63-
NPM_AUTHTOKEN: ${{ secrets.NPM_AUTHTOKEN }}
6470
REPO_PAT: ${{ secrets.REPO_PAT }}

src/__fixtures__/registry.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const portRange = 1000;
1717
* Lists of tests known to use `Registry`. This is used to make each test try a different
1818
* port range to avoid collisions caused by race conditions with grabbing free ports.
1919
*/
20-
const knownTests = ['packagePublish', 'publishE2E', 'publishNpm', 'syncE2E'];
20+
const knownTests = ['packagePublish'];
2121

2222
// NOTE: If you are getting timeouts and port collisions, set jest.setTimeout to a higher value.
2323
// The default value of 5 seconds may not be enough in situations with port collisions.
@@ -71,15 +71,21 @@ export class Registry {
7171
try {
7272
const registry = this.getUrl();
7373
console.log(`logging in to ${registry}`);
74-
const npm = execa('npm', ['adduser', '--registry', registry]);
74+
const npm = execa('npm', ['login', '--registry', registry, '--verbose']);
75+
// If this is failing or hanging and you need to debug:
76+
// npm.stdout?.pipe(process.stdout);
77+
// npm.stderr?.pipe(process.stderr);
78+
// With Node 22+ and verdaccio 5, the npm login HTTP request fails for some reason.
79+
// This is fixed with latest verdaccio, which we can bump when bumping Node.
80+
7581
// for some reason there's no way to supply the username, password, and email besides stdin
7682
npm.stdout?.on('data', chunk => {
7783
const chunkStr = String(chunk);
7884
if (chunkStr.includes('Username:')) {
7985
npm.stdin?.write(verdaccioUser.username + '\r\n');
8086
} else if (chunkStr.includes('Password:')) {
8187
npm.stdin?.write(verdaccioUser.password + '\r\n');
82-
} else if (chunkStr.includes('Email:')) {
88+
} else if (chunkStr.includes('Email:') || chunkStr.includes('Email (')) {
8389
npm.stdin?.write('fake@example.com\r\n');
8490
}
8591
});

0 commit comments

Comments
 (0)