Skip to content

Commit

Permalink
Merge pull request #39 from sidx1024/sid/test-base
Browse files Browse the repository at this point in the history
Fix comparison with base branch
  • Loading branch information
sidx1024 authored May 27, 2023
2 parents 1e37c2b + b79e10f commit dfb4449
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 36 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/base-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ jobs:
run: git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1000

- name: Download artifact
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v2.24.2
continue-on-error: true
with:
workflow: ${{ github.event.pull_request.base.ref == 'main' && 'default-branch.yml' || 'main.yml' }}
workflow_conclusion: success
commit: ${{github.event.pull_request.base.sha}}
name: 'test-coverage-output'
path: base-artifacts
search_artifacts: 'test-coverage-output'
search_artifacts: true

- name: Download artifact
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v2.24.2
continue-on-error: true
with:
workflow: 'main.yml'
workflow_conclusion: success
commit: ${{github.event.pull_request.head.sha}}
name: 'test-coverage-output'
path: artifacts
search_artifacts: 'test-coverage-output'
search_artifacts: true

- name: Check file existence
id: check_files
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}

- name: Download artifact
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v2.24.2
continue-on-error: true
with:
workflow: ${{ github.event.pull_request.base.ref == 'main' && 'default-branch.yml' || 'main.yml' }}
run_id: ${{steps.get_run_id.outputs.run_id}}
name: 'test-coverage-output'
path: base-artifacts
search_artifacts: 'test-coverage-output'
search_artifacts: true

- name: Check file existence
id: check_files
Expand Down
57 changes: 33 additions & 24 deletions comment-template.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,43 @@
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,
}
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,
}
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,
}
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,
}
}];
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',
Expand Down Expand Up @@ -101,33 +110,33 @@

<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}
{#if has_base_data}
<th>Base</th>
{/if}
<th>This PR</th>
</thead>
<tbody>
{#each summary_list as {type, percent}}
{#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}%
<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}%
<img src={getCoverageLevelImage(percent.total)} alt="" />&nbsp;{percent.total}%
{#if has_base_data}
&nbsp;({formatPercentDiff(percent.diff)})
{/if}
Expand All @@ -141,7 +150,7 @@ Base: <a href="{base_commit_link}">{base_ref}@{base_short_commit_sha}</a><br><br
</table>

<details>
<summary>Details (changed files):</summary><br>
<summary>Details (changed files):</summary><br />
<table>
<thead>
<th>File</th>
Expand All @@ -156,7 +165,7 @@ Base: <a href="{base_commit_link}">{base_ref}@{base_short_commit_sha}</a><br><br
data.statements.pct,
data.branches.pct,
data.functions.pct,
data.lines.pct
data.lines.pct,
]}
<tr>
<td>
Expand All @@ -165,7 +174,7 @@ Base: <a href="{base_commit_link}">{base_ref}@{base_short_commit_sha}</a><br><br
{#each percents as percent}
<td>
{#if Number.isFinite(percent)}
<img src="{getCoverageLevelImage(percent)}" alt="">&nbsp;{percent}%
<img src={getCoverageLevelImage(percent)} alt="" />&nbsp;{percent}%
{:else}
-
{/if}
Expand Down
9 changes: 3 additions & 6 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ t.test('replaceTokens', async () => {
'1, 2, and 3',
);

t.throws(
function throwsErrorForMissingToken() {
replaceTokens('{{one}}, {{four}}, and {{five}}', { one: 1, two: 2, three: 3 });
},
new Error('Invalid or missing tokens: four,five')
);
t.throws(function throwsErrorForMissingToken() {
replaceTokens('{{one}}, {{four}}, and {{five}}', { one: 1, two: 2, three: 3 });
}, new Error('Invalid or missing tokens: four,five'));
});

0 comments on commit dfb4449

Please sign in to comment.