Skip to content

Commit c97abfe

Browse files
fix: broken tests ci workflow.
1 parent bf106d7 commit c97abfe

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ yarn-error.log*
3535
.vercel
3636
**/.vercel
3737

38+
.npmrc
3839
**/.npmrc
39-
!/.npmrc
40+
.npmrc.oidc
4041

4142

4243
# Created by https://www.toptal.com/developers/gitignore/api/macos,windows,visualstudiocode,webstorm,intellij,node

‎.npmrc‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎scripts/oidc-install.mjs‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const JF_URL = "https://a0us.jfrog.io";
66
const OIDC_PROVIDER_NAME = "vercel";
77
const ARTIFACTORY_NPM_HOST = "a0us.jfrog.io/artifactory/api/npm/npm";
88
const PUBLIC_NPM_HOST = "registry.npmjs.org";
9+
const BUILD_NPMRC_PATH = ".npmrc.oidc";
910

1011
async function exchangeVercelOidcTokenForArtifactoryToken() {
1112
const oidcToken = process.env.VERCEL_OIDC_TOKEN;
@@ -50,14 +51,24 @@ function pointLockfileAtArtifactory() {
5051
writeFileSync("package-lock.json", rewritten);
5152
}
5253

54+
// Written fresh for this build only, under --userconfig, so the Artifactory
55+
// registry override never leaks into a plain `npm ci` elsewhere (e.g. the
56+
// GitHub Actions test workflows, which install straight from the public
57+
// registry and have no access to this token).
58+
function writeBuildScopedNpmrc(npmToken) {
59+
writeFileSync(
60+
BUILD_NPMRC_PATH,
61+
`registry=https://${ARTIFACTORY_NPM_HOST}/\n` +
62+
`//${ARTIFACTORY_NPM_HOST}/:_authToken=${npmToken}\n`
63+
);
64+
}
65+
5366
const npmToken = await exchangeVercelOidcTokenForArtifactoryToken();
5467

5568
// Only this ephemeral Vercel build checkout is rewritten to fetch through
5669
// Artifactory; the committed lockfile (used by GitHub Actions' npm ci) is
5770
// untouched and keeps resolving against the public registry.
5871
pointLockfileAtArtifactory();
72+
writeBuildScopedNpmrc(npmToken);
5973

60-
execSync("npm ci", {
61-
stdio: "inherit",
62-
env: { ...process.env, NPM_TOKEN: npmToken },
63-
});
74+
execSync(`npm ci --userconfig ${BUILD_NPMRC_PATH}`, { stdio: "inherit" });

0 commit comments

Comments
 (0)