diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 5085f3f..3b983b6 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -27,13 +27,15 @@ jobs: NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH }} - name: Create Coverage Report for base branch run: | - mv coverage/lcov.info coverage/lcov_head.info + mv coverage coverage-pr git fetch git checkout origin/${{ github.event.pull_request.base.ref }} npm ci --ignore-scripts && npm run ci:coverage + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH }} - name: Post Coverage Report - uses: checkdigit/github-actions/coverage-reporter@main + uses: checkdigit/github-actions/coverage-reporter@coverage-folder-handling-conflict with: - lcov-file: 'coverage/lcov_head.info' - lcov-base: 'coverage/lcov.info' + coverage-results-folder-pr: 'coverage-pr' + coverage-results-folder-base: 'coverage' delete-old-comments: true diff --git a/coverage-reporter/action.yml b/coverage-reporter/action.yml index e2387f6..f1a5790 100644 --- a/coverage-reporter/action.yml +++ b/coverage-reporter/action.yml @@ -5,12 +5,12 @@ inputs: description: Github token required: true default: ${{ github.token }} - lcov-file: - description: The location of the lcov.info file - required: false - lcov-base: - description: The location of the lcov file for the base branch - required: false + coverage-results-folder-pr: + description: The test coverage results folder of PR branch + required: true + coverage-results-folder-base: + description: The test coverage results folder of main branch + required: true filter-changed-files: description: Set to true to only comment with coverage on files changed in this commit required: false diff --git a/package-lock.json b/package-lock.json index c207b19..61d508f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@checkdigit/github-actions", - "version": "2.2.0", + "version": "2.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@checkdigit/github-actions", - "version": "2.2.0", + "version": "2.3.0", "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", diff --git a/package.json b/package.json index 6fde5b6..a62850b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@checkdigit/github-actions", - "version": "2.2.0", + "version": "2.3.0", "description": " Provides supporting operations for github action builds.", "author": "Check Digit, LLC", "license": "MIT", @@ -46,7 +46,7 @@ "test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style", "ci:compile": "tsc --noEmit", "ci:test": "NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false", - "ci:coverage": "NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true", + "ci:coverage": "rimraf coverage && mkdir coverage && NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true", "ci:lint": "npm run lint", "ci:style": "npm run prettier" }, diff --git a/src/coverage-reporter/coverage-reporter.ts b/src/coverage-reporter/coverage-reporter.ts index a7054e4..ffe88c3 100644 --- a/src/coverage-reporter/coverage-reporter.ts +++ b/src/coverage-reporter/coverage-reporter.ts @@ -22,6 +22,8 @@ import { normalizePath } from './util'; const MAX_COMMENT_CHARS = 65_536; const log = debug('github-actions:coverage-reporter'); +const LCOV_FILE_NAME = 'lcov.info'; + export default async function (): Promise { try { log('Action start'); @@ -29,24 +31,24 @@ export default async function (): Promise { const token = getInput('github-token'); const githubClient = getOctokit(token); const workingDirectory = getInput('working-directory') || './'; - const lcovFile = path.join(workingDirectory, getInput('lcov-file') || './coverage/lcov.info'); - const baseFile = getInput('lcov-base'); + const prLcovFile = path.join(workingDirectory, getInput('coverage-results-folder-pr'), LCOV_FILE_NAME); + const baseLcovFile = path.join(workingDirectory, getInput('coverage-results-folder-base'), LCOV_FILE_NAME); const shouldFilterChangedFiles = getInput('filter-changed-files').toLowerCase() === 'true'; const shouldDeleteOldComments = getInput('delete-old-comments').toLowerCase() === 'true'; const title = getInput('title'); - const raw = await fs.readFile(lcovFile, 'utf8').catch(() => null); + const raw = await fs.readFile(prLcovFile, 'utf8').catch(() => null); if (raw === null || raw === '') { // eslint-disable-next-line no-console - console.log(`No coverage report found at '${lcovFile}', exiting...`); + console.log(`No coverage report found at '${prLcovFile}', exiting...`); return; } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const baseRaw = baseFile && (await fs.readFile(baseFile, 'utf8').catch(() => null))!; - if (baseFile && !baseRaw) { + const baseRaw = baseLcovFile && (await fs.readFile(baseLcovFile, 'utf8').catch(() => null))!; + if (baseLcovFile && !baseRaw) { // eslint-disable-next-line no-console - console.log(`No coverage report found at '${baseFile}', ignoring...`); + console.log(`No coverage report found at '${baseLcovFile}', ignoring...`); } const options = {