Skip to content

feat: add node-checkout-and-setup action - #24

Merged
rekmarks-consensys-1 merged 24 commits into
mainfrom
ocap/node-checkout-and-setup
Nov 25, 2026
Merged

rekmarks-consensys-1 merged 24 commits into
mainfrom
ocap/node-checkout-and-setup

Conversation

@rekmarks-consensys-1

@rekmarks-consensys-1 rekmarks-consensys-1 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Lines added, by type

Code Tests Docs Lockfiles Config Total
556 (23%) 953 (40%) 155 711 4 2379

Lockfiles: the test fixture's yarn.lock and Yarn plugin bundle.

Adds node-checkout-and-setup, a port of MetaMask/action-checkout-and-setup v3 (097d47e) that also replaces MetaMask/action-retry-command. It checks out the repository (unless the workspace already is one), sets up Node.js and Corepack, and runs yarn --immutable with retries. It can also cache node_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) and npm-publish (#29). Each is based on main and independent of the others, except that each appends its own lines to CODEOWNERS, so a PR merged after another needs a one-line rebase. Each new directory is co-owned by @Consensys-Incorporated/ocap-kernel-admins in CODEOWNERS.

To review: the first commit is a verbatim copy of upstream (action-checkout-and-setup at 097d47e, and action-retry-command at 2377689 as scripts/retry.sh), so reviewing commit by commit shows each change against upstream.

Differences from upstream

  • persist-credentials defaults to false (upstream: true).
  • is-high-risk-environment: true with cache-node-modules: true now fails. Upstream supported it as a write-only cache mode. Without that mode, a high-risk job never touches the Actions cache.
  • Removed inputs: fetch-depth (the checkout always uses 1), filter, yarn-install-max-retries (always 5 attempts) and yarn-tarball.
  • Outputs are node-modules-cache-hit, skipped-setup (both always true or false) and node-version.
  • The retry loop is scripts/retry.sh. It runs the command directly rather than through $SHELL -c, and doesn't sleep after the last attempt.
  • The two setup-node steps pin v7 (upstream: v6). The first sets package-manager-cache: false, so no cache is used regardless of what the repository's package.json declares.
  • The cache key matches upstream's, so old and new jobs share cache entries during the transition.
  • Every boolean input must be exactly true or false. An empty persist-credentials, for example, would otherwise reach actions/checkout and pick up its default of true.
  • When the selected Node.js doesn't ship Corepack (Node.js 25 and later), corepack@0.36.0 is installed for it, rather than relying on whichever Corepack the runner image has.
  • allow-scripts is detected by node_modules/.bin/allow-scripts rather than yarn 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.
  • The metadata directory is cleared first, so a second call in the same job with a different ref doesn't reuse the first call's .nvmrc and package.json.
  • Nothing is downloaded into an existing checkout. Upstream downloads a missing .nvmrc, package.json or yarn.lock from ref or the triggering commit, which may differ from the commit checked out. A downloaded yarn.lock is written to the workspace and relies on actions/checkout to overwrite it; in a workspace that was already checked out from a tree without a root yarn.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 unless node-version is given.
  • A root yarn.lock and package.json are required (unless skip-install). A step right after checkout fails with a clear error when either is missing. Without a yarn.lock, the cache keys end in an empty hash, which actions/cache matches by prefix; without a package.json, Corepack runs its default Yarn.
  • When the workspace is already a git repository, the action doesn't check out, and warns if ref or persist-credentials: true is given: ref then has no effect at all, and persist-credentials applies only to the action's own checkout. Upstream ignored them silently. The input values aren't printed.
  • Whether the workspace is already a git repository is decided once, by -e .git in download-metadata.sh, whose checked-out output the warn and checkout steps use. Upstream uses hashFiles('.git'), which hashes every file under .git and treats an empty .git directory as absent, so it could disagree with the script.

Security properties

  • High-risk mode never reads or writes any Actions cache: not actions/cache, and not setup-node's cache:.
  • skip-install: true runs no repository code.
  • When the action checks out, the job token isn't left in .git/config unless the caller asks for it. A workspace checked out earlier keeps its .git/config as that checkout set it.
  • Inputs reach run: steps only through env:.

Tests

.github/workflows/test_node-checkout-and-setup.yml runs the action against test-fixture/, a Yarn 4 workspace that uses 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 22.x, 24.x, 26.x, lts/*, v24.13.0 and 24, plus .nvmrc alone, and that Yarn comes from the selected Node.js's Corepack.
  • Invalid inputs, run in a workspace the action would otherwise set up, so a failure can only come from validation.
  • The cache sequence, with a cache key unique to each workflow run: the first job misses and saves; a second job skips setup; force-setup with and without skip-allow-scripts; a low-risk job restores; a high-risk job ignores an existing entry.
  • skip-install, in both risk modes.
  • The action's own checkout: fetch-depth, credentials persisted or not (including the default, with the input left unset), and a clean tree afterwards.
  • A workspace that is already checked out isn't checked out again, and one checked out without a yarn.lock or without a package.json fails before Node.js is set up. Script tests check that download-metadata.sh downloads nothing into a checkout, and that it fails there without .nvmrc unless node-version is given.
  • download-metadata.sh's checked-out output is checked with a repository, an empty .git directory, a .git file and no .git; a job checks that the action neither checks out nor downloads into a workspace with an empty .git directory.
  • Script-level tests of the metadata download, over both raw.githubusercontent.com and gh api, of the retry loop, and of the warning about ignored ref and persist-credentials (annotations can't be read from inside a job).
  • test/check-cache-guards.sh checks action.yml structurally, since a job can't observe whether a cache step was skipped: every actions/cache* step and every setup-node step with a cache input must have inputs.is-high-risk-environment == 'false' in a plain && condition, and every setup-node step must set package-manager-cache: false or 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-setup is that ref: a single-commit branch made by test/publish-fixture.sh. A test job fails if the branch and test-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/checkout empties a workspace that isn't a git repository, which would delete the local action under test. So that test removes .git and lets the action check out the same commit again.

🤖 Generated with Claude Code

@socket-security

socket-security Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​lavamoat/​allow-scripts@​5.1.19910010092100
Addedallow-scripts-marker@​1.0.0N/AN/AN/AN/AN/A

View full report

@rekmarks-consensys-1
rekmarks-consensys-1 force-pushed the ocap/node-checkout-and-setup branch from acee47d to cdcf277 Compare November 24, 2026 19:36
rekmarks-consensys-1 and others added 22 commits November 24, 2026 14:28
…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>
@rekmarks-consensys-1
rekmarks-consensys-1 force-pushed the ocap/node-checkout-and-setup branch from 44485a9 to f41ac17 Compare November 24, 2026 22:37
@rekmarks-consensys-1
rekmarks-consensys-1 marked this pull request as ready for review November 24, 2026 23:39
@rekmarks-consensys-1
rekmarks-consensys-1 requested review from a team as code owners November 24, 2026 23:39
@joshuafernandes

Copy link
Copy Markdown
Contributor

Looks good overall. Two suggestions, neither blocking.

1. Detect an existing checkout once, without hashFiles('.git')

The warn and checkout steps use hashFiles('.git') to test whether .git exists. That comes from upstream, but:

  • It hashes every file under .git just to check that it exists, and it does so twice. That's cheap with fetch-depth: 1, but slow on a large or full-history checkout, and hashFiles has a runner time limit.
  • download-metadata.sh already answers the same question with [[ -e .git ]], and the two can disagree. With an empty .git directory, the script treats the workspace as a checkout and downloads nothing, while hashFiles returns '', so actions/checkout runs too.

Suggestion: output the script's answer and use it in both conditions.

write_output "checked-out" "$checked_out"
# warn
if: ${{ steps.try-skip-setup.outputs.cache-hit != 'true' && steps.download-metadata.outputs.checked-out == 'true' }}
# checkout
if: ${{ steps.try-skip-setup.outputs.cache-hit != 'true' && steps.download-metadata.outputs.checked-out != 'true' }}

Nothing between download-metadata and the checkout creates .git, so the output can't go stale. If you'd rather keep hashFiles, hashFiles('.git/HEAD') hashes a single file instead.

2. Key the fixture branch by tree SHA

test-fixtures/node-checkout-and-setup is a single force-pushed branch. Republishing it makes the fixture check fail on every other open PR, because that job runs on every pull_request, until the change merges and those PRs are rebased. Two PRs that both change the fixture can't both pass at the same time.

Naming the branch after the fixture's tree SHA avoids that without giving CI write access:

tree="$(git rev-parse HEAD:node-checkout-and-setup/test-fixture)"
commit="$(git commit-tree "$tree" -m "Test fixture for node-checkout-and-setup")"
git push origin "$commit:refs/heads/test-fixtures/node-checkout-and-setup/$tree"

The workflow computes the same $tree from its own checkout and uses that branch. The up-to-date job then checks that the branch for its tree exists. Each fixture version gets its own branch, nothing is force-pushed, and PRs no longer break each other. The cost is old fixture branches piling up, which an occasional cleanup handles. Happy for this to be a follow-up.

@joshuafernandes joshuafernandes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment @rekmarks-consensys-1 but good to merge

rekmarks-consensys-1 and others added 2 commits November 24, 2026 17:36
…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>
@rekmarks-consensys-1

Copy link
Copy Markdown
Contributor Author

@joshuafernandes Addressed finding 1 and deferred 2 to #35. Needs reapproval.

@joshuafernandes joshuafernandes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rekmarks-consensys-1
rekmarks-consensys-1 merged commit 88f798f into main Nov 25, 2026
82 checks passed
@rekmarks-consensys-1
rekmarks-consensys-1 deleted the ocap/node-checkout-and-setup branch November 25, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants