Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test runs with minimum dependency versions #757

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines 19 to +23
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason CircleCI decided to change the name of the existing job to node-current-1. Not sure why, this does not happen with node-v12 for example. I tried adding name: node-current but it does not change this.

I guess we'll have to accept this and update the name of the required job in settings if we decide to merge the PR. I think we should make the min-dependencies jobs required as well.

- build-package
- hardhat-sample-project: *requires_package
- cli-smoke-test: *requires_package
Expand Down Expand Up @@ -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: <<parameters.min_dependencies>>
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:
Expand Down Expand Up @@ -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:
Expand Down
56 changes: 56 additions & 0 deletions .circleci/package-json-with-min-dependencies.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF | jq --slurp '.[0] * .[1]' package.json -
{
"dependencies": ${dependencies},
"devDependencies": ${dev_dependencies}
}
EOF