Skip to content

Commit ad445dc

Browse files
ivanbarlogclaude
andcommitted
fix: fetch OIDC token and write to .npmrc before npm publish
publib's NPM_TRUSTED_PUBLISHER flag skips its own token check but does not set up npm auth — it leaves ~/.npmrc empty and npm publish fails with ENEEDAUTH. Patch the Release step to request a GitHub OIDC token with the npm registry as audience and write it to ~/.npmrc before publib runs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ff4d0b9 commit ad445dc

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { awscdk } from "projen";
1+
import { awscdk, JsonPatch } from "projen";
22
import { NodePackageManager, NpmAccess } from "projen/lib/javascript";
33
import { ReleaseTrigger } from "projen/lib/release";
44

@@ -40,6 +40,25 @@ const project = new awscdk.AwsCdkConstructLibrary({
4040
vscode: false,
4141
});
4242

43+
// publib's NPM_TRUSTED_PUBLISHER skips its own token check but doesn't write
44+
// npm auth — fetch the GitHub OIDC token and write it to .npmrc before publib runs.
45+
const releaseWorkflow = project.tryFindObjectFile(
46+
".github/workflows/release.yml",
47+
);
48+
if (releaseWorkflow) {
49+
releaseWorkflow.patch(
50+
JsonPatch.replace(
51+
"/jobs/release_npm/steps/10/run",
52+
[
53+
`TOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "\${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=https://registry.npmjs.org" | jq -r '.value')`,
54+
`echo "::add-mask::$TOKEN"`,
55+
`echo "//registry.npmjs.org/:_authToken=$TOKEN" >> ~/.npmrc`,
56+
`npx -p publib@latest publib-npm`,
57+
].join("\n"),
58+
),
59+
);
60+
}
61+
4362
project.package.addField("volta", {
4463
node: "24.13.0",
4564
});

0 commit comments

Comments
 (0)