Skip to content

Commit c9b9cb4

Browse files
mmmmaybe?
1 parent 6fbd15f commit c9b9cb4

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

.github/workflows/first-release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ jobs:
103103
env:
104104
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105105
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
106+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/scripts/first-release-publish.mjs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { existsSync, readdirSync, readFileSync } from "node:fs";
22
import { join } from "node:path";
33
import { spawnSync } from "node:child_process";
44

5-
if (!process.env.NPM_TOKEN) {
6-
console.error("NPM_TOKEN is required for first package releases.");
5+
const npmToken = process.env.NODE_AUTH_TOKEN ?? process.env.NPM_TOKEN;
6+
7+
if (!npmToken) {
8+
console.error("NODE_AUTH_TOKEN or NPM_TOKEN is required for first package releases.");
79
process.exit(1);
810
}
911

@@ -88,9 +90,29 @@ for (const pkg of missingPackages) {
8890
}
8991

9092
for (const pkg of missingPackages) {
93+
const whoami = spawnSync(
94+
"npm",
95+
["whoami", "--registry", "https://registry.npmjs.org"],
96+
{
97+
cwd: pkg.dir,
98+
encoding: "utf8",
99+
env: { ...process.env, NODE_AUTH_TOKEN: npmToken, NPM_TOKEN: npmToken },
100+
stdio: ["inherit", "pipe", "pipe"],
101+
},
102+
);
103+
104+
process.stdout.write(whoami.stdout);
105+
process.stderr.write(whoami.stderr);
106+
107+
if (whoami.status !== 0) {
108+
console.error(`${pkg.name} could not authenticate to npm before publish.`);
109+
process.exit(whoami.status ?? 1);
110+
}
111+
91112
const result = spawnSync("npm", ["publish", "--provenance", "--access", "public"], {
92113
cwd: pkg.dir,
93114
encoding: "utf8",
115+
env: { ...process.env, NODE_AUTH_TOKEN: npmToken, NPM_TOKEN: npmToken },
94116
stdio: ["inherit", "pipe", "pipe"],
95117
});
96118

0 commit comments

Comments
 (0)