Skip to content

Commit

Permalink
Merge pull request #974 from Accenture/task/972-upgrade-report-nyc-co…
Browse files Browse the repository at this point in the history
…verage-github-action-to-v127

Task/972 upgrade report-nyc-coverage GitHub action to v1.2.7
  • Loading branch information
JoernBerkefeld authored Jun 6, 2023
2 parents 9d7ad2d + 6a93f52 commit 6f541c7
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 197 deletions.
20 changes: 0 additions & 20 deletions .coverage-comment-template.md

This file was deleted.

338 changes: 177 additions & 161 deletions .coverage-comment-template.svelte
Original file line number Diff line number Diff line change
@@ -1,178 +1,194 @@
<script>
export let total_statements_coverage_percent_raw;
export let total_branches_coverage_percent_raw;
export let total_functions_coverage_percent_raw;
export let total_lines_coverage_percent_raw;
export let base_total_statements_coverage_percent_raw;
export let base_total_branches_coverage_percent_raw;
export let base_total_functions_coverage_percent_raw;
export let base_total_lines_coverage_percent_raw;
export let commit_sha;
export let short_commit_sha;
export let commit_link;
export let base_commit_sha;
export let base_short_commit_sha;
export let base_commit_link;
export let base_ref;
export let changed_files_coverage_data;
const has_base_data = base_total_branches_coverage_percent_raw !== '?';
const summary_list = [
{
type: 'Total Statements Coverage',
percent: {
total: total_statements_coverage_percent_raw,
base: has_base_data ? base_total_statements_coverage_percent_raw: null,
diff: has_base_data ? (total_statements_coverage_percent_raw - base_total_statements_coverage_percent_raw) : null,
}
},
{
type: 'Total Branches Coverage',
percent: {
total: total_branches_coverage_percent_raw,
base: has_base_data ? base_total_branches_coverage_percent_raw: null,
diff: has_base_data ? (total_branches_coverage_percent_raw - base_total_branches_coverage_percent_raw) : null,
}
},
{
type: 'Total Functions Coverage',
percent: {
total: total_functions_coverage_percent_raw,
base: has_base_data ? base_total_functions_coverage_percent_raw: null,
diff: has_base_data ? (total_functions_coverage_percent_raw - base_total_functions_coverage_percent_raw) : null,
}
},
{
type: 'Total Lines Coverage',
percent: {
total: total_lines_coverage_percent_raw,
base: has_base_data ? base_total_lines_coverage_percent_raw: null,
diff: has_base_data ? (total_lines_coverage_percent_raw - base_total_lines_coverage_percent_raw) : null,
}
}];
const LETTER_LABEL = {
S: 'Statements',
B: 'Branches',
F: 'Functions',
L: 'Lines',
};
const COVERAGE_LEVEL_IMAGE = {
low: 'https://user-images.githubusercontent.com/11299391/159445221-fe3dc085-8c56-4e03-9642-219784c88fe7.svg',
medium:
'https://user-images.githubusercontent.com/11299391/159445212-f135c6d7-f354-4e8c-9a9f-28bb3ff1b7b5.svg',
high: 'https://user-images.githubusercontent.com/11299391/159445220-d88b3624-0814-4664-80c8-09f0f2b8e68b.svg',
};
function formatPercentDiff(percent) {
if (!Number.isFinite(percent)) {
return '';
export let total_statements_coverage_percent_raw;
export let total_branches_coverage_percent_raw;
export let total_functions_coverage_percent_raw;
export let total_lines_coverage_percent_raw;
export let base_total_statements_coverage_percent_raw;
export let base_total_branches_coverage_percent_raw;
export let base_total_functions_coverage_percent_raw;
export let base_total_lines_coverage_percent_raw;
export let commit_sha;
export let short_commit_sha;
export let commit_link;
export let base_commit_sha;
export let base_short_commit_sha;
export let base_commit_link;
export let base_ref;
export let changed_files_coverage_data;
const has_base_data = base_total_branches_coverage_percent_raw !== '?';
const summary_list = [
{
type: 'Total Statements Coverage',
percent: {
total: total_statements_coverage_percent_raw,
base: has_base_data ? base_total_statements_coverage_percent_raw : null,
diff: has_base_data
? total_statements_coverage_percent_raw -
base_total_statements_coverage_percent_raw
: null,
},
},
{
type: 'Total Branches Coverage',
percent: {
total: total_branches_coverage_percent_raw,
base: has_base_data ? base_total_branches_coverage_percent_raw : null,
diff: has_base_data
? total_branches_coverage_percent_raw - base_total_branches_coverage_percent_raw
: null,
},
},
{
type: 'Total Functions Coverage',
percent: {
total: total_functions_coverage_percent_raw,
base: has_base_data ? base_total_functions_coverage_percent_raw : null,
diff: has_base_data
? total_functions_coverage_percent_raw -
base_total_functions_coverage_percent_raw
: null,
},
},
{
type: 'Total Lines Coverage',
percent: {
total: total_lines_coverage_percent_raw,
base: has_base_data ? base_total_lines_coverage_percent_raw : null,
diff: has_base_data
? total_lines_coverage_percent_raw - base_total_lines_coverage_percent_raw
: null,
},
},
];
const LETTER_LABEL = {
S: 'Statements',
B: 'Branches',
F: 'Functions',
L: 'Lines',
};
const COVERAGE_LEVEL_IMAGE = {
low: 'https://user-images.githubusercontent.com/11299391/159445221-fe3dc085-8c56-4e03-9642-219784c88fe7.svg',
medium: 'https://user-images.githubusercontent.com/11299391/159445212-f135c6d7-f354-4e8c-9a9f-28bb3ff1b7b5.svg',
high: 'https://user-images.githubusercontent.com/11299391/159445220-d88b3624-0814-4664-80c8-09f0f2b8e68b.svg',
};
function formatPercentDiff(percent) {
if (!Number.isFinite(percent)) {
return '';
}
const roundedPercent = `${Number(percent.toFixed(2))}%`;
if (percent >= 0) {
return '+' + roundedPercent;
}
return roundedPercent;
}
const roundedPercent = `${Number(percent.toFixed(2))}%`;
if (percent >= 0) {
return '+' + roundedPercent;
function getCoverageLevelImage(percent) {
// https://github.com/istanbuljs/istanbuljs/blob/c1559005b3bb318da01f505740adb0e782aaf14e/packages/istanbul-lib-report/lib/watermarks.js
if (percent >= 80) {
return COVERAGE_LEVEL_IMAGE.high;
} else if (percent >= 50) {
return COVERAGE_LEVEL_IMAGE.medium;
} else {
return COVERAGE_LEVEL_IMAGE.low;
}
}
return roundedPercent;
}
function getCoverageLevelImage(percent) {
// https://github.com/istanbuljs/istanbuljs/blob/c1559005b3bb318da01f505740adb0e782aaf14e/packages/istanbul-lib-report/lib/watermarks.js
if (percent >= 80) {
return COVERAGE_LEVEL_IMAGE.high;
} else if (percent >= 50) {
return COVERAGE_LEVEL_IMAGE.medium;
} else {
return COVERAGE_LEVEL_IMAGE.low;
function getFilePrefix() {
return `../blob/${commit_sha}/`;
}
}
function getFilePrefix() {
return `../blob/${commit_sha}/`;
}
</script>

<h2>Coverage Report</h2>

Commit: <a href="{commit_link}">{short_commit_sha}</a><br>
Base: <a href="{base_commit_link}">{base_ref}@{base_short_commit_sha}</a><br><br>
Commit:<a href={commit_link}>{short_commit_sha}</a><br />
Base: <a href={base_commit_link}>{base_ref}@{base_short_commit_sha}</a><br /><br />

<table>
<thead>
<th>Type</th>
{#if has_base_data}
<th>Base</th>
{/if}
<th>This PR</th>
</thead>
<tbody>
{#each summary_list as {type, percent}}
<tr>
<td>{type}</td>
<thead>
<th>Type</th>
{#if has_base_data}
<td>
{#if Number.isFinite(percent.base)}
<img src="{getCoverageLevelImage(percent.base)}" alt="">&nbsp;{percent.base}%
{:else}
-
{/if}
</td>
<th>Base</th>
{/if}
<td>
{#if Number.isFinite(percent.total)}
<img src="{getCoverageLevelImage(percent.total)}" alt="">&nbsp;{percent.total}%
{#if has_base_data}
&nbsp;({formatPercentDiff(percent.diff)})
{/if}
{:else}
-
{/if}
</td>
</tr>
{/each}
</tbody>
</table>

<details>
<summary>Details (changed testable files):</summary><br>
<table>
<thead>
<th>File</th>
<th>Statements</th>
<th>Branches</th>
<th>Functions</th>
<th>Lines</th>
<th>This PR</th>
</thead>
<tbody>
{#each changed_files_coverage_data as [file, data]}
{@const percents = [
data.statements.pct,
data.branches.pct,
data.functions.pct,
data.lines.pct
]}
<tr>
<td>
<a href="{getFilePrefix()}{file}">{file}</a>
</td>
{#each percents as percent}
<td>
{#if Number.isFinite(percent)}
<img src="{getCoverageLevelImage(percent)}" alt="">&nbsp;{percent}%
{:else}
-
{/if}
</td>
{/each}
</tr>
{/each}
{#each summary_list as { type, percent }}
<tr>
<td>{type}</td>
{#if has_base_data}
<td>
{#if Number.isFinite(percent.base)}
<img
src={getCoverageLevelImage(percent.base)}
alt=""
/>&nbsp;{percent.base}%
{:else}
-
{/if}
</td>
{/if}
<td>
{#if Number.isFinite(percent.total)}
<img
src={getCoverageLevelImage(percent.total)}
alt=""
/>&nbsp;{percent.total}%
{#if has_base_data}
&nbsp;({formatPercentDiff(percent.diff)})
{/if}
{:else}
-
{/if}
</td>
</tr>
{/each}
</tbody>
</table>
</details>
</table>

<details>
<summary>Details (changed files):</summary><br />
<table>
<thead>
<th>File</th>
<th>Statements</th>
<th>Branches</th>
<th>Functions</th>
<th>Lines</th>
</thead>
<tbody>
{#each changed_files_coverage_data as [file, data]}
{@const percents = [
data.statements.pct,
data.branches.pct,
data.functions.pct,
data.lines.pct,
]}
<tr>
<td>
<a href="{getFilePrefix()}{file}">{file}</a>
</td>
{#each percents as percent}
<td>
{#if Number.isFinite(percent)}
<img src={getCoverageLevelImage(percent)} alt="" />&nbsp;{percent}%
{:else}
-
{/if}
</td>
{/each}
</tr>
{/each}
</tbody>
</table>
</details>
4 changes: 2 additions & 2 deletions .github/workflows/coverage-base-update.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update coverage comment
name: Update coverage comment # base-update.yml
on:
pull_request:
types: [edited]
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
files: 'base-artifacts/coverage-summary.json, artifacts/coverage-summary.json'

- name: Update Coverage comment
uses: sidx1024/report-nyc-coverage-github-action@v1.2.6
uses: sidx1024/report-nyc-coverage-github-action@v1.2.7
if: steps.check_files.outputs.files_exists == 'true'
# Only runs if all of the files exists
with:
Expand Down
Loading

0 comments on commit 6f541c7

Please sign in to comment.