diff --git a/.circleci/config.yml b/.circleci/config.yml index f6450c2b..7bd7aaa3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,14 +8,19 @@ workflows: pr-checks: jobs: - check-coding-style - - node-v10 - node-v12 + - node-v12: + name: node-v12-min-dependencies + min_dependencies: true - node-v14 - node-v16 - node-v18 - node-v20 - node-current: run_coveralls: true + - node-current: + name: node-current-min-dependencies + min_dependencies: true - build-package - hardhat-sample-project: *requires_package - cli-smoke-test: *requires_package @@ -168,10 +173,31 @@ jobs: run_coveralls: type: boolean default: false + min_dependencies: + description: "Install the oldest dependencies still matching ranges specified in package.json" + type: boolean + default: false steps: # We want the default npm here. Older one might not work with older node.js - show-npm-version - checkout + - when: + condition: <> + steps: + - run: + name: Install the semver utility + command: | + # NOTE: Newer cimg/node images require sudo here, older don't. Try both. + sudo npm install semver --global || npm install semver --global + - run: + name: Force oldest supported dependency versions in package.json + command: | + min_package_json=$(.circleci/package-json-with-min-dependencies.sh) + echo "$min_package_json" > package.json + - run: + name: "Show selected dependency versions" + command: | + jq 'with_entries(select(.key == "dependencies" or .key == "devDependencies"))' package.json --indent 4 - install-dependencies: cache-id: solc-js - run: @@ -345,10 +371,6 @@ 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/)" - node-v10: - <<: *node-base - docker: - - image: cimg/node:10.24 node-v12: <<: *node-base docker: diff --git a/.circleci/package-json-with-min-dependencies.sh b/.circleci/package-json-with-min-dependencies.sh new file mode 100755 index 00000000..7fd959dd --- /dev/null +++ b/.circleci/package-json-with-min-dependencies.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# Creates a variant of package.json, hard-coded to use the oldest version of each dependency in +# the supported range. +# +# package.json is taken from the current working directory. The script does not modify the file - +# the new version is instead printed to the standard output. +# +# Dependencies: npm, jq, semver + +set -euo pipefail + +function fail { >&2 echo "$@"; exit 1; } + +function find_min_supported_versions { + local packages_json min_versions packages supported_range available_versions min_version + + # The function expects a JSON dict with package names and versions, extracted from package.json by the caller. + packages_json=$(cat -) + + # Use @tsv filter to get tab-separated package names. We assume that neither packages, nor + # available versions contain spaces. Spaces in version range are fine though. + packages=$(echo "$packages_json" | jq --raw-output 'keys | @tsv') + min_versions=() + for package in $packages; do + available_versions=$(npm view "$package" versions --json | jq --raw-output @tsv) + supported_range=$(echo "$packages_json" | jq --raw-output ".\"${package}\"") + + # shellcheck disable=SC2086 + # semver prints versions matching the range, one per line, in semver order, oldest first + min_version=$(semver $available_versions --range "$supported_range" | head --lines 1) + [[ $min_version != "" ]] || fail "No version matching ${supported_range} found for package ${package}." + + # Debug info. It goes to stderr not to interfere with actual output. + >&2 echo "Package ${package}:" + >&2 echo " minimum version: ${min_version}" + >&2 echo " supported range: ${supported_range}" + >&2 echo " available versions: ${available_versions}" + >&2 echo + + min_versions+=("{\"${package}\": \"${min_version}\"}") + done + + # Actual output: min_versions merged into a single dict. + echo "${min_versions[@]}" | jq --slurp add +} + +dependencies=$(jq .dependencies package.json | find_min_supported_versions) +dev_dependencies=$(jq .devDependencies package.json | find_min_supported_versions) + +# Print package.json with overwritten dependency versions +cat <