Skip to content

Commit

Permalink
fix: defer format for output
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Nov 13, 2024
1 parent c1fd37a commit 7693725
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 91 deletions.
37 changes: 26 additions & 11 deletions dist/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -19980,25 +19980,40 @@ function formatCoverage(coverage) {
if (coverage > 0.8) color = "orange";
if (coverage > 0.95) color = "lightgreen";
if (coverage === 1) color = "green";
return "\\$\\${\\\\\\\\color{" + color + "}" + percent + "\\\\\\\\%}\\$\\$";
return "{\\color{" + color + "}" + percent + "\\%}";
}
function getCoverageLine({
hit,
found
}) {
let percent = found == 0 ? 1 : hit / found;
return `${formatCoverage(percent)}<br />${hit} / ${found}`;
function formatCoverageLine({ hit, found }, previousCoverage) {
const coverage = getCoverage({ hit, found });
const diff = !previousCoverage || coverage === previousCoverage ? 0 : (coverage - previousCoverage) / Math.abs(previousCoverage) * 100;
let formattedString = formatCoverage(coverage);
if (diff)
formattedString = "^" + new Intl.NumberFormat("en-US", {
maximumSignificantDigits: 2
}).format(diff) + "\\%" + formattedString;
return `$${formattedString}$<br />$${hit} / ${found}$`;
}
function findFile(report, file) {
return report.find((r) => r.file === file);
}
function getCoverage({ hit, found }) {
return found == 0 ? 1 : hit / found;
}
function generateCoverageDiff(before, after) {
let content = "| File | Line Coverage | Function Coverage | Branch Coverage |\n| --- | ---: | ---: | ---: |\n";
for (const report of after) {
const previousRunResult = findFile(before, report.file);
const lineCoverage = getCoverageLine(report.lines);
const functionCoverage = getCoverageLine(report.functions);
const branchCoverage = getCoverageLine(report.branches);
const lineCoverage = formatCoverageLine(
report.lines,
previousRunResult ? getCoverage(previousRunResult.lines) : 0
);
const functionCoverage = formatCoverageLine(
report.functions,
previousRunResult ? getCoverage(previousRunResult.functions) : 0
);
const branchCoverage = formatCoverageLine(
report.branches,
previousRunResult ? getCoverage(previousRunResult.branches) : 0
);
content += `| ${report.file} | ${lineCoverage} | ${functionCoverage} | ${branchCoverage} |
`;
}
Expand Down Expand Up @@ -20035,7 +20050,7 @@ async function main() {
"report",
`<details><summary>:crystal_ball: <strong>Coverage report</strong></summary>

${content}
${content.replace("\\", "\\\\\\\\").replace("$", "\\$")}

</details>`
);
Expand Down
37 changes: 26 additions & 11 deletions dist/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19985,25 +19985,40 @@ function formatCoverage(coverage) {
if (coverage > 0.8) color = "orange";
if (coverage > 0.95) color = "lightgreen";
if (coverage === 1) color = "green";
return "\\$\\${\\\\\\\\color{" + color + "}" + percent + "\\\\\\\\%}\\$\\$";
return "{\\color{" + color + "}" + percent + "\\%}";
}
function getCoverageLine({
hit,
found
}) {
let percent = found == 0 ? 1 : hit / found;
return `${formatCoverage(percent)}<br />${hit} / ${found}`;
function formatCoverageLine({ hit, found }, previousCoverage) {
const coverage = getCoverage({ hit, found });
const diff = !previousCoverage || coverage === previousCoverage ? 0 : (coverage - previousCoverage) / Math.abs(previousCoverage) * 100;
let formattedString = formatCoverage(coverage);
if (diff)
formattedString = "^" + new Intl.NumberFormat("en-US", {
maximumSignificantDigits: 2
}).format(diff) + "\\%" + formattedString;
return `$${formattedString}$<br />$${hit} / ${found}$`;
}
function findFile(report, file) {
return report.find((r) => r.file === file);
}
function getCoverage({ hit, found }) {
return found == 0 ? 1 : hit / found;
}
function generateCoverageDiff(before, after) {
let content = "| File | Line Coverage | Function Coverage | Branch Coverage |\n| --- | ---: | ---: | ---: |\n";
for (const report of after) {
const previousRunResult = findFile(before, report.file);
const lineCoverage = getCoverageLine(report.lines);
const functionCoverage = getCoverageLine(report.functions);
const branchCoverage = getCoverageLine(report.branches);
const lineCoverage = formatCoverageLine(
report.lines,
previousRunResult ? getCoverage(previousRunResult.lines) : 0
);
const functionCoverage = formatCoverageLine(
report.functions,
previousRunResult ? getCoverage(previousRunResult.functions) : 0
);
const branchCoverage = formatCoverageLine(
report.branches,
previousRunResult ? getCoverage(previousRunResult.branches) : 0
);
content += `| ${report.file} | ${lineCoverage} | ${functionCoverage} | ${branchCoverage} |
`;
}
Expand Down Expand Up @@ -20040,7 +20055,7 @@ async function main() {
"report",
`<details><summary>:crystal_ball: <strong>Coverage report</strong></summary>

${content}
${content.replace("\\", "\\\\\\\\").replace("$", "\\$")}

</details>`
);
Expand Down
35 changes: 25 additions & 10 deletions dist/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,40 @@ function formatCoverage(coverage) {
if (coverage > 0.8) color = "orange";
if (coverage > 0.95) color = "lightgreen";
if (coverage === 1) color = "green";
return "\\$\\${\\\\\\\\color{" + color + "}" + percent + "\\\\\\\\%}\\$\\$";
return "{\\color{" + color + "}" + percent + "\\%}";
}
function getCoverageLine({
hit,
found
}) {
let percent = found == 0 ? 1 : hit / found;
return `${formatCoverage(percent)}<br />${hit} / ${found}`;
function formatCoverageLine({ hit, found }, previousCoverage) {
const coverage = getCoverage({ hit, found });
const diff = !previousCoverage || coverage === previousCoverage ? 0 : (coverage - previousCoverage) / Math.abs(previousCoverage) * 100;
let formattedString = formatCoverage(coverage);
if (diff)
formattedString = "^" + new Intl.NumberFormat("en-US", {
maximumSignificantDigits: 2
}).format(diff) + "\\%" + formattedString;
return `$${formattedString}$<br />$${hit} / ${found}$`;
}
function findFile(report, file) {
return report.find((r) => r.file === file);
}
function getCoverage({ hit, found }) {
return found == 0 ? 1 : hit / found;
}
function generateCoverageDiff(before, after) {
let content = "| File | Line Coverage | Function Coverage | Branch Coverage |\n| --- | ---: | ---: | ---: |\n";
for (const report of after) {
const previousRunResult = findFile(before, report.file);
const lineCoverage = getCoverageLine(report.lines);
const functionCoverage = getCoverageLine(report.functions);
const branchCoverage = getCoverageLine(report.branches);
const lineCoverage = formatCoverageLine(
report.lines,
previousRunResult ? getCoverage(previousRunResult.lines) : 0
);
const functionCoverage = formatCoverageLine(
report.functions,
previousRunResult ? getCoverage(previousRunResult.functions) : 0
);
const branchCoverage = formatCoverageLine(
report.branches,
previousRunResult ? getCoverage(previousRunResult.branches) : 0
);
content += `| ${report.file} | ${lineCoverage} | ${functionCoverage} | ${branchCoverage} |
`;
}
Expand Down
35 changes: 25 additions & 10 deletions dist/lib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,40 @@ function formatCoverage(coverage) {
if (coverage > 0.8) color = "orange";
if (coverage > 0.95) color = "lightgreen";
if (coverage === 1) color = "green";
return "\\$\\${\\\\\\\\color{" + color + "}" + percent + "\\\\\\\\%}\\$\\$";
return "{\\color{" + color + "}" + percent + "\\%}";
}
function getCoverageLine({
hit,
found
}) {
let percent = found == 0 ? 1 : hit / found;
return `${formatCoverage(percent)}<br />${hit} / ${found}`;
function formatCoverageLine({ hit, found }, previousCoverage) {
const coverage = getCoverage({ hit, found });
const diff = !previousCoverage || coverage === previousCoverage ? 0 : (coverage - previousCoverage) / Math.abs(previousCoverage) * 100;
let formattedString = formatCoverage(coverage);
if (diff)
formattedString = "^" + new Intl.NumberFormat("en-US", {
maximumSignificantDigits: 2
}).format(diff) + "\\%" + formattedString;
return `$${formattedString}$<br />$${hit} / ${found}$`;
}
function findFile(report, file) {
return report.find((r) => r.file === file);
}
function getCoverage({ hit, found }) {
return found == 0 ? 1 : hit / found;
}
function generateCoverageDiff(before, after) {
let content = "| File | Line Coverage | Function Coverage | Branch Coverage |\n| --- | ---: | ---: | ---: |\n";
for (const report of after) {
const previousRunResult = findFile(before, report.file);
const lineCoverage = getCoverageLine(report.lines);
const functionCoverage = getCoverageLine(report.functions);
const branchCoverage = getCoverageLine(report.branches);
const lineCoverage = formatCoverageLine(
report.lines,
previousRunResult ? getCoverage(previousRunResult.lines) : 0
);
const functionCoverage = formatCoverageLine(
report.functions,
previousRunResult ? getCoverage(previousRunResult.functions) : 0
);
const branchCoverage = formatCoverageLine(
report.branches,
previousRunResult ? getCoverage(previousRunResult.branches) : 0
);
content += `| ${report.file} | ${lineCoverage} | ${functionCoverage} | ${branchCoverage} |
`;
}
Expand Down
Loading

0 comments on commit 7693725

Please sign in to comment.