Skip to content

Commit b18711d

Browse files
committed
Add CI job to check if updateBinary downloads the correct release
Co-authored-by: Kamil Śliwak <[email protected]>
1 parent fe75220 commit b18711d

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

.circleci/config.yml

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ workflows:
1414
- truffle-sample-project
1515
- cli-smoke-test
1616
- solidity-solcjs-ext-test
17+
- update-binary-test
1718

1819
version: 2.1
1920

@@ -353,6 +354,24 @@ jobs:
353354
- run: cd solidity/ && curl "https://binaries.soliditylang.org/bin/soljson-nightly.js" --location --output soljson.js
354355
- run: cd solidity/ && test/externalTests/solc-js/solc-js.sh "$(realpath soljson.js)" "$(scripts/get_version.sh)" "$(realpath ../solc-js/)"
355356

357+
update-binary-test:
358+
docker:
359+
- image: cimg/node:current
360+
steps:
361+
- show-npm-version
362+
- checkout:
363+
path: solc-js
364+
- install-dependencies:
365+
cache-id: solc-js
366+
path: solc-js
367+
- run:
368+
name: Verify that `npm run updateBinary` downloads the latest release
369+
command: |
370+
cd solc-js
371+
npm run updateBinary
372+
npm run build
373+
scripts/is-binary-up-to-date.sh
374+
356375
node-v10:
357376
<<: *node-base
358377
docker:

scripts/is-binary-up-to-date.sh

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
BASE_URL="https://binaries.soliditylang.org/bin"
6+
REPO_ROOT="$(dirname "$0")/.."
7+
LIST_FILE=$(mktemp -t solc-bin-list-XXXXXX.json)
8+
9+
function fail() {
10+
echo -e "ERROR: $*" >&2
11+
exit 1
12+
}
13+
14+
function check_release_version() {
15+
local current_version="$1"
16+
17+
curl --silent --fail "${BASE_URL}/list.json" -o "$LIST_FILE"
18+
[[ ! -f $LIST_FILE ]] && fail "Download of release list failed:\n [url]: ${BASE_URL}/list.json"
19+
20+
# Retrieve the latest released version
21+
latest_version_short=$(jq --raw-output ".latestRelease" "$LIST_FILE")
22+
latest_version_long=$(jq --raw-output ".releases | .[\"${latest_version_short}\"]" "$LIST_FILE" | sed --regexp-extended --quiet 's/^soljson-v(.*).js$/\1/p')
23+
24+
# Check if current version is the latest release
25+
if [[ $current_version != "$latest_version_long" ]]; then
26+
fail "Version is not the latest release:\n [current]: ${current_version}\n [latest]: ${latest_version_short}"
27+
fi
28+
29+
current_sha=$(shasum --binary --algorithm 256 ./soljson.js | awk '{ print $1 }')
30+
release_sha=$(jq --raw-output ".builds[] | select(.longVersion == \"${latest_version_long}\") | .sha256" "$LIST_FILE" | sed 's/^0x//')
31+
32+
# Check if sha matches
33+
if [[ $current_sha != "$release_sha" ]]; then
34+
fail "Checksum mismatch.\n [current]: ${current_sha}\n [release]: ${release_sha}"
35+
fi
36+
}
37+
38+
(
39+
cd "$REPO_ROOT"
40+
41+
current_version=$(node ./dist/solc.js --version | sed --regexp-extended --quiet 's/^(.*).Emscripten.*/\1/p')
42+
43+
# Verify if current version matches the package version.
44+
# It already exits with an error if the version mismatch
45+
node ./dist/verifyVersion.js
46+
47+
# Verify if current version is the latest release
48+
if check_release_version "$current_version"; then
49+
echo "The currently installed soljson.js binary (${current_version}) matches the latest release available in solc-bin."
50+
fi
51+
52+
# Cleanup temp files
53+
rm -f "$LIST_FILE"
54+
)

0 commit comments

Comments
 (0)