Closed hemant-brb closed 1 year ago
have added a fix for this issue https://github.com/barecheck/code-coverage-action/pull/236
const getChangedFilesCoverage = async (coverage) => {
const pullRequestContext = getPullRequestContext();
if (!pullRequestContext) return coverage.data;
const octokit = await getOctokit();
const { repo, owner, pullNumber } = pullRequestContext;
const changedFiles = await githubApi.getChangedFiles(octokit, {
repo,
owner,
pullNumber
});
const workspacePath = getWorkspacePath();
const changedFilesCoverage = coverage.data.reduce(
(allFiles, { file, lines }) => {
const filePath = workspacePath ? `${workspacePath}/${file}` : file;
const changedFile = changedFiles.find(
({ filename }) => filename === filePath
);
if (changedFile) {
return [
...allFiles,
{
file: filePath,
url: changedFile.blob_url,
lines
}
];
}
return allFiles;
},
[]
);
return changedFilesCoverage;
};
The Github action:
- name: Backend Code Coverage report
id: code-coverage-backend
uses: ./code-coverage
with:
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
lcov-file: "apps/server/coverage/lcov.info"
send-summary-comment: true
show-annotations: "warning"
workspace-path: "apps/server"
app-name: "Backend"
env:
BARECHECK_GITHUB_APP_TOKEN: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
That's great @Hemant11111 ! Thanks for doing it 🎉
I just left a few comments, let me know when you're able to take a look and we can merge/release this feature.
Hey @Hemant11111 ! I just released new version - please, let me know if you see any issues with it
Consider a monorepo which have
app/web
andapp/server
with their own coverage information at locationapp/web/coverage/lcov.info
andapp/server/coverage/lcov.info
respectively. (which we can specify throughlcov-file
param).However when the script tries to read the changed files coverage information in changeFilesCoverage.js -> getChangedFilesCoverage(), there is an issue in file path comparison logic due to which it doesn't match any files and returns an empty array.
Now, In coverage/lcov.info file path is
app/web/**/xyz.js
but the script tries to compare this file with the**/xyz.js
. While passing the params through GitHub Actions we need to tell the script the workspace path so that the script can use that workspace path + file path to compare.