Skip to content

Commit af92370

Browse files
committed
CI: Fix solc-js injection and make it more robust
1 parent f83b049 commit af92370

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

.circleci/config.yml

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,34 @@ commands:
8383
tarball-path:
8484
type: string
8585
default: solc-js.tgz
86-
install-command:
87-
type: string
88-
default: npm install
86+
package-manager:
87+
type: enum
88+
enum: ["npm", "yarn"]
89+
default: npm
8990
steps:
9091
- run:
91-
name: Inject solc-js from the tarball into dependencies at <<parameters.path>>
92+
name: "Sanity check: tarball exists and the target dir contains a JS project"
9293
command: |
9394
[[ -f "<<parameters.tarball-path>>" ]]
95+
[[ -f "<<parameters.path>>/package.json" ]]
96+
- run:
97+
name: Inject solc-js from the tarball into dependencies at <<parameters.path>>
98+
command: |
9499
absolute_tarball_path=$(realpath "<<parameters.tarball-path>>")
95-
for solc_module in $(find "<<parameters.path>>" -type d -path "*/node_modules/solc"); do
96-
pushd "${solc_module}/../.."
97-
<<parameters.install-command>> "$absolute_tarball_path" --ignore-workspace-root-check
98-
popd
99-
done
100+
cd "<<parameters.path>>"
101+
mv package.json original-package.json
102+
# NOTE: The 'overrides' feature requires npm >= 8.3. Yarn requires `resolutions` instead.
103+
jq ". + {overrides: {solc: \"${absolute_tarball_path}\"}} + {resolutions: {solc: \"${absolute_tarball_path}\"}}" original-package.json > package.json
104+
"<<parameters.package-manager>>" install
105+
- run:
106+
name: "Sanity check: all transitive dependencies successfully replaced with the tarball"
107+
command: |
108+
solc_version=$(jq --raw-output .version solc-js/package.json)
109+
cd "<<parameters.path>>"
110+
if "<<parameters.package-manager>>" list --pattern solc | grep 'solc@' | grep -v "solc@${solc_version}"; then
111+
echo "Another version of solc-js is still present in the dependency tree."
112+
exit 1
113+
fi
100114
101115
provision-and-package-solcjs:
102116
description: "Creates a package out of latest solc-js to test its installation as a dependency."
@@ -124,26 +138,16 @@ commands:
124138
dependency-file: yarn.lock
125139
- inject-solc-js-tarball:
126140
path: hardhat/
127-
install-command: yarn add
141+
package-manager: yarn
128142

129143
provision-truffle-with-packaged-solcjs:
130144
description: "Clones Truffle repository and configures it to use a local clone of solc-js."
131145
steps:
132146
- run: git clone --depth 1 "https://github.com/trufflesuite/truffle" truffle/
133147
- install-truffle-dependencies
134148
- inject-solc-js-tarball:
135-
path: truffle/node_modules/
136-
install-command: yarn add
137-
- run:
138-
name: Neutralize any copies of solc-js outside of node_modules/
139-
command: |
140-
# NOTE: Injecting solc-js into node_modules/ dirs located under truffle/packages/ causes
141-
# an error 'Tarball is not in network and can not be located in cache'. These are not
142-
# supposed to be used but let's remove them just in case.
143-
find truffle/ \
144-
-path "*/solc/wrapper.js" \
145-
-not -path "truffle/node_modules/*" \
146-
-printf "%h\n" | xargs --verbose rm -r
149+
path: truffle/
150+
package-manager: yarn
147151

148152
jobs:
149153
node-base: &node-base
@@ -185,7 +189,18 @@ jobs:
185189
- provision-and-package-solcjs
186190
- provision-hardhat-with-packaged-solcjs
187191
- run:
188-
name: Run hardhat-core test suite with its default solc
192+
name: Restore the default solc binary expected by Hardhat
193+
command: |
194+
# Hardhat downloader tests are hard-coded to expect the version that comes with the solc-js.
195+
# We forced latest solc-js but we still want the default binary with it.
196+
hardhat_default_solc_version=$(jq --raw-output '.dependencies.solc' hardhat/packages/hardhat-core/package.json)
197+
mkdir hardhat-default-solc/
198+
pushd hardhat-default-solc/
199+
npm install "solc@${hardhat_default_solc_version}"
200+
popd
201+
ln -sf ../../../hardhat-default-solc/node_modules/solc/soljson.js hardhat/node_modules/solc/soljson.js
202+
- run:
203+
name: Run hardhat-core test suite with its default solc binary
189204
command: |
190205
cd hardhat/packages/hardhat-core
191206
# TODO: yarn build should not be needed to run these tests. Remove it.

0 commit comments

Comments
 (0)