Repository navigation
feat: add npm-publish action - #29
Conversation
d313832 to
78ea17a
Compare
6b23cd2 to
d842764
Compare
78ea17a to
e8c3d5a
Compare
d842764 to
b18d781
Compare
73c7a26 to
d8ce20b
Compare
b18d781 to
9df97c4
Compare
d8ce20b to
b6cfa64
Compare
9df97c4 to
6b0838d
Compare
b6cfa64 to
6417928
Compare
1444a1d to
c417f28
Compare
d536f2a to
62b89f9
Compare
c417f28 to
4cda6e0
Compare
62b89f9 to
ff6a100
Compare
4cda6e0 to
7834b10
Compare
ff6a100 to
86f11d8
Compare
7834b10 to
dd2283b
Compare
f4b9982 to
f11467a
Compare
b78588a to
7aa4358
Compare
bda2c84 to
44f891b
Compare
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
44f891b to
ba48c84
Compare
`npm i -g pkdiff@2.0.1` pins pkdiff but not its dependencies, and ran their install scripts in the job, where the token or OIDC may be available. None of its current dependencies has an install script, and pkdiff 2.0.1 installed with --ignore-scripts still writes a diff report against a package's latest version (checked locally), so nothing is lost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
publish.sh packs only when `dry-run` is exactly `true`, so a typo such as `True` or `yes` published. A new first step rejects any value other than `true`, `false` or empty before anything else runs, and publish.sh checks the same. The empty value keeps its documented meaning. The rejected job runs the action with `dry-run: yes` and checks that it fails without packing and before the sanitize step writes its Yarn configuration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GH_TOKEN was in the Publish step's environment only so that main.sh could log the pull request that merged the commit. Every process in that step, Yarn included, inherited the job's GITHUB_TOKEN. The lookup now runs in its own step before Publish, which no longer gets GH_TOKEN. The URL is printed only if it looks like one, since it lands on its own log line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With RUNNER_DEBUG=1, publish.sh ran under `set -x`, which printed the npm token in `YARN_NPM_AUTH_TOKEN=...` and in each test of it. GitHub masks the token only if it came from a secret, not from another step's output. main.sh, publish.sh and needs-publish.sh, whose environment holds the token, no longer turn on xtrace; sanitize.sh and report.sh, which don't see it, still do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… commands The runner reads any output line starting with `::` as a workflow command, and package names, versions, workspace locations, a `publishConfig.registry` and the names of packed files all come from the repository: - needs-publish.sh, which every name and version passes through before anything else prints or uses them, now fails unless the name follows npm's rules (upper case allowed, as in older names) and the version is a semantic version, and prints a rejected value with %q, on one line. - main.sh and sanitize.sh fail on a workspace location with a control character instead of splitting it across lines. - sanitize.sh prints a rejected registry as JSON, on one line. - publish.sh prints Yarn's output while packing or publishing, which lists file names, between ::stop-commands::<random> and ::<random>::. main.sh also passed names and versions to `xargs -n 2` split on whitespace, with quotes interpreted, so a name with a space or a quote was mis-split or failed with an xargs error; they now go NUL-separated to `xargs -0`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
npm's rules allow a package name to start with `-`, and `npm view` and `pkdiff` would read such a name as an option. Both now get their options first and the package spec after `--` (checked with npm 11 and pkdiff 2.0.1). The npm shim in publish-modes.sh fails unless the spec follows `--`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a self-hosted runner that is reused, ~/.yarnrc.yml stays deleted, the generated .yarnrc-<random>.yml stays in the checkout's parent directory, and the checkout's manifests keep their lifecycle scripts removed. The README didn't say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`npm view` decides whether a package is new (token path) or already published (OIDC path). npm_config_registry, or a scope's registry such as npm_config_@scope:registry, set by the caller's job or through $GITHUB_ENV redirected that lookup to another registry. Pass --registry and, for a scoped name, --@<scope>:registry on the command line, which take precedence over environment variables and .npmrc files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
npm_config_registry set by the caller's job or through $GITHUB_ENV redirected `npm i -g pkdiff@2.0.1`, and pkdiff's own `npm pack` of <name>@latest (it reads `npm config get registry` when not given --registry). Pass --registry https://registry.npmjs.org to both. A scope's registry still applies to pkdiff's download, and pkdiff has no option for it; the README says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This is deliberate: a `v`-prefixed version fails rather than being normalised. Say so plainly so callers aren't surprised. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Strict semver is a deliberate choice, now stated in the README; pin it with a test so that it isn't loosened by accident. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… set The sanitize test's control step failed: the runner does not carry NODE_OPTIONS from $GITHUB_ENV into later steps, so the canary never ran. GitHub's workflow-commands docs say "Due to security restrictions, GITHUB_ENV cannot be used to set the NODE_OPTIONS environment variable", and actions/runner's SetEnvFileCommand drops it (_setEnvBlockList in src/Runner.Worker/FileCommandManager.cs, at 35e45850b519). NODE_OPTIONS is the only entry, so BASH_ENV and ENV are still accepted and the action keeps clearing them. NODE_OPTIONS can then come only from the caller's own workflow, so the action no longer clears it. The test drops its NODE_OPTIONS canary and the README no longer says it can arrive through $GITHUB_ENV. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the runner, yarn config get prints booleans with colour codes, so enableScripts compared as a coloured 'false' and the check failed. --json output, read with jq, has no colour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`npm i -g pkdiff@2.0.1` pinned pkdiff but resolved its 49 transitive dependencies by version range at install time. pkdiff/package-lock.json now pins all of them, with integrity hashes, to registry.npmjs.org tarballs, and install-pkdiff.sh installs them with `npm ci --ignore-scripts --registry https://registry.npmjs.org` into a new directory under $RUNNER_TEMP. --registry still matters: `npm ci` downloads the lockfile's registry.npmjs.org URLs from the configured registry. report.sh runs that install's pkdiff by path. The lockfile nests pkdiff's dependencies under it (pkdiff/.npmrc sets install-strategy=shallow), as a global install does: pkdiff reads diff2html's files from its own node_modules, and fails with a hoisted layout. A new workflow job checks that a dry run writes a report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`npm ci` doesn't always keep the lockfile's layout: with npm_config_install_strategy=linked, from $GITHUB_ENV or the user's npmrc, it installs into node_modules/.store, and pkdiff then fails to find its nested diff2html. The command-line flag overrides the environment. The report test job now sets the linked strategy in $GITHUB_ENV. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
report.sh's `|| true`, meant for a package not yet on npm, also hid a pkdiff that was never installed (exit 127) or crashed. It now fails if pkdiff isn't executable, and install-pkdiff.sh fails if `npm ci` didn't nest diff2html under pkdiff: a wrong layout, or an install that did nothing because npm_config_dry_run=true was set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heck fails The check printed the whole lockfile, about 550 lines, on failure. It now prints the keys of the packages without a registry.npmjs.org URL or a sha512 integrity hash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`ls -A` sorts by the locale's collation, which may differ under some glibc locales from the order the expected command assumes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pkdiff is installed from a version 3 lockfile, which npm 6 can't read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pkdiff 2.0.1 pins minimist 0.2.1, which has a prototype-pollution advisory (GHSA-xvch-5gv4-984h) fixed in 0.2.4. The override is keyed on minimist@0.2.1: a bare "minimist" key would, on a fresh lockfile, also force handlebars' minimist from 1.2.8 down to 0.2.4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Corepack runs the Yarn that the nearest package.json names, so a workspace with `"packageManager": "yarn@1.22.22"` got Yarn 1 in its directory. Yarn 1 has no `npm` command and runs `yarn npm publish` as the workspace's own `npm` script, with the token or OIDC in its environment, and the step then reported success. publish.sh now packs and publishes with `corepack yarn@<version>`, the root's version that main.sh checked, and sanitize.sh rejects workspaces other than the root that set `packageManager` or `devEngines.packageManager`.
Yarn matches environment variable names case-insensitively, but environment.sh unset only upper-case YARN_* names. With `yarn_rc_filename=.yarnrc.yml` set through $GITHUB_ENV, Yarn loaded the repository's .yarnrc.yml and its plugins, which could read the token and OIDC, and `yarn_npm_publish_registry` or `Yarn_Npm_Registry_Server` could redirect the publish. environment.sh now unsets every name matching ^yarn_ in any case, except the exact upper-case names the action sets or needs.
--registry pins only the registry's URL. npm view still went through HTTPS_PROXY, https_proxy or npm_config_https_proxy, and npm reports a proxy's 404 as the registry's: a proxy answering CONNECT with 404 made left-pad@1.3.0 look unpublished. That sends an existing package down the token path, published without staging or provenance. npm-view.sh now runs npm with nothing from the environment but PATH, and with empty user and global configuration files. A runner that can reach the registry only through a proxy fails the lookup, which fails the action.
e5eaa76 to
c4a1b9a
Compare
|
@joshuafernandes I cherry-picked your commits from #37 onto this branch. I also just rebased it on the new |
Merge commits are not allowed on this repository
Lines added, by type
Lockfiles:
pkdiff/package-lock.json. Docs includeNOTICE.Adds
npm-publish, a port ofMetaMask/action-npm-publishv7 (640617d). It publishes every public workspace package whose current version isn't on npm yet:npm-token;pkdiffreport, and uploads the tarballs and reports as an artifact. The report needs npm 7 or later, which can read the version 3 lockfilepkdiffis installed from; the README says so.Upstream's sanitize step is kept and extended, so the repository can't run code while publishing. The README example runs
node-checkout-and-setupwithskip-install: truein both the dry-run and publish jobs, and says nothing from the repository may run earlier in the publish job: code that runs earlier could persist into the action's steps through$GITHUB_PATH, the Corepack cache or files in the checkout. Packing and publishing need only the committedyarn.lock, notnode_modules.To review: the first commit is a verbatim copy of upstream's
action.yml,README.mdandscripts/at640617d, so reviewing commit by commit shows each change against upstream. Upstream is MIT-licensed;NOTICEcarries its copyright and permission notice, and the README links to it.Differences from upstream
staged-publishandprovenance. OIDC publishes are always staged, with provenance for public repositories.slack-webhook-url,channel,subteam,usernameandicon-urlinputs, the payload and post steps, and theslackapi/slack-github-actiondependency are removed.publish.shruns directly in each workspace, in the orderyarn workspaces listprints them, stopping at the first failure, instead of throughyarn workspaces foreach exec. That command puts the bins of the workspace and its dependencies first onPATH, so a package declaring abash,jq,npmoryarnbin ran in place of the real tool, with the token in its environment.dry-runmust betrue,falseor empty. A first step rejects any other value before anything else runs. Upstream published for any value other thantrue, such asTrueoryes.corepack yarn@<root version>, and the sanitize step rejects a workspace other than the root that names a package manager (packageManagerordevEngines.packageManager). Corepack runs the Yarn that the nearestpackage.jsonnames, and Yarn 1 runsyarn npm publishas the workspace's ownnpmscript, which got the token or the OIDC request variables.npm viewandpkdiffget the package spec after--, so a name starting with-isn't read as an option.npm-publish-dry-run-<sha>. It setsoverwrite: true, so a second dry run in the same workflow run replaces it instead of failing.pkdiff2.0.1 and its 49 dependencies are pinned by a lockfile,pkdiff/package-lock.json, with integrity hashes, tohttps://registry.npmjs.orgtarballs. Upstream runsnpm i -g pkdiff@2.0.1, so the dependencies resolve by version range at install time.scripts/install-pkdiff.shrunsnpm ci --ignore-scripts --install-strategy=shallow --registry https://registry.npmjs.orgin a new directory,$RUNNER_TEMP/npm-publish-pkdiff, holding only the manifest and the lockfile: outside the repository, so no.npmrcin it applies; without install scripts; and with--registry, sincenpm cidownloads the lockfile's URLs from the configured registry andnpm_config_registrywould otherwise redirect them. The lockfile nestspkdiff's dependencies under it (pkdiff/.npmrcsetsinstall-strategy=shallowfornpm install), as a global install does:pkdiffreadsdiff2html's files from its ownnode_modules.--install-strategy=shallowonnpm cikeeps that layout when the caller's job sets anothernpm_config_install_strategy, such aslinked, andinstall-pkdiff.shfails ifdiff2htmlisn't then nested underpkdiff.pkdiff/package.jsonoverridespkdiff'sminimistfrom 0.2.1 to 0.2.4, which fixes a prototype-pollution advisory (GHSA-xvch-5gv4-984h); the override's key isminimist@0.2.1, sohandlebarskeeps its ownminimist1.2.8.report.shruns that install'spkdiffby path, with--registry https://registry.npmjs.org, which it passes to thenpm packthat downloads<name>@latest. That doesn't override a scope's registry (such asnpm_config_@scope:registryset through$GITHUB_ENV), andpkdiffhas no option that does, so for a scoped package the dry run's diff report can still be made against a tarball from another registry.report.shignorespkdiff's failures, as for a package not yet on npm, but fails ifpkdiffisn't installed. The report is informational only; nothing is published from it. The README says so.npm viewis pinned tohttps://registry.npmjs.orgwith--registryand, for a scoped package,--@<scope>:registry, which--registrydoesn't override. Command-line options take precedence overnpm_config_*variables set by the caller's job or through$GITHUB_ENV, and over.npmrcfiles, so neither can redirect the lookup that chooses between the token and OIDC.npm viewalso runs with no environment variables butPATHand with empty user and global configuration files, so a proxy (HTTPS_PROXY,npm_config_https_proxyand the like) can't answer 404 for a package that exists. A self-hosted runner that reaches npm only through a proxy therefore fails the lookup; the README says so.$RUNNER_TEMP/npm-publish-packagesrather than/tmp, so stale tarballs on a reused runner aren't reported or uploaded.dry-runis set once,trueif any package was packed, and is also an action output. Upstream wrote it once per package, so the last package handled decided it.YARN_RC_FILENAMEto$GITHUB_ENV, so every later Yarn command in the caller's job used the action's stripped-down configuration. It is now a step output passed to the publish step'senv:, andmain.shfails if it is empty.YARN_*variables are unset in any case, except the action's own. Yarn reads their names case-insensitively, soyarn_rc_filenamewould load the repository's.yarnrc.ymlandyarn_npm_publish_registrywould redirect the publish..corepack.envis ignored (COREPACK_ENV_FILE=0). Corepack reads that file from the project, andCOREPACK_ENABLE_UNSAFE_CUSTOM_URLS=1there letspackageManagername any URL as the Yarn to download and run with the token and OIDC available.COREPACK_*variables set by the caller's job, such as a mirror's, are left alone.BASH_ENVandENVare cleared in each step'senv:, so values an earlier step wrote to$GITHUB_ENVdon't run code in the action's steps. (The runner refusesNODE_OPTIONSin$GITHUB_ENV, so it can only come from the caller's own workflow.)GH_TOKENis no longer in the Publish step's environment.RUNNER_DEBUG,main.sh,publish.shandneeds-publish.shdon't run underset -x, which printed the npm token; GitHub masks it only if it came from a secret.v1.2.3fails (the README says so). Workspace locations with a control character fail. Names and versions reachxargsNUL-separated. Yarn's output while packing or publishing, which lists file names, is printed between::stop-commands::<random>and::<random>::, and a rejected registry is printed as JSON on one line, so no repository text is read as a workflow command.On a reused (self-hosted) runner, the sanitize step's changes outlast the job:
~/.yarnrc.ymlstays deleted, the generated.yarnrc-<random>.ymlstays in the checkout's parent directory, and the checkout's manifests keep their lifecycle scripts removed. The README says so.Security properties
.yarnrc.yml, Yarn plugins,yarnPath, lifecycle scripts,YARN_*overrides,.corepack.envor package bins, and noBASH_ENVorENVfrom earlier steps. Nothing from the repository may run earlier in the job (see the README).https://registry.npmjs.org, and looked up only there.pkdiffand its dependencies are installed from there too, at the versions and integrity hashes inpkdiff/package-lock.json, without install scripts; its diff report can follow a scope's registry (see above).GH_TOKENisn't in the Publish step's environment, and the npm token isn't traced underRUNNER_DEBUG.run:step, and none is printed where the runner could read it as a workflow command.Tests
test/publish-modes.shrunspublish.shandmain.shwithyarnandnpmreplaced by stand-ins that record their arguments:dry-runcombination, and an invaliddry-run;--tag,--stagedand--provenance, that the token is unset for OIDC publishes, and that package specs follow--;0.0.0packages, an emptynpm-tag, Yarn below 4.16, and npm lookup errors other than E404;YARN_RC_FILENAME;v-prefixed version such asv1.2.3, which fail without being read as workflow commands, and Yarn's output wrapped in::stop-commands::;npm viewgets--registry https://registry.npmjs.organd, for a scoped package,--@<scope>:registry=https://registry.npmjs.org, and runs with no proxy ornpm_config_*variables and with empty configuration files;corepack yarn@<root version>, never plainyarn, and that a Yarn version that isn'tMAJOR.MINOR.PATCHfails;install-pkdiff.shrunsnpm ci --ignore-scripts --install-strategy=shallow --registry https://registry.npmjs.orgin a new directory (an.npmrcleft there doesn't survive) and fails ifdiff2htmlisn't nested underpkdiffafterwards, and thatreport.shruns that install'spkdiff, not one onPATH, with--registry https://registry.npmjs.org, and fails if it isn't installed;pkdiff/package-lock.jsonis lockfile version 3, nestsdiff2htmlunderpkdiff, resolves every package tohttps://registry.npmjs.org/with asha512integrity hash (on failure, the test lists only the packages that aren't), and haspkdiff'sminimistat 0.2.4;RUNNER_DEBUGdoesn't print the token;test/environment-variables.shchecks thatscripts/environment.shleaves only the action's ownYARN_*variables, in any case, and that real Corepack then ignores a.corepack.envthat allows a URL aspackageManager.The workflow runs both, and runs the action with real Yarn against fixture projects built by
test/make-fixture.sh:0.0.0one are skipped), after whichYARN_RC_FILENAMEisn't set in the caller's steps;npm_config_registryand a scope's registry set to an unreachable host in$GITHUB_ENV(after a control showing npm uses them), which still looks packages up on, and installspkdifffrom,https://registry.npmjs.org;npm_config_install_strategy=linkedset in$GITHUB_ENV, which writes apkdiffreport withpkdiffinstalled from the lockfile;dry-run: truewith a token;dry-run: falsewithout credentials, for both a new and an existing package;dry-run: yes, which fails without packing and before the sanitize step writes its Yarn configuration;publishConfig.registry;packageManagerordevEngines.packageManager, which the sanitize step rejects before itsnpmscript can run;yarnPath, lifecycle scripts andbash/jq/npm/yarnbins would write marker files, as wouldBASH_ENVset in$GITHUB_ENV(first checked to run code in an ordinary step);YARN_*overrides such asYARN_NPM_REGISTRY_SERVER, and lowercase ones such asyarn_npm_publish_registryandyarn_rc_filename, don't change the configuration the Publish step reads, after a control showing they do apply withoutenvironment.sh.To test before ocap-kernel's first release with these actions: run its
publish-release.ymlfrom a branch viaworkflow_dispatch, with the publish job's environment andid-tokenremoved, so the action packs instead of publishing.🤖 Generated with Claude Code