Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: properly handle subdependencies for Endo branch override #7958

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/actions/restore-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ inputs:
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:
Expand Down Expand Up @@ -98,14 +103,18 @@ runs:
sudo apt-get update
sudo apt-get install libbsd-dev
fi
yarn install
# Replace the Endo packages with the ones built from the checked-out branch.
if test -e ~/endo; then
scripts/replace-packages.sh ~/endo
rm -rf ~/endo
scripts/get-packed-versions.sh ~/endo | scripts/resolve-versions.sh
fi
yarn install
mkdir -p node_modules/.cache/agoric
date > node_modules/.cache/agoric/yarn-installed
if test -e ~/endo; then
# Remove traces of the redirected `yarn install`.
git restore package.json yarn.lock
rm -rf ~/endo
fi
shell: bash
if: steps.built.outputs.cache-hit != 'true'
- name: yarn build
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ jobs:
- uses: ./.github/actions/restore-node
with:
node-version: ${{ steps.vars.outputs.node-version }}
id: restore-node
- run: echo "ENDO_BRANCH=${{ steps.restore-node.outputs.endo-branch }}" >> $GITHUB_ENV
# END-TEST-BOILERPLATE
- name: yarn test (SwingSet)
if: (success() || failure())
Expand Down Expand Up @@ -504,6 +506,8 @@ jobs:
- uses: ./.github/actions/restore-node
with:
node-version: ${{ steps.vars.outputs.node-version }}
id: restore-node
- run: echo "ENDO_BRANCH=${{ steps.restore-node.outputs.endo-branch }}" >> $GITHUB_ENV
# END-TEST-BOILERPLATE
- name: yarn test (SwingSet)
if: (success() || failure())
Expand Down Expand Up @@ -553,6 +557,8 @@ jobs:
- uses: ./.github/actions/restore-node
with:
node-version: ${{ steps.vars.outputs.node-version }}
id: restore-node
- run: echo "ENDO_BRANCH=${{ steps.restore-node.outputs.endo-branch }}" >> $GITHUB_ENV
# END-TEST-BOILERPLATE
- name: yarn test (SwingSet)
if: (success() || failure())
Expand Down Expand Up @@ -592,6 +598,8 @@ jobs:
- uses: ./.github/actions/restore-node
with:
node-version: ${{ steps.vars.outputs.node-version }}
id: restore-node
- run: echo "ENDO_BRANCH=${{ steps.restore-node.outputs.endo-branch }}" >> $GITHUB_ENV
# END-TEST-BOILERPLATE

- name: yarn test (SwingSet)
Expand Down
8 changes: 8 additions & 0 deletions packages/SwingSet/test/test-xsnap-store.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global globalThis */
import '@endo/init/debug.js';

import { spawn } from 'child_process';
Expand Down Expand Up @@ -130,6 +131,13 @@ test('create SES worker, save, restore, resume', async t => {
* They are also sensitive to the XS code itself.
*/
test('XS + SES snapshots are long-term deterministic', async t => {
const ENDO_BRANCH = globalThis.process?.env?.ENDO_BRANCH;
if (ENDO_BRANCH && ENDO_BRANCH !== 'NOPE') {
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if instead we shouldn't run a yarn test --update-snapshots (and ignore the clobbered snapshot artifacts in the porcelain check)

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't want to make an assumption that this is the only SwingSet test using t.snapshot. This approach seems less brittle.

Copy link
Member

Choose a reason for hiding this comment

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

The way I see it, when we add a test that breaks under these endo changes, either we update the test, or we update the CI job to handle the test. The main problem is if there are golden test impacted by endo changes that do not use snapshots.

The CI config here could simply add --update-snapshot to all yarn test invocations if we're not worried about other snapshot based tests diverging in more significant ways.

t.log(`Skipping test on ENDO_BRANCH=${ENDO_BRANCH}`);
t.pass();
return;
}

const db = sqlite3(':memory:');
const store = makeSnapStore(db, () => {}, makeMockSnapStoreIO());

Expand Down
39 changes: 39 additions & 0 deletions scripts/get-packed-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /bin/bash
# Usage: get-packed-versions.sh <WORKDIR>
#
# This script creates package tarballs in the specified workspace directory and
# writes out information for resolve-versions.sh to update a destination
# workspace to use them. This is useful for testing changes to dependencies of
# the destination repository.
set -xueo pipefail

WORKDIR=${1:-.}
cd -- "$WORKDIR" 1>&2

# Install and build the source directory.
yarn install 1>&2
yarn build 1>&2
yarn --silent workspaces info | jq -r '.[].location' | while read -r dir; do
# Skip private packages.
echo "dir=$dir" 1>&2
test "$(jq .private < "$dir/package.json")" != true || continue

##################
pushd "$dir" 1>&2

# Gather the metadata.
name=$(jq -r .name < package.json)
version=$(jq -r .version < package.json)
stem=$(echo "$name" | sed -e 's!^@!!; s!/!-!g;')
file="$(pwd)/${stem}-v${version}.tgz"

# Create the tarball.
yarn pack 1>&2

# Write out the version entry.
jq -s --arg name "$name" --arg file "$file" \
'{ key: $name, value: ("file:" + $file) }' < /dev/null

popd 1>&2
##################
done | jq -s from_entries
19 changes: 19 additions & 0 deletions scripts/resolve-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -ueo pipefail

# Accepts a dependency version map on stdin and updates the current
# package.json's resolutions section to use the packages and versions from
# the map.
# This is useful for temporary bulk updates over all packages.

DIR=$(dirname -- "${BASH_SOURCE[0]}")

cd -- "$DIR/.."

override=$(jq 'to_entries | map({ key: ("**/" + .key), value: .value }) | from_entries')

PACKAGEJSONHASH=$(
jq --arg override "$override" '.resolutions *= ($override | fromjson)' package.json |
git hash-object -w --stdin
Copy link
Member

Choose a reason for hiding this comment

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

Interesting hack

Copy link
Member

Choose a reason for hiding this comment

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

I love this hack. It’s the best hack ever.

)
git cat-file blob "$PACKAGEJSONHASH" > package.json