Skip to content

Commit 109af08

Browse files
committed
fix: correctly report changed files when using workingDirectory
1 parent 46c34a3 commit 109af08

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

dist/main/index.js

Lines changed: 17 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ async function run() {
1212
await exec.exec('sudo apt-get install lcov');
1313

1414
const tmpPath = path.resolve(os.tmpdir(), github.context.action);
15+
const workingDirectory = ensureTrailingSlash(core.getInput('working-directory').trim() || './');
1516
const coverageFilesPattern = core.getInput('coverage-files');
1617
const globber = await glob.create(coverageFilesPattern);
1718
const coverageFiles = await globber.glob();
1819

19-
await genhtml(coverageFiles, tmpPath);
20+
await genhtml(coverageFiles, tmpPath, workingDirectory);
2021

2122
const coverageFile = await mergeCoverages(coverageFiles, tmpPath);
2223
const totalCoverage = lcovTotal(coverageFile);
@@ -32,7 +33,7 @@ async function run() {
3233
const pr = prs[i];
3334
console.log(`Calculating coverage for PR ${pr.number}, sha ${pr.head.sha}...`);
3435
const summary = await summarize(coverageFile);
35-
const details = await detail(coverageFile, pr, octokit);
36+
const details = await detail(coverageFile, pr, octokit, workingDirectory);
3637
const shaShort = pr.head.sha.substr(0, 7);
3738
let body = `### Coverage of commit [<code>${shaShort}</code>](${pr.number}/commits/${pr.head.sha})
3839
<pre>${summary}
@@ -103,8 +104,15 @@ function ownerRepo(url) {
103104
};
104105
}
105106

106-
async function genhtml(coverageFiles, tmpPath) {
107-
const workingDirectory = core.getInput('working-directory').trim() || './';
107+
function ensureTrailingSlash(path) {
108+
if (path.endsWith("/")) {
109+
return path;
110+
}
111+
112+
return path + "/";
113+
}
114+
115+
async function genhtml(coverageFiles, tmpPath, workingDirectory) {
108116
const artifactName = core.getInput('artifact-name').trim();
109117
const artifactPath = path.resolve(tmpPath, 'html').trim();
110118
const args = [...coverageFiles];
@@ -173,7 +181,7 @@ async function summarize(coverageFile) {
173181
return lines.join('\n');
174182
}
175183

176-
async function detail(coverageFile, pull_request, octokit) {
184+
async function detail(coverageFile, pull_request, octokit, workingDirectory) {
177185
let output = '';
178186

179187
const options = {};
@@ -210,6 +218,10 @@ async function detail(coverageFile, pull_request, octokit) {
210218
lines = lines.filter((line, index) => {
211219
if (index <= 2) return true; // Include header
212220

221+
if (workingDirectory !== "./") {
222+
line = workingDirectory + line;
223+
}
224+
213225
for (const changedFile of changedFiles) {
214226
console.log(`${line} === ${changedFile}`);
215227

0 commit comments

Comments
 (0)