Remove npm auth handling in favor of docs (#695)

* Add docs for npm auth setup

* Show bash examples

* Improve bash pattern

* Update and reference docs

* Remove setup auth code

* Update

* Update

* Update
This commit is contained in:
Bjorn Lu
2026-07-24 15:24:09 +00:00
committed by GitHub
parent 8a9495e0ee
commit 469993ce57
5 changed files with 212 additions and 80 deletions
-47
View File
@@ -1,10 +1,8 @@
import fs from "node:fs/promises";
import * as core from "@actions/core";
import { GitHub } from "./github.ts";
import readChangesetState from "./readChangesetState.ts";
import { runPublish, runVersion } from "./run.ts";
import {
fileExists,
getOptionalInput,
getRequiredInput,
throwOnRenamedInputs,
@@ -84,51 +82,6 @@ import {
"No changesets found. Attempting to publish any unpublished packages to npm",
);
if (process.env.NPM_TOKEN) {
const userNpmrcPath = `${process.env.HOME}/.npmrc`;
if (await fileExists(userNpmrcPath)) {
core.info("Found existing user .npmrc file");
const userNpmrcContent = await fs.readFile(userNpmrcPath, "utf8");
const authLine = userNpmrcContent.split("\n").find((line) => {
// check based on https://github.com/npm/cli/blob/8f8f71e4dd5ee66b3b17888faad5a7bf6c657eed/test/lib/adduser.js#L103-L105
return /^\s*\/\/registry\.npmjs\.org\/:[_-]authToken=/i.test(line);
});
if (authLine) {
core.info(
"Found existing auth token for the npm registry in the user .npmrc file",
);
} else {
core.info(
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one",
);
await fs.appendFile(
userNpmrcPath,
`\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`,
);
}
} else {
core.info(
"No user .npmrc file found, creating one with NPM_TOKEN used as auth token",
);
await fs.writeFile(
userNpmrcPath,
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`,
);
}
} else if (
process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN &&
process.env.ACTIONS_ID_TOKEN_REQUEST_URL
) {
core.info(
"No NPM_TOKEN found, but OIDC is available - using npm trusted publishing",
);
} else {
core.info(
"No NPM_TOKEN or OIDC available - assuming npm is already authenticated",
);
}
const createGithubReleases = core.getBooleanInput(
"create-github-releases",
);
-7
View File
@@ -119,13 +119,6 @@ export function isErrorWithCode(err: unknown, code: string) {
);
}
export function fileExists(filePath: string) {
return fs.access(filePath, fs.constants.F_OK).then(
() => true,
() => false,
);
}
export function getOptionalInput(name: string) {
// normalize empty string default return value of `core.getInput` to undefined
return core.getInput(name) || undefined;