From 6d22b94c06c9fabf98b03269c22990c31a1f0f20 Mon Sep 17 00:00:00 2001 From: Thomas Cooper Date: Sat, 21 Oct 2023 12:47:35 -0400 Subject: [PATCH] only use include on PRs, otherwise ignore --- .github/workflows/nodejs.yml | 2 ++ nyc.config.js | 36 ++++++++++++++++++++++++------------ package-lock.json | 6 +++--- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 84e8ee031..6cb463033 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -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 diff --git a/nyc.config.js b/nyc.config.js index dc22ec462..32618ab15 100644 --- a/nyc.config.js +++ b/nyc.config.js @@ -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; diff --git a/package-lock.json b/package-lock.json index b97bfc6bc..0c01cc79e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2245,9 +2245,9 @@ "integrity": "sha512-kMpQpfZKSCBqltAJwskgePRaYRFukDkm1oItcAbC3gNELR20XIBcN9VRgg4+m8DKsTfkWeA4m4Imp4DDuWy7FQ==" }, "node_modules/@types/react": { - "version": "18.2.24", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.24.tgz", - "integrity": "sha512-Ee0Jt4sbJxMu1iDcetZEIKQr99J1Zfb6D4F3qfUWoR1JpInkY1Wdg4WwCyBjL257D0+jGqSl1twBjV8iCaC0Aw==", + "version": "17.0.69", + "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.69.tgz", + "integrity": "sha512-klEeru//GhiQvXUBayz0Q4l3rKHWsBR/EUOhOeow6hK2jV7MlO44+8yEk6+OtPeOlRfnpUnrLXzGK+iGph5aeg==", "dependencies": { "@types/prop-types": "*", "@types/scheduler": "*",