name: Agoric SDK restore Node.js build description: 'Set up Node.js environment and restore cached built files' inputs: node-version: description: 'The version or semantic name (node-old, node-new and xs supported) of Node.js to use' required: true path: description: 'The relative path to the agoric-sdk directory' required: false default: '.' ref: default: '' description: 'Ref of this repository to check out and build (default: the commit that triggered the workflow)' required: false keep-endo: description: 'Keep Endo repository after installing from it' required: false default: 'false' ignore-endo-branch: description: 'Ignore external Endo branch configuration' required: false default: 'false' xsnap-random-init: description: Build xsnap binary with random memory init required: false default: '0' outputs: endo-branch: description: 'The branch of Endo used (NOPE if no override)' value: ${{ steps.endo-branch.outputs.result }} runs: using: composite steps: - id: set-node-version name: Set correct node version shell: bash env: VERSION_IDENTIFIER: ${{ inputs.node-version }} run: | set -o xtrace # By default, treat the version identifier as a semantic version. OUTPUT_NODE_VERSION="$VERSION_IDENTIFIER" case $VERSION_IDENTIFIER in node-old | xs) OUTPUT_NODE_VERSION="22" ;; node-new) OUTPUT_NODE_VERSION="24" ;; esac echo "NODE_VERSION=$OUTPUT_NODE_VERSION" >> "$GITHUB_OUTPUT" - id: checkout uses: actions/checkout@v5 with: clean: false path: ${{ inputs.path }} persist-credentials: false ref: ${{ inputs.ref }} # Select an Endo target against which to test, defaulting to 'NOPE' for use # of internally-referenced NPM packages but allowing overrides in the pull # request description for referencing a branch of the # [endo repository](https://github.com/endojs/endo) using lines like # `#endo-branch: rank-strings-by-codepoint` - name: Get the appropriate Endo branch id: endo-branch uses: actions/github-script@v8 with: result-encoding: string script: |- let branch = 'NOPE'; if (${{ inputs.ignore-endo-branch }}) { // Skip any override directive. } else if (context.eventName === 'schedule') { branch = 'master'; } else if (context.payload.pull_request) { const { body } = context.payload.pull_request; const regex = /^\#endo-branch:\s+(\S+)/m; const result = regex.exec(body); if (result) { branch = result[1]; } } console.log('Endo override branch: ' + branch); return branch; - name: merge endo integration branch id: endo-integration-merge if: steps.endo-branch.outputs.result != 'NOPE' working-directory: ${{ inputs.path }} shell: bash run: |- set -e git ls-remote --exit-code --heads origin "refs/heads/integration-endo-${{ steps.endo-branch.outputs.result }}" || exit 0 git fetch --unshallow origin integration-endo-${{ steps.endo-branch.outputs.result }} git config user.name github-actions git config user.email github-actions@github.com git merge --commit --no-edit origin/integration-endo-${{ steps.endo-branch.outputs.result }} - name: check out Endo if necessary id: endo-checkout if: steps.endo-branch.outputs.result != 'NOPE' uses: actions/checkout@v5 with: repository: endojs/endo path: ./replacement-endo ref: ${{ steps.endo-branch.outputs.result }} clean: 'false' submodules: 'true' persist-credentials: false - name: Move Endo checkout outside the working directory id: endo-sha shell: bash run: |- set -ex if test -e ./replacement-endo; then mv ./replacement-endo ~/endo sha=$(cd ~/endo && git rev-parse HEAD) else sha=NOPE fi echo "sha=$sha" >> $GITHUB_OUTPUT cd "${{ inputs.path }}" echo "$sha" > endo-sha.txt - name: Reconfigure git to use HTTP authentication shell: bash run: git config --global url."https://github.com/".insteadOf ssh://git@github.com/ # Set up for Corepack before trying to cache yarn. See # https://github.com/actions/setup-node/issues/899#issuecomment-1828798029. - uses: actions/setup-node@v5 with: node-version: ${{ steps.set-node-version.outputs.NODE_VERSION }} # Corepack is not enabled yet, so setup-node must not try to detect # the yarn cache on this first pass. package-manager-cache: false # Before setup-node because that action tries to discover the cache directory. # See https://github.com/actions/setup-node/issues/480#issuecomment-1915448139 - shell: bash run: | set -ex "${{ inputs.path }}/scripts/ensure-corepack-yarn.sh" "${{ inputs.path }}" mkdir -p "$(yarn config get cacheFolder)" - uses: actions/setup-node@v5 with: node-version: ${{ steps.set-node-version.outputs.NODE_VERSION }} cache: yarn cache-dependency-path: | ${{ inputs.path }}/yarn.lock ${{ inputs.path }}/a3p-integration/yarn.lock ${{ inputs.path }}/a3p-integration/proposals/*/yarn.lock ${{ inputs.path }}/multichain-testing/yarn.lock ${{ inputs.path }}/endo-sha.txt - uses: kenchan0130/actions-system-info@master id: system-info - name: restore built files id: built uses: actions/cache@v5 with: path: ${{ inputs.path }} key: ${{ runner.os }}-${{ runner.arch }}-${{ steps.system-info.outputs.release }}-node-${{ steps.set-node-version.outputs.NODE_VERSION }}-built-${{ inputs.xsnap-random-init }}-${{ steps.checkout.outputs.commit }}-${{ steps.endo-sha.outputs.sha }} # This and the git diff below are to detect if `yarn install` results in a # change to the lock file. - name: yarn install if: steps.built.outputs.cache-hit != 'true' working-directory: ${{ inputs.path }} shell: bash run: |- set -ex if test "${{ inputs.xsnap-random-init }}" != 0 && test -d /etc/apt; then # Need libbsd-dev, as it's referenced in xsnapPlatform.h sudo apt-get update sudo apt-get install libbsd-dev fi # Preserve the original package.json to restore it after Endo replacements. cp -a package.json package.json.orig # Replace the Endo packages with the ones built from the checked-out branch. if test -e ~/endo; then scripts/get-packed-versions.sh ~/endo | scripts/resolve-versions.sh fi yarn install # In the event that the package.json has been modified by Endo # replacements, we need to have a yarn-installed timestamp that # corresponds to the unmodified package.json. As long as we don't # explicitly `yarn install` anywhere other than in this action and in # the bin/agd script, we should be able to reuse even Endo-overridden # built caches successfully. mv package.json.orig package.json if test -e ~/endo; then # Stage the redirected `yarn install` consequences. git add package.json yarn.lock ${{ inputs.keep-endo }} || rm -rf ~/endo fi - name: yarn build if: steps.built.outputs.cache-hit != 'true' working-directory: ${{ inputs.path }} env: XSNAP_RANDOM_INIT: ${{ inputs.xsnap-random-init }} shell: bash run: |- set -ex yarn build mkdir -p node_modules/.cache/agoric date > node_modules/.cache/agoric/yarn-built - name: Validate Git Tree Cleanliness uses: pyTooling/Actions/with-post-step@v7.11.1 with: main: | bash -x "$SRC/.github/actions/restore-node/check-git-status.sh" "$SRC" "$IGNORE_DIRTY_YARN_LOCK" post: | bash -x "$SRC/.github/actions/restore-node/check-git-status.sh" "$SRC" "$IGNORE_DIRTY_YARN_LOCK" env: SRC: ${{ inputs.path }} IGNORE_DIRTY_YARN_LOCK: ${{ steps.endo-branch.outputs.result != 'NOPE' }}