Repository navigation
feat: add node-checkout-and-setup action - #24
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
acee47d to
cdcf277
Compare
…up@097d47e Verbatim copies of the upstream files the port is based on, so that the following commits show the port's changes as modifications. This commit is not expected to pass CI. From https://github.com/MetaMask/action-checkout-and-setup at 097d47e741dfa9c09ee779a020b8851875e72904: - action.yml -> node-checkout-and-setup/action.yml - README.md -> node-checkout-and-setup/README.md - .github/workflows/build-lint-test.yml -> .github/workflows/test_node-checkout-and-setup.yml From https://github.com/MetaMask/action-retry-command at 2377689bfd9a03010a956b7c14273a2fc43d20cf: - action.yml -> node-checkout-and-setup/scripts/retry.sh The port folds action-retry-command into the script node-checkout-and-setup/scripts/retry.sh. The retry loop upstream lives inline in that repository's action.yml, so the action.yml is the baseline for the script and is placed at the script's path; the two upstream action.yml files could not otherwise share a path. Upstream's scripts/get.sh (a jq reader for package.json, identical in both repositories and not used by either action) has no counterpart in the port and is not copied. The port's other scripts are extracted from the inline steps of action.yml in a later commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the bash of the metadata download, Node.js version computation, cache path computation and release resolution steps into scripts under scripts/, called with env: inputs only. The logic is unchanged apart from: - The metadata directory is passed in as METADATA_DIR. - compute-cache-paths.sh writes its multiline output with a random heredoc delimiter rather than a fixed EOF. - resolve-node-version.sh uses jq's `// empty` instead of comparing against "null". Also rename the action, its steps and step ids, reorder the inputs and reword their descriptions and messages, and merge the "Print Node.js version" step into "Enable Corepack". Behaviour is otherwise as upstream; the following commits make the port's changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove fetch-depth, filter, yarn-install-max-retries and yarn-tarball, and the "Hydrate Yarn" step that used the last. ocap-kernel doesn't set any of them: the checkout now always uses fetch-depth 1, `yarn --immutable` is always tried up to 5 times, and ocap-kernel keeps no Yarn tarball. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y.sh Replace MetaMask/action-retry-command with scripts/retry.sh, a bash function in the action's own directory, so the action has no dependency on another MetaMask action. Differences from action-retry-command: - The command and its arguments are executed directly rather than through `$SHELL -c`, so no input is evaluated by a shell. - Attempts are fixed at 5, with the same 1, 2, 4 and 8 second backoff. - It doesn't sleep after the last failed attempt. The allow-scripts step now checks `yarn bin allow-scripts` once and retries only `yarn allow-scripts`, and says when it skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the SPDX header and pin actions/cache, actions/checkout and actions/setup-node to commit SHAs. Move both setup-node steps from v6 to v7. Since v5, setup-node can turn on a package-manager cache by itself based on package.json, so the first setup-node step sets `package-manager-cache: false`: it must not use any cache, which in a high-risk job would be a cache read. The second step's explicit `cache: yarn` is unaffected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sk jobs Upstream supports `is-high-risk-environment: true` with `cache-node-modules: true` as a write-only mode: the job doesn't read the cache but saves node_modules to it. Fail on that combination instead, so that a job holding write tokens or publish credentials never touches the Actions cache. Nothing the port keeps depends on the write-only mode. Cache paths and package.json are now only needed in low-risk jobs, and the Yarn cache step checks for `false` rather than "not `true`". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd validate booleans persist-credentials now defaults to false (upstream: true), so the job token is not left in .git/config for later steps unless the caller asks for it. Every boolean input must now be exactly `true` or `false`. Upstream only checked is-high-risk-environment, and its step conditions compare against 'true' or 'false' inconsistently, so another value could select a mix of branches. An empty persist-credentials, for example, would otherwise reach actions/checkout and pick up its default of `true`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the outputs node-modules-cache-hit, skipped-setup and node-version, and drop yarn-cache-hit and computed-node-version, which upstream exposes only for its own tests. actions/cache leaves cache-hit empty on a miss, so upstream's node-modules-cache-hit and skipped-setup are empty both on a miss and when no cache was consulted. Report `true` or `false` instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ship it Node.js 25 and later don't ship Corepack, so upstream's `corepack enable` would use whichever Corepack the runner image has on its PATH, if any. When the selected Node.js has no corepack binary next to it, install corepack@0.36.0 for it with npm (retried, without install scripts), and run the corepack next to the selected node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream checks for allow-scripts with `yarn bin allow-scripts`. That is the first Yarn command after a cache restore, and Corepack downloads Yarn for it, so a failed download reads as "allow-scripts is not installed" and the step silently skips the allowlisted install scripts. Check for node_modules/.bin/allow-scripts instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
download-metadata.sh reuses a non-empty file at its destination. When the action runs twice in a job, with different refs, the second call would reuse the first call's .nvmrc and package.json. Clear the metadata directory first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…space Replace upstream's tests, which ran the action against its own repository, with a test workflow that runs it against test-fixture/, a Yarn 4 workspace using LavaMoat's allow-scripts plugin. One of its dependencies has an allowed postinstall that writes a marker file, so the tests can tell whether allow-scripts ran. The workflow covers Node.js versions and .nvmrc, invalid inputs, the node_modules cache sequence (save, skip setup, force-setup, restore, high-risk ignoring an existing entry), skip-install in both risk modes, the action's own checkout and credentials, a pre-checked-out workspace, and script-level tests of the metadata download and the retry loop. Tests that need the fixture at the root of a ref use the test-fixtures/node-checkout-and-setup branch, made by test/publish-fixture.sh; a job fails if it drifts from test-fixture/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace upstream's README with one describing the port: usage, inputs and outputs, behaviour, security properties, tests, and the differences from upstream. Make @Consensys-Incorporated/ocap-kernel a co-owner of the action and its test workflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…README The README listed only the persist-credentials default, the high-risk cache rule and the removed inputs. Add the other differences: boolean validation, outputs, retry.sh, setup-node v7, the Corepack install and allow-scripts detection, and mention that the action also replaces action-retry-command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Align the inputs and outputs tables. No content changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erge order MetaMask/action-checkout-and-setup and action-retry-command carry no license, so the README no longer calls them MIT. The fixture branch is shared by every pull request, so republishing it breaks the fixture check on other open pull requests until the change merges. Say so, and that fixture changes should merge first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… checkout follows yarn.lock is downloaded into the workspace for the cache lookup and relies on actions/checkout to overwrite it. When the caller had already checked out a tree without a root yarn.lock, the action skips its own checkout, so the downloaded file stayed and yarn --immutable installed from a lockfile the tree doesn't have. It is now removed after the lookup whenever no checkout follows. Upstream has the same behaviour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… downloaded one The previous fix removed a downloaded yarn.lock when no checkout followed. Review found that a pre-checked-out tree without yarn.lock then failed later, in setup-node's Yarn cache step, and that its cache keys ended in an empty hash, which actions/cache matched by prefix and restored another job's node_modules. The new test passed for that unrelated reason. Now yarn.lock is not downloaded into a workspace that is already checked out, and a step right after checkout fails with a clear error when there is no root yarn.lock and install isn't skipped. The removal step and its output are gone. The test asserts that the action fails before Node.js is set up, and a script test asserts that no yarn.lock is downloaded into a checkout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sk-guarded The high-risk test shows node_modules was not restored, but a job cannot observe whether "Restore Yarn cache" (setup-node with `cache: yarn`) ran, so removing its guard failed no test. Check action.yml instead: every actions/cache* step and every setup-node step with a `cache` input must have `inputs.is-high-risk-environment == 'false'` as a term of a plain `&&` condition, and every setup-node step must set `package-manager-cache: false` or be guarded. The check fails if it finds no cache steps, so a parsing mistake cannot make it pass. It uses yq and jq, which ubuntu-latest includes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… ignored In a workspace that is already a git repository the action skips its checkout, and `ref` and `persist-credentials` are only passed to that checkout. A caller who set either got neither, with no message. Warn instead of failing, so that callers who check out first and pass a redundant `ref` keep working. The input values are not printed. Also correct the README: in such a workspace `.git/config` is left as the earlier checkout set it, and a missing .nvmrc or package.json is still downloaded from `ref`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In a workspace that was already checked out, a missing .nvmrc or package.json was still downloaded from `ref` or github.sha, which may differ from the commit checked out. yarn.lock already wasn't. Now nothing is: without node-version, a checkout without .nvmrc fails with an error saying to add one or set node-version, and a checkout without package.json caches **/node_modules. `ref` therefore has no effect at all in a checkout, which the warning now says. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since nothing is downloaded into an existing checkout, a checkout without a root package.json fell back to the broad cache path and left Corepack to run its default Yarn. The requirement step now checks package.json as well as yarn.lock, unless skip-install, and the pre-checked-out test covers both files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44485a9 to
f41ac17
Compare
|
Looks good overall. Two suggestions, neither blocking. 1. Detect an existing checkout once, without
|
joshuafernandes
left a comment
There was a problem hiding this comment.
One minor comment @rekmarks-consensys-1 but good to merge
…sh, not hashFiles
hashFiles('.git') hashes every file under .git, which is slow on large
checkouts and subject to the runner's hashFiles time limit, and it returns
'' for an empty .git directory, where download-metadata.sh already treats
the workspace as checked out. The script now outputs checked-out from its
existing -e .git test, and both checkout steps use that.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pty .git The checkout steps now depend on download-metadata.sh's checked-out output, so check it for a repository, an empty .git directory, a .git file and no .git, and that the action neither checks out nor downloads into a workspace with an empty .git directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@joshuafernandes Addressed finding 1 and deferred 2 to #35. Needs reapproval. |
Lines added, by type
Lockfiles: the test fixture's
yarn.lockand Yarn plugin bundle.Adds
node-checkout-and-setup, a port ofMetaMask/action-checkout-and-setupv3 (097d47e) that also replacesMetaMask/action-retry-command. It checks out the repository (unless the workspace already is one), sets up Node.js and Corepack, and runsyarn --immutablewith retries. It can also cachenode_modules.This is one of the PRs adding the Node.js/npm actions ocap-kernel uses in place of MetaMask's:
node-checkout-and-setup(#24),check-skip-merge-queue(#25),check-changelog(#26, stacked with #31 and #32),npm-is-release(#27),npm-publish-release(#28) andnpm-publish(#29). Each is based onmainand independent of the others, except that each appends its own lines toCODEOWNERS, so a PR merged after another needs a one-line rebase. Each new directory is co-owned by@Consensys-Incorporated/ocap-kernel-adminsinCODEOWNERS.To review: the first commit is a verbatim copy of upstream (
action-checkout-and-setupat097d47e, andaction-retry-commandat2377689asscripts/retry.sh), so reviewing commit by commit shows each change against upstream.Differences from upstream
persist-credentialsdefaults tofalse(upstream:true).is-high-risk-environment: truewithcache-node-modules: truenow fails. Upstream supported it as a write-only cache mode. Without that mode, a high-risk job never touches the Actions cache.fetch-depth(the checkout always uses 1),filter,yarn-install-max-retries(always 5 attempts) andyarn-tarball.node-modules-cache-hit,skipped-setup(both alwaystrueorfalse) andnode-version.scripts/retry.sh. It runs the command directly rather than through$SHELL -c, and doesn't sleep after the last attempt.setup-nodesteps pin v7 (upstream: v6). The first setspackage-manager-cache: false, so no cache is used regardless of what the repository'spackage.jsondeclares.trueorfalse. An emptypersist-credentials, for example, would otherwise reachactions/checkoutand pick up its default oftrue.corepack@0.36.0is installed for it, rather than relying on whichever Corepack the runner image has.allow-scriptsis detected bynode_modules/.bin/allow-scriptsrather thanyarn bin allow-scripts. After a cache restore, that is the first Yarn command, so a failed Yarn download read as "not installed" and the allowlisted install scripts were silently skipped..nvmrcandpackage.json..nvmrc,package.jsonoryarn.lockfromrefor the triggering commit, which may differ from the commit checked out. A downloadedyarn.lockis written to the workspace and relies onactions/checkoutto overwrite it; in a workspace that was already checked out from a tree without a rootyarn.lock, nothing overwrote it, so the install used a lockfile from another ref. Now the metadata is only downloaded into a workspace that isn't checked out yet. In a checkout without.nvmrc, the action fails with a clear error unlessnode-versionis given.yarn.lockandpackage.jsonare required (unlessskip-install). A step right after checkout fails with a clear error when either is missing. Without ayarn.lock, the cache keys end in an empty hash, which actions/cache matches by prefix; without apackage.json, Corepack runs its default Yarn.reforpersist-credentials: trueis given:refthen has no effect at all, andpersist-credentialsapplies only to the action's own checkout. Upstream ignored them silently. The input values aren't printed.-e .gitindownload-metadata.sh, whosechecked-outoutput the warn and checkout steps use. Upstream useshashFiles('.git'), which hashes every file under.gitand treats an empty.gitdirectory as absent, so it could disagree with the script.Security properties
actions/cache, and notsetup-node'scache:.skip-install: trueruns no repository code..git/configunless the caller asks for it. A workspace checked out earlier keeps its.git/configas that checkout set it.run:steps only throughenv:.Tests
.github/workflows/test_node-checkout-and-setup.ymlruns the action againsttest-fixture/, a Yarn 4 workspace that uses LavaMoat'sallow-scriptsplugin. One of its dependencies has an allowedpostinstallthat writes a marker file, so the tests can tell whetherallow-scriptsran. The workflow covers:22.x,24.x,26.x,lts/*,v24.13.0and24, plus.nvmrcalone, and that Yarn comes from the selected Node.js's Corepack.force-setupwith and withoutskip-allow-scripts; a low-risk job restores; a high-risk job ignores an existing entry.skip-install, in both risk modes.fetch-depth, credentials persisted or not (including the default, with the input left unset), and a clean tree afterwards.yarn.lockor without apackage.jsonfails before Node.js is set up. Script tests check thatdownload-metadata.shdownloads nothing into a checkout, and that it fails there without.nvmrcunlessnode-versionis given.download-metadata.sh'schecked-outoutput is checked with a repository, an empty.gitdirectory, a.gitfile and no.git; a job checks that the action neither checks out nor downloads into a workspace with an empty.gitdirectory.raw.githubusercontent.comandgh api, of the retry loop, and of the warning about ignoredrefandpersist-credentials(annotations can't be read from inside a job).test/check-cache-guards.shchecksaction.ymlstructurally, since a job can't observe whether a cache step was skipped: everyactions/cache*step and everysetup-nodestep with acacheinput must haveinputs.is-high-risk-environment == 'false'in a plain&&condition, and everysetup-nodestep must setpackage-manager-cache: falseor be guarded. It fails if it finds no cache steps.Some tests need a ref of this repository whose root is the fixture.
test-fixtures/node-checkout-and-setupis that ref: a single-commit branch made bytest/publish-fixture.sh. A test job fails if the branch andtest-fixture/drift apart. There is one fixture branch for the whole repository, so republishing it fails that job on every other open PR until the change merges; the README says to merge fixture changes first.A note on the checkout test:
actions/checkoutempties a workspace that isn't a git repository, which would delete the local action under test. So that test removes.gitand lets the action check out the same commit again.🤖 Generated with Claude Code