Skip to content

Commit 1283652

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

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

.circleci/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ workflows:
1515
- truffle-sample-project
1616
- cli-smoke-test
1717
- solidity-solcjs-ext-test
18+
- update-binary-test
1819

1920
version: 2.1
2021

@@ -375,6 +376,24 @@ jobs:
375376
- run: cd solidity/ && curl "https://binaries.soliditylang.org/bin/soljson-nightly.js" --location --output soljson.js
376377
- run: cd solidity/ && test/externalTests/solc-js/solc-js.sh "$(realpath soljson.js)" "$(scripts/get_version.sh)" "$(realpath ../solc-js/)"
377378

379+
update-binary-test:
380+
docker:
381+
- image: cimg/node:current
382+
steps:
383+
- show-npm-version
384+
- checkout:
385+
path: solc-js
386+
- install-dependencies:
387+
cache-id: solc-js
388+
path: solc-js
389+
- run:
390+
name: Verify that `npm run updateBinary` downloads the latest release
391+
command: |
392+
cd solc-js
393+
npm run updateBinary
394+
npm run build
395+
scripts/is-binary-up-to-date.sh
396+
378397
node-v10:
379398
<<: *node-base
380399
docker:

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

Lines changed: 54 additions & 0 deletions
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_release_path=$(jq --raw-output ".releases | .[\"${latest_version_short}\"]" "$LIST_FILE")
23+
24+
# Check if current version is the latest release
25+
if [[ "soljson-v${current_version}.js" != "$latest_release_path" ]]; 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(.path == \"${latest_release_path}\") | .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)