Skip to content

Commit 3c2ed50

Browse files
authored
Merge pull request #625 from ethereum/fix-solcjs-injection-in-ci
Fix solc-js injection in CI
2 parents 4377232 + 5636d58 commit 3c2ed50

File tree

1 file changed

+80
-23
lines changed

1 file changed

+80
-23
lines changed

.circleci/config.yml

Lines changed: 80 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ workflows:
1212
- hardhat-core-latest-solc
1313
- hardhat-sample-project
1414
- truffle-sample-project
15+
- cli-smoke-test
1516

1617
version: 2.1
1718

@@ -22,6 +23,13 @@ commands:
2223
name: Versions
2324
command: npm version
2425

26+
update-npm:
27+
steps:
28+
- run:
29+
name: Update globally available npm to the latest version
30+
# Note: We need npm >= 8.3 which supports 'overrides' in package.json
31+
command: sudo npm install npm --global
32+
2533
install-dependencies:
2634
parameters:
2735
cache-id:
@@ -76,20 +84,34 @@ commands:
7684
tarball-path:
7785
type: string
7886
default: solc-js.tgz
79-
install-command:
80-
type: string
81-
default: npm install
87+
package-manager:
88+
type: enum
89+
enum: ["npm", "yarn"]
90+
default: npm
8291
steps:
8392
- run:
84-
name: Inject solc-js from the tarball into dependencies at <<parameters.path>>
93+
name: "Sanity check: tarball exists and the target dir contains a JS project"
8594
command: |
8695
[[ -f "<<parameters.tarball-path>>" ]]
96+
[[ -f "<<parameters.path>>/package.json" ]]
97+
- run:
98+
name: Inject solc-js from the tarball into dependencies at <<parameters.path>>
99+
command: |
87100
absolute_tarball_path=$(realpath "<<parameters.tarball-path>>")
88-
for solc_module in $(find "<<parameters.path>>" -type d -path "*/node_modules/solc"); do
89-
pushd "${solc_module}/../.."
90-
<<parameters.install-command>> "$absolute_tarball_path" --ignore-workspace-root-check
91-
popd
92-
done
101+
cd "<<parameters.path>>"
102+
mv package.json original-package.json
103+
# NOTE: The 'overrides' feature requires npm >= 8.3. Yarn requires `resolutions` instead.
104+
jq ". + {overrides: {solc: \"${absolute_tarball_path}\"}} + {resolutions: {solc: \"${absolute_tarball_path}\"}}" original-package.json > package.json
105+
"<<parameters.package-manager>>" install
106+
- run:
107+
name: "Sanity check: all transitive dependencies successfully replaced with the tarball"
108+
command: |
109+
solc_version=$(jq --raw-output .version solc-js/package.json)
110+
cd "<<parameters.path>>"
111+
if "<<parameters.package-manager>>" list --pattern solc | grep 'solc@' | grep -v "solc@${solc_version}"; then
112+
echo "Another version of solc-js is still present in the dependency tree."
113+
exit 1
114+
fi
93115
94116
provision-and-package-solcjs:
95117
description: "Creates a package out of latest solc-js to test its installation as a dependency."
@@ -117,26 +139,16 @@ commands:
117139
dependency-file: yarn.lock
118140
- inject-solc-js-tarball:
119141
path: hardhat/
120-
install-command: yarn add
142+
package-manager: yarn
121143

122144
provision-truffle-with-packaged-solcjs:
123145
description: "Clones Truffle repository and configures it to use a local clone of solc-js."
124146
steps:
125147
- run: git clone --depth 1 "https://github.com/trufflesuite/truffle" truffle/
126148
- install-truffle-dependencies
127149
- inject-solc-js-tarball:
128-
path: truffle/node_modules/
129-
install-command: yarn add
130-
- run:
131-
name: Neutralize any copies of solc-js outside of node_modules/
132-
command: |
133-
# NOTE: Injecting solc-js into node_modules/ dirs located under truffle/packages/ causes
134-
# an error 'Tarball is not in network and can not be located in cache'. These are not
135-
# supposed to be used but let's remove them just in case.
136-
find truffle/ \
137-
-path "*/solc/wrapper.js" \
138-
-not -path "truffle/node_modules/*" \
139-
-printf "%h\n" | xargs --verbose rm -r
150+
path: truffle/
151+
package-manager: yarn
140152

