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 6d22b94
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:

steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
fetch-depth: 0

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
Expand Down
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 $(git rev-parse origin/${baseRef})..${headRef}`,
(err, stdout, stderr) => {
if (err) {
console.error(err + stderr);
return;
}
files.push(...stdout.split('\n'));
},
);
opts['include'] = files;
}

module.exports = opts;
6 changes: 3 additions & 3 deletions package-lock.json

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

0 comments on commit 6d22b94

Please sign in to comment.