From b58f3bbe80b94fb878a69d16a5d856d7c751014e Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Mon, 5 Feb 2024 18:26:41 -0600 Subject: [PATCH] fixup! build(agd): rely on checksums, not timestamps --- .github/actions/restore-node/action.yml | 29 +++++++++++++++---------- bin/agd | 24 ++++++++++++-------- scripts/smoketest-binaries.sh | 2 +- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/.github/actions/restore-node/action.yml b/.github/actions/restore-node/action.yml index effedbbc0f58..a1e17d50f60d 100644 --- a/.github/actions/restore-node/action.yml +++ b/.github/actions/restore-node/action.yml @@ -129,21 +129,28 @@ runs: if test -e ~/endo; then scripts/get-packed-versions.sh ~/endo | scripts/resolve-versions.sh fi - cp package.json package.json.orig yarn install - if cmp -s package.json.orig package.json; then - # We need to generate a yarn-installed.sum that matches 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. + if ! cmp -s <(git cat-file blob HEAD:package.json) package.json; then + # In the event that the package.json has been modified by Endo + # replacements, We need to generate a yarn-installed.sum that matches + # 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. git checkout HEAD -- package.json fi - rm package.json.orig - function findsha1() { - find ${1+"$@"} -print0 | xargs -0 sha1sum | sort +1 || true + function diffsha1() { + stamp=$1 + shift + find ${1+"$@"} -exec sha1sum {} \; | sort +1 > "$stamp.new" || true + if test ! -s "$stamp.new" -a ! -e "$stamp"; then + echo "No dependencies found for $stamp" 1>&2 + return 0 + fi + diff -u "$stamp" "$stamp.new" || return 1 + return 0 } # Find the current list of package.jsons. @@ -154,7 +161,7 @@ runs: sed -ne '/"location":/{ s/.*": "//; s!",.*!/package.json!; p; }') mkdir -p node_modules/.cache/agoric - findsha1 "${files[@]}" > node_modules/.cache/agoric/yarn-installed.sum + diffsha1 node_modules/.cache/agoric/yarn-installed.sum "${files[@]}" if test -e ~/endo; then # Stage the redirected `yarn install` consequences. diff --git a/bin/agd b/bin/agd index 35e412a79b3d..f111f7adde32 100755 --- a/bin/agd +++ b/bin/agd @@ -19,8 +19,16 @@ function fatal() { exit 1 } -function findsha1() { - find ${1+"$@"} -print0 | xargs -0 sha1sum | sort +1 || true +function diffsha1() { + stamp=$1 + shift + find ${1+"$@"} -exec sha1sum {} \; | sort +1 > "$stamp.new" || true + if test ! -s "$stamp.new" -a ! -e "$stamp"; then + echo "No dependencies found for $stamp" 1>&2 + return 0 + fi + diff -u "$stamp" "$stamp.new" || return 1 + return 0 } GVM_URL=${GVM_URL-https://github.com/devnw/gvm/releases/download/latest/gvm} @@ -34,7 +42,9 @@ thisdir=$(cd "$(dirname -- "$real0")" >/dev/null && pwd -P) # shellcheck disable=SC1091 source "$thisdir/../repoconfig.sh" +NO_BUILD=${NO_BUILD-false} if test "${1-''}" = build; then + NO_BUILD=false BUILD_ONLY=true # Enable shell debugging. set -x @@ -124,9 +134,7 @@ fi done < <(lazy_yarn -s workspaces info | sed -ne '/"location":/{ s/.*": "//; s!",.*!/package.json!; p; }') - findsha1 "${files[@]}" > "$sum.new" || true - diff -u "$sum" "$sum.new" || { - echo "$sum has changed" + diffsha1 "$sum" "${files[@]}" || { echo "$sum has changed"; $NO_BUILD; } || { rm -f "$sum" "$STAMPS/yarn-built" lazy_yarn install mv "$sum.new" "$sum" @@ -142,12 +150,10 @@ fi fi sum=$STAMPS/golang-built.sum - findsha1 "$GOLANG_DIR" \( \ + diffsha1 "$sum" "$GOLANG_DIR" \( \ ! -name '*_test.go' -name '*.go' \ -o -name '*.cc' \ - -o -name 'go.*' \) > "$sum.new" || true - diff -u "$sum" "$sum.new" || { - echo "$GOLANG_DIR $sum has changed" + -o -name 'go.*' \) || { echo "$GOLANG_DIR $sum has changed"; $NO_BUILD; } || { rm -f "$sum" ( # Run this build in another subshell in case we had to modify the path. diff --git a/scripts/smoketest-binaries.sh b/scripts/smoketest-binaries.sh index 126b7a60c256..3b866e382938 100755 --- a/scripts/smoketest-binaries.sh +++ b/scripts/smoketest-binaries.sh @@ -4,7 +4,7 @@ binaries=( "agd version" "agoric -V" "ag-chain-cosmos version" ) for binary in "${binaries[@]}"; do - echo "Checking $binary a" + echo "Checking $binary" $binary ec=$? if [[ $ec -ne 0 ]]; then