141153
jobs:
142154
node-base: &node-base
@@ -148,6 +160,7 @@ jobs:
148160
type: boolean
149161
default: false
150162
steps:
163+
# We want the default npm here. Older one might not work with older node.js
151164
- show-npm-version
152165
- checkout
153166
- install-dependencies:
@@ -172,11 +185,23 @@ jobs:
172185
docker:
173186
- image: circleci/node:16
174187
steps:
188+
- update-npm
175189
- show-npm-version
176190
- provision-and-package-solcjs
177191
- provision-hardhat-with-packaged-solcjs
178192
- run:
179-
name: Run hardhat-core test suite with its default solc
193+
name: Restore the default solc binary expected by Hardhat
194+
command: |
195+
# Hardhat downloader tests are hard-coded to expect the version that comes with the solc-js.
196+
# We forced latest solc-js but we still want the default binary with it.
197+
hardhat_default_solc_version=$(jq --raw-output '.dependencies.solc' hardhat/packages/hardhat-core/package.json)
198+
mkdir hardhat-default-solc/
199+
pushd hardhat-default-solc/
200+
npm install "solc@${hardhat_default_solc_version}"
201+
popd
202+
ln -sf ../../../hardhat-default-solc/node_modules/solc/soljson.js hardhat/node_modules/solc/soljson.js
203+
- run:
204+
name: Run hardhat-core test suite with its default solc binary
180205
command: |
181206
cd hardhat/packages/hardhat-core
182207
# TODO: yarn build should not be needed to run these tests. Remove it.
@@ -188,6 +213,7 @@ jobs:
188213
docker:
189214
- image: circleci/node:16
190215
steps:
216+
- update-npm
191217
- show-npm-version
192218
- provision-and-package-solcjs
193219
- provision-hardhat-with-packaged-solcjs
@@ -205,6 +231,7 @@ jobs:
205231
docker:
206232
- image: circleci/node:16
207233
steps:
234+
- update-npm
208235
- show-npm-version
209236
- provision-and-package-solcjs
210237
- run: git clone --depth 1 "https://github.com/nomiclabs/hardhat-hackathon-boilerplate" boilerplate/
@@ -258,6 +285,7 @@ jobs:
258285
docker:
259286
- image: circleci/node:12
260287
steps:
288+
- update-npm
261289
- show-npm-version
262290
- provision-and-package-solcjs
263291
- provision-truffle-with-packaged-solcjs
@@ -284,6 +312,35 @@ jobs:
284312
echo "module.exports['compilers'] = {solc: {version: '$(realpath node_modules/solc/)'}}" > truffle-config.js
285313
node ../truffle/node_modules/.bin/truffle test
286314
315+
cli-smoke-test:
316+
docker:
317+
- image: circleci/node:17
318+
steps:
319+
- update-npm
320+
- show-npm-version
321+
- provision-and-package-solcjs
322+
- run:
323+
name: "CLI smoke test (repository)"
324+
command: |
325+
cd solc-js
326+
dist/solc.js --version
327+
328+
echo "contract C {}" > C.sol
329+
dist/solc.js C.sol --bin
330+
[[ -f C_sol_C.bin ]]
331+
- run:
332+
name: "CLI smoke test (package)"
333+
command: |
334+
mkdir package/
335+
cd package/
336+
npm install ../solc-js.tgz
337+
338+
npx solcjs --version
339+
340+
echo "contract C {}" > C.sol
341+
npx solcjs C.sol --bin
342+
[[ -f C_sol_C.bin ]]
343+
287344
node-v10:
288345
<<: *node-base
289346
docker:

0 commit comments

Comments
 (0)