Skip to content

Commit 168857f

Browse files
committed
Make NPM_TOKEN optional for package release
Same as w3c/webref#1744 for browser-specs. Classic tokens are no longer supported by npm. We may still want to run the release script from a local machine using a fine-grained access token, but these tokens expire after 90 days at most and are thus not suitable for our release process. I set up OpenID Connect between the `browser-specs` and `web-specs` packages in npm and GitHub Actions and dropped the former `NPM_TOKEN` secret. This update adjusts the release script not to fail if such a token cannot be found. The call to `npmPublish` gets adjusted accordingly only to pass the token if it exists.
1 parent 5f42bd1 commit 168857f

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

.github/workflows/release-package.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ jobs:
3434
run: node src/release-package.js ${{ github.event.pull_request.number }}
3535
env:
3636
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

src/release-package.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ async function releasePackage(prNumber) {
7373

7474
console.log(`- Publish packages/${type} folder to npm`);
7575
const packageFolder = path.join(installFolder, "packages", type, "package.json");
76-
const pubResult = await npmPublish({
77-
package: packageFolder,
78-
token: NPM_TOKEN
76+
const pubOptions = {
77+
package: packageFolder
7978
//, debug: console.debug
80-
});
79+
};
80+
if (NPM_TOKEN) {
81+
pubOptions.token = NPM_TOKEN;
82+
}
83+
const pubResult = await npmPublish(pubOptions);
8184
console.log(`- Published version was ${pubResult.oldVersion}`);
8285
console.log(`- Version bump: ${pubResult.type}`);
8386
console.log(`- Published version is ${pubResult.version}`);
@@ -127,10 +130,6 @@ if (!GITHUB_TOKEN) {
127130
}
128131

129132
const NPM_TOKEN = config?.NPM_TOKEN ?? process.env.NPM_TOKEN;
130-
if (!NPM_TOKEN) {
131-
console.error("NPM_TOKEN must be set to an npm token as an env variable or in a config.json file");
132-
process.exit(1);
133-
}
134133

135134
// Note: npm-publish has a bug and needs an "INPUT_TOKEN" env variable:
136135
// https://github.com/JS-DevTools/npm-publish/issues/15

0 commit comments

Comments
 (0)