Skip to content

Commit

Permalink
Add CI job to check if updateBinary downloads the correct release
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Śliwak <[email protected]>
  • Loading branch information
r0qs and cameel committed Mar 20, 2023
1 parent c572d36 commit 1283652
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ workflows:
- truffle-sample-project
- cli-smoke-test
- solidity-solcjs-ext-test
- update-binary-test

version: 2.1

Expand Down Expand Up @@ -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:
Expand Down
54 changes: 54 additions & 0 deletions scripts/is-binary-up-to-date.sh
Original file line number Diff line number Diff line change
@@ -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"
)

0 comments on commit 1283652

Please sign in to comment.