Skip to content

Commit

Permalink
introduce coverage-cmd input
Browse files Browse the repository at this point in the history
  • Loading branch information
mrblackus committed Feb 9, 2024
1 parent 0e18e74 commit 286789e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 40 deletions.
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -45,6 +45,10 @@ inputs:
description: 'The refname to use for the git notes. Defaults to gocoverage'
required: false
default: gocoverage
coverage-cmd:
description: 'Override the whole go test call with a custom command. Useful when using a custom script or make rule.'
required: false
default: ''

outputs:
report-pathname:
Expand Down
51 changes: 32 additions & 19 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

53 changes: 33 additions & 20 deletions index.js
Expand Up @@ -131,25 +131,15 @@ function packageDelta(prior, now) {
return pkgs;
}

async function generateCoverage() {
const report = {
pkg_count: 0,
with_tests: 0,
no_tests: 0,
skipped_count: 0,
coverage_pct: 0,
reportPathname: '',
gocovPathname: '',
gocovAggPathname: '',
};

report.gocovPathname = path.join(tmpdir, 'go.cov');
report.gocovAggPathname = path.join(tmpdir, 'go-aggregate.cov');

const filename = core.getInput('report-filename');
report.reportPathname = filename.startsWith('/')
? filename
: path.join(tmpdir, filename);
async function runCoverage(gocovPathname) {
const coverCmd = core.getInput('coverage-cmd');

// If we have an explicit command to run, use that and return
if (coverCmd) {
const args = coverCmd.split(/\s+/);
await exec(args[0], args.slice(1));
return;
}

const coverMode = core.getInput('cover-mode');
const coverPkg = core.getInput('cover-pkg');
Expand All @@ -170,11 +160,34 @@ async function generateCoverage() {
'-covermode',
coverMode,
'-coverprofile',
report.gocovPathname,
gocovPathname,
...(coverPkg ? ['-coverpkg', coverPkg] : []),
'./...',
]);
await exec('go', args);
}

async function generateCoverage() {
const report = {
pkg_count: 0,
with_tests: 0,
no_tests: 0,
skipped_count: 0,
coverage_pct: 0,
reportPathname: '',
gocovPathname: '',
gocovAggPathname: '',
};

report.gocovPathname = path.join(tmpdir, 'go.cov');
report.gocovAggPathname = path.join(tmpdir, 'go-aggregate.cov');

const filename = core.getInput('report-filename');
report.reportPathname = filename.startsWith('/')
? filename
: path.join(tmpdir, filename);

await runCoverage(report.gocovPathname);

const pkgStats = {};
const [globalPct, skippedFileCount, pkgStmts] = await calcCoverage(
Expand Down

0 comments on commit 286789e

Please sign in to comment.