From 2b118846facad475542792d727fb7d04374b253d Mon Sep 17 00:00:00 2001 From: "Rodrigo Q. Saramago" Date: Sat, 17 Sep 2022 15:38:32 +0200 Subject: [PATCH] =?UTF-8?q?Add=20CI=20job=20to=20check=20if=20updateBinary?= =?UTF-8?q?=20downloads=20the=20correct=20release=20Co-authored-by:=20Kami?= =?UTF-8?q?l=20=C5=9Aliwak=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .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 7acfa445..0db416dd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,6 +14,7 @@ workflows: - truffle-sample-project - cli-smoke-test - solidity-solcjs-ext-test + - update-binary-test version: 2.1 @@ -353,6 +354,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..3a9080b2 --- /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_version_long=$(jq --raw-output ".releases | .[\"${latest_version_short}\"]" "$LIST_FILE" | sed --regexp-extended --quiet 's/^soljson-v(.*).js$/\1/p') + + # Check if current version is the latest release + if [[ "$current_version" != "$latest_version_long" ]]; 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(.longVersion == \"${latest_version_long}\") | .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" +)