Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions coverage-reporter/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
16 changes: 9 additions & 7 deletions src/coverage-reporter/coverage-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,33 @@ 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<void> {
try {
log('Action start');

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 = {
Expand Down