Skip to content

Commit 286789e

Browse files
author
Mathieu Savy
committed
introduce coverage-cmd input
1 parent 0e18e74 commit 286789e

File tree

4 files changed

+70
-40
lines changed

4 files changed

+70
-40
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ inputs:
4545
description: 'The refname to use for the git notes. Defaults to gocoverage'
4646
required: false
4747
default: gocoverage
48+
coverage-cmd:
49+
description: 'Override the whole go test call with a custom command. Useful when using a custom script or make rule.'
50+
required: false
51+
default: ''
4852

4953
outputs:
5054
report-pathname:

dist/index.js

Lines changed: 32 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,15 @@ function packageDelta(prior, now) {
131131
return pkgs;
132132
}
133133

134-
async function generateCoverage() {
135-
const report = {
136-
pkg_count: 0,
137-
with_tests: 0,
138-
no_tests: 0,
139-
skipped_count: 0,
140-
coverage_pct: 0,
141-
reportPathname: '',
142-
gocovPathname: '',
143-
gocovAggPathname: '',
144-
};
145-
146-
report.gocovPathname = path.join(tmpdir, 'go.cov');
147-
report.gocovAggPathname = path.join(tmpdir, 'go-aggregate.cov');
148-
149-
const filename = core.getInput('report-filename');
150-
report.reportPathname = filename.startsWith('/')
151-
? filename
152-
: path.join(tmpdir, filename);
134+
async function runCoverage(gocovPathname) {
135+
const coverCmd = core.getInput('coverage-cmd');
136+
137+
// If we have an explicit command to run, use that and return
138+
if (coverCmd) {
139+
const args = coverCmd.split(/\s+/);
140+
await exec(args[0], args.slice(1));
141+
return;
142+
}
153143

154144
const coverMode = core.getInput('cover-mode');
155145
const coverPkg = core.getInput('cover-pkg');
@@ -170,11 +160,34 @@ async function generateCoverage() {
170160
'-covermode',
171161
coverMode,
172162
'-coverprofile',
173-
report.gocovPathname,
163+
gocovPathname,
174164
...(coverPkg ? ['-coverpkg', coverPkg] : []),
175165
'./...',
176166
]);
177167
await exec('go', args);
168+
}
169+
170+
async function generateCoverage() {
171+
const report = {
172+
pkg_count: 0,
173+
with_tests: 0,
174+
no_tests: 0,
175+
skipped_count: 0,
176+
coverage_pct: 0,
177+
reportPathname: '',
178+
gocovPathname: '',
179+
gocovAggPathname: '',
180+
};
181+
182+
report.gocovPathname = path.join(tmpdir, 'go.cov');
183+
report.gocovAggPathname = path.join(tmpdir, 'go-aggregate.cov');
184+
185+
const filename = core.getInput('report-filename');
186+
report.reportPathname = filename.startsWith('/')
187+
? filename
188+
: path.join(tmpdir, filename);
189+
190+
await runCoverage(report.gocovPathname);
178191

179192
const pkgStats = {};
180193
const [globalPct, skippedFileCount, pkgStmts] = await calcCoverage(

0 commit comments

Comments
 (0)