Skip to content

Commit 23ca117

Browse files
test(solidity): time-limit and log each deploy consumer step
A hung command made the CI job hit its timeout, and a cancelled job loses its log. Give every external command a time limit and print the duration of each step, so a hang fails the job with output.
1 parent 93b2785 commit 23ca117

1 file changed

Lines changed: 40 additions & 7 deletions

File tree

‎solidity/deploy-consumer/prepare.js‎

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@ const os = require("os")
55
const path = require("path")
66
const { execFileSync } = require("child_process")
77

8+
// Every external command gets a time limit. A hung command must fail the job
9+
// with its output, not be cancelled by the workflow timeout, which loses the log.
10+
const MINUTE = 60 * 1000
11+
const exec = (label, minutes, command, args, options = {}) => {
12+
console.log(`[prepare] ${label}`)
13+
const started = Date.now()
14+
try {
15+
return execFileSync(command, args, {
16+
timeout: minutes * MINUTE,
17+
killSignal: "SIGKILL",
18+
...options,
19+
})
20+
} catch (error) {
21+
if (error.code === "ETIMEDOUT") {
22+
throw new Error(`${label} exceeded ${minutes} minutes`)
23+
}
24+
throw error
25+
} finally {
26+
console.log(`[prepare] ${label} took ${(Date.now() - started) / 1000}s`)
27+
}
28+
}
29+
830
const major = process.argv[2]
931
if (!["5", "6"].includes(major))
1032
throw new Error("Usage: node prepare.js 5|6 [directory]")
@@ -62,7 +84,9 @@ const dependencies = {
6284
}
6385
for (const name of ["random-beacon", "ecdsa"]) {
6486
const output = JSON.parse(
65-
execFileSync(
87+
exec(
88+
`npm pack ${name}`,
89+
3,
6690
"npm",
6791
["pack", "--ignore-scripts", "--json", "--pack-destination", directory],
6892
{
@@ -94,21 +118,30 @@ fs.writeFileSync(
94118
// Both hardhat-deploy lines use their own ethers v5. Helpers 0.7's peer range
95119
// predates hardhat-deploy 1.0.4, so --legacy-peer-deps is required; the v6 lane
96120
// deliberately tests that consumer combination.
97-
execFileSync(
121+
exec(
122+
"npm install",
123+
10,
98124
"npm",
99125
[
100126
"install",
101127
"--ignore-scripts",
102128
"--legacy-peer-deps",
103129
"--no-audit",
104130
"--no-fund",
131+
"--loglevel=http",
105132
],
106133
{ cwd: directory, stdio: "inherit", env: environment }
107134
)
108135
for (const file of ["smoke.js", "edge.js"]) {
109-
execFileSync("npx", ["--no-install", "hardhat", "run", file], {
110-
cwd: directory,
111-
stdio: "inherit",
112-
env: environment,
113-
})
136+
exec(
137+
`hardhat run ${file}`,
138+
12,
139+
"npx",
140+
["--no-install", "hardhat", "run", file],
141+
{
142+
cwd: directory,
143+
stdio: "inherit",
144+
env: environment,
145+
}
146+
)
114147
}

0 commit comments

Comments
 (0)