From 1283652572558e1cb34c37ae29a224c49805cc81 Mon Sep 17 00:00:00 2001 From: "Rodrigo Q. Saramago" Date: Sat, 17 Sep 2022 15:38:32 +0200 Subject: [PATCH] Add CI job to check if updateBinary downloads the correct release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kamil ƚliwak --- .circleci/config.yml | 19 ++++++++++++ scripts/is-binary-up-to-date.sh | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100755 scripts/is-binary-up-to-date.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index a5265445..76f66d5d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,6 +15,7 @@ workflows: - truffle-sample-project - cli-smoke-test - solidity-solcjs-ext-test + - update-binary-test version: 2.1 @@ -375,6 +376,24 @@ jobs: - run: cd solidity/ && curl "https://binaries.soliditylang.org/bin/soljson-nightly.js" --location --output soljson.js - run: cd solidity/ && test/externalTests/solc-js/solc-js.sh "$(realpath soljson.js)" "$(scripts/get_version.sh)" "$(realpath ../solc-js/)" + update-binary-test: + docker: + - image: cimg/node:current + steps: + - show-npm-version + - checkout: + path: solc-js + - install-dependencies: + cache-id: solc-js + path: solc-js + - run: + name: Verify that `npm run updateBinary` downloads the latest release + command: | + cd solc-js + npm run updateBinary + npm run build + scripts/is-binary-up-to-date.sh + node-v10: <<: *node-base docker: diff --git a/scripts/is-binary-up-to-date.sh b/scripts/is-binary-up-to-date.sh new file mode 100755 index 00000000..164c2a45 --- /dev/null +++ b/scripts/is-binary-up-to-date.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -euo pipefail + +BASE_URL="https://binaries.soliditylang.org/bin" +REPO_ROOT="$(dirname "$0")/.." +LIST_FILE=$(mktemp -t solc-bin-list-XXXXXX.json) + +function fail() { + echo -e "ERROR: $*" >&2 + exit 1 +} + +function check_release_version() { + local current_version="$1" + + curl --silent --fail "${BASE_URL}/list.json" -o "$LIST_FILE" + [[ ! -f $LIST_FILE ]] && fail "Download of release list failed:\n [url]: ${BASE_URL}/list.json" + + # Retrieve the latest released version + latest_version_short=$(jq --raw-output ".latestRelease" "$LIST_FILE") + latest_release_path=$(jq --raw-output ".releases | .[\"${latest_version_short}\"]" "$LIST_FILE") + + # Check if current version is the latest release + if [[ "soljson-v${current_version}.js" != "$latest_release_path" ]]; then + fail "Version is not the latest release:\n [current]: ${current_version}\n [latest]: ${latest_version_short}" + fi + + current_sha=$(shasum --binary --algorithm 256 ./soljson.js | awk '{ print $1 }') + release_sha=$(jq --raw-output ".builds[] | select(.path == \"${latest_release_path}\") | .sha256" "$LIST_FILE" | sed 's/^0x//') + + # Check if sha matches + if [[ $current_sha != "$release_sha" ]]; then + fail "Checksum mismatch.\n [current]: ${current_sha}\n [release]: ${release_sha}" + fi +} + +( + cd "$REPO_ROOT" + + current_version=$(node ./dist/solc.js --version | sed --regexp-extended --quiet 's/^(.*).Emscripten.*/\1/p') + + # Verify if current version matches the package version. + # It already exits with an error if the version mismatch + node ./dist/verifyVersion.js + + # Verify if current version is the latest release + if check_release_version "$current_version"; then + echo "The currently installed soljson.js binary (${current_version}) matches the latest release available in solc-bin." + fi + + # Cleanup temp files + rm -f "$LIST_FILE" +)