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 4f571db
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions nyc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@

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 baseRef = process.env.GITHUB_BASE_REF;
const headRef = process.env.GITHUB_SHA;
const files = [];
exec(
`git diff --name-only origin/${baseRef}..${headRef}`,
(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 4f571db

Please sign in to comment.