Skip to content

Commit 769ccc3

Browse files
committed
Fix Windows support in test coverage
1 parent a0b8c88 commit 769ccc3

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
- name: Tests
3131
run: npm run test:ci
3232
- name: Codecov test coverage
33-
run: bash bin/report_coverage.sh "${{ matrix.os }}" "${{ matrix.node-version }}"
33+
run: node ./bin/report_coverage.js "${{ matrix.os }}" "${{ matrix.node-version }}"

bin/report_coverage.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
// Upload test coverage to Codecov
3+
// We need to use a Node.js script instead of using a npm script or the official
4+
// GitHub action because we want to send OS and Node.js version as flags.
5+
// Codecov does not support dots nor dashes in flags. However, GitHub actions
6+
// variables for those do, so we need to strip them.
7+
const process = require('process')
8+
9+
const execa = require('execa')
10+
11+
const [, , os, nodeVersion] = process.argv
12+
13+
const reportCoverage = async function () {
14+
try {
15+
const curlProcess = execa('curl', ['-s', 'https://codecov.io/bash'], {
16+
stdin: 'ignore',
17+
stdout: 'pipe',
18+
stderr: 'inherit',
19+
})
20+
const bashProcess = execa(
21+
'bash',
22+
[
23+
'-s',
24+
'--',
25+
'-Z',
26+
'-f',
27+
'coverage/coverage-final.json',
28+
'-F',
29+
os.replace('-latest', ''),
30+
'-F',
31+
nodeVersion.replace(/\./g, '_'),
32+
],
33+
{ stdin: 'pipe', stdout: 'inherit', stderr: 'inherit' },
34+
)
35+
curlProcess.stdout.pipe(bashProcess.stdin)
36+
await Promise.all([curlProcess, bashProcess])
37+
// Codecov API fails quite often. Therefore, we don't exit this process with
38+
// non-0 code
39+
} catch (error) {
40+
console.error(`Could not upload test coverage: ${error.message}`)
41+
}
42+
}
43+
44+
reportCoverage()

bin/report_coverage.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"bin": {
1313
"run-e": "./bin/run_e.js",
14-
"report_coverage": "./bin/report_coverage.sh"
14+
"report-coverage": "./bin/report_coverage.js"
1515
},
1616
"scripts": {
1717
"test": "run-s format test:dev",

0 commit comments

Comments
 (0)