Skip to content

Commit 41d5270

Browse files
authored
Ensure coverage data from multiple tasks don't overwrite each other (#747)
1 parent 19303f4 commit 41d5270

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ jobs:
111111
if: ${{ always() && matrix.coverage }}
112112
with:
113113
use_oidc: true
114-
disable_search: true
115114
name: ${{ matrix.name || matrix.os }}
116-
files: ./coverage.out
115+
directory: ./coverage
117116

118117
- run: git diff --staged --exit-code --stat
119118

Herebyfile.mjs

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,26 @@ export const generate = task({
239239
},
240240
});
241241

242-
const goTestFlags = [
243-
...goBuildFlags,
244-
...goBuildTags(),
245-
...(options.tests ? [`-run=${options.tests}`] : []),
246-
...(options.coverage ? ["-coverprofile=coverage.out", "-coverpkg=./..."] : []),
247-
];
242+
const coverageDir = path.join(__dirname, "coverage");
243+
244+
const ensureCoverageDirExists = memoize(() => {
245+
if (options.coverage) {
246+
fs.mkdirSync(coverageDir, { recursive: true });
247+
}
248+
});
249+
250+
/**
251+
* @param {string} taskName
252+
*/
253+
function goTestFlags(taskName) {
254+
ensureCoverageDirExists();
255+
return [
256+
...goBuildFlags,
257+
...goBuildTags(),
258+
...(options.tests ? [`-run=${options.tests}`] : []),
259+
...(options.coverage ? [`-coverprofile=${path.join(coverageDir, "coverage." + taskName + ".out")}`, "-coverpkg=./..."] : []),
260+
];
261+
}
248262

249263
const goTestEnv = {
250264
...(options.concurrentTestPrograms ? { TS_TEST_PROGRAM_SINGLE_THREADED: "false" } : {}),
@@ -260,18 +274,24 @@ const goTestSumFlags = [
260274

261275
const $test = $({ env: goTestEnv });
262276

263-
const gotestsum = memoize(() => {
277+
/**
278+
* @param {string} taskName
279+
*/
280+
function gotestsum(taskName) {
264281
const args = isInstalled("gotestsum") ? ["gotestsum", ...goTestSumFlags, "--"] : ["go", "test"];
265-
return args.concat(goTestFlags);
266-
});
282+
return args.concat(goTestFlags(taskName));
283+
}
267284

268-
const goTest = memoize(() => {
269-
return ["go", "test"].concat(goTestFlags);
270-
});
285+
/**
286+
* @param {string} taskName
287+
*/
288+
function goTest(taskName) {
289+
return ["go", "test"].concat(goTestFlags(taskName));
290+
}
271291

272292
async function runTests() {
273293
warnIfTypeScriptSubmoduleNotCloned();
274-
await $test`${gotestsum()} ./... ${isCI ? ["--timeout=45m"] : []}`;
294+
await $test`${gotestsum("tests")} ./... ${isCI ? ["--timeout=45m"] : []}`;
275295
}
276296

277297
export const test = task({
@@ -282,7 +302,7 @@ export const test = task({
282302
async function runTestBenchmarks() {
283303
warnIfTypeScriptSubmoduleNotCloned();
284304
// Run the benchmarks once to ensure they compile and run without errors.
285-
await $test`${goTest()} -run=- -bench=. -benchtime=1x ./...`;
305+
await $test`${goTest("benchmarks")} -run=- -bench=. -benchtime=1x ./...`;
286306
}
287307

288308
export const testBenchmarks = task({
@@ -291,7 +311,7 @@ export const testBenchmarks = task({
291311
});
292312

293313
async function runTestTools() {
294-
await $test({ cwd: path.join(__dirname, "_tools") })`${gotestsum()} ./...`;
314+
await $test({ cwd: path.join(__dirname, "_tools") })`${gotestsum("tools")} ./...`;
295315
}
296316

297317
export const testTools = task({

0 commit comments

Comments
 (0)