Skip to content

Commit

Permalink
only use include on PRs, otherwise ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
coopernetes committed Oct 21, 2023
1 parent 3eb49d2 commit 254cc77
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions nyc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

const { exec } = require('child_process');

console.log('Generating coverage report for changed files...');
const files = [];
exec('git diff --name-only HEAD~1', (err, stdout, stderr) => {
if (err) {
console.error(err + stderr);
return;
}
files.push(...stdout.split('\n'));
});

module.exports = {
include: files,
const opts = {
branches: 80,
lines: 80,
functions: 80,
statements: 80,
};

// Only generate coverage report for changed files in PR
// see: https://github.com/actions/checkout/issues/438#issuecomment-1446882066
// https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
if (process.env.GITHUB_BASE_REF !== undefined) {
console.log('Generating coverage report for changed files...');
const files = [];
exec('git diff --name-only $(git rev-parse HEAD)', (err, stdout, stderr) => {
if (err) {
console.error(err + stderr);
return;
}
files.push(...stdout.split('\n'));
});
opts['include'] = files;
}

module.exports = opts;

0 comments on commit 254cc77

Please sign in to comment.