Skip to content

Commit

Permalink
only use include on PRs, otherwise ignore
Browse files Browse the repository at this point in the history
reconcile package-lock from main
  • Loading branch information
coopernetes committed Oct 21, 2023
1 parent 03d57c5 commit 1fc80f3
Show file tree
Hide file tree
Showing 3 changed files with 478 additions and 44 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
46 changes: 33 additions & 13 deletions nyc.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
/* eslint-disable max-len */
'use strict';

const { exec } = require('child_process');
const { execFileSync } = 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,
let 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...');
try {
const baseRef = execFileSync('git', [
'rev-parse',
`origin/${process.env.GITHUB_BASE_REF}`,
])
.toString()
.replace('\n', '');
const headRef = process.env.GITHUB_SHA;
const stdout = execFileSync('git', [
'diff',
'--name-only',
`${baseRef}..${headRef}`,
]).toString();
opts = {
...opts,
include: stdout.split('\n'),
};
} catch (error) {
console.log('Error: ', error);
}
}

console.log('nyc config: ', opts);
module.exports = opts;
Loading

0 comments on commit 1fc80f3

Please sign in to comment.