Skip to content

Commit 4b30979

Browse files
committed
docs: add report coverage difference
1 parent 0d32f25 commit 4b30979

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

docs/github_action.md

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
The `go-test-coverage` GitHub Action provides the following capabilities:
44
- Enforce success of GitHub workflows only when a specified coverage threshold is met.
55
- Generate a coverage badge to display the total test coverage.
6-
- Post a detailed coverage report as a comment on pull requests.
6+
- Post a detailed coverage report as a comment on pull requests, including:
7+
- current test coverage
8+
- the difference compared to the base branch
9+
10+
## Action Inputs and Outputs
11+
12+
Action inputs and outputs are documented in [action.yml](/action.yml) file.
713

8-
9-
## Usage
14+
15+
## Basic Usage
1016

1117
Here’s an example of how to integrate `go-test-coverage` in a GitHub workflow that uses a config file. This is the preferred way because the same config file can be used for running coverage checks locally.
1218

@@ -32,10 +38,6 @@ Alternatively, if you don't need advanced configuration options from a config fi
3238
3339
Note: When using a config file alongside action properties, specifying these parameters will override the corresponding values in the config file.
3440
35-
## Action Inputs and Outputs
36-
37-
Action inputs and outputs are documented in [action.yml](/action.yml) file.
38-
3941
## Liberal Coverage Check
4042
4143
The `go-test-coverage` GitHub Action can be configured to report the current test coverage without enforcing specific thresholds. To enable this functionality in your GitHub workflow, include the `continue-on-error: true` property in the job step configuration. This ensures that the workflow proceeds even if the coverage check fails.
@@ -51,9 +53,50 @@ Below is an example that reports files with coverage below 80% without causing t
5153
threshold-file: 80
5254
```
5355

56+
## Report Coverage Difference
57+
58+
Using go-test-coverage, you can display a detailed comparison of code coverage changes relative to the base branch. When this feature is enabled, the report highlights files with coverage differences compared to the base branch.
59+
60+
The same logic is used in workflow in [this repo](/.github/workflows/test.yml).
61+
62+
```yml
63+
# Download main (aka base) branch breakdown
64+
- name: download artifact (main.breakdown)
65+
id: download-main-breakdown
66+
uses: dawidd6/action-download-artifact@v6
67+
with:
68+
branch: main
69+
workflow_conclusion: success
70+
name: main.breakdown
71+
72+
- name: check test coverage
73+
uses: vladopajic/go-test-coverage@v2
74+
with:
75+
config: ./.github/.testcoverage.yml
76+
profile: ubuntu-latest-profile,macos-latest-profile,windows-latest-profile
77+
78+
# Save current coverage breakdown if current branch is main. It will be
79+
# uploaded as artifact in step below.
80+
breakdown-file-name: ${{ github.ref_name == 'main' && 'main.breakdown' || '' }}
81+
82+
# If this is not main brach we want to show report including
83+
# file coverage difference from main branch.
84+
diff-base-breakdown-file-name: ${{ steps.download-main-breakdown.outputs.found_artifact && 'main.breakdown' || '' }}
85+
86+
- name: upload artifact (main.breakdown)
87+
uses: actions/upload-artifact@v4
88+
if: github.ref_name == 'main'
89+
with:
90+
name: main.breakdown
91+
path: main.breakdown # as specified via `breakdown-file-name`
92+
if-no-files-found: error
93+
```
94+
5495
## Post Coverage Report to PR
5596
56-
Here is an example of how to post comments with the coverage report to your pull request. The same logic is used in workflow in [this repo](/.github/workflows/test.yml).
97+
Here is an example of how to post comments with the coverage report to your pull request.
98+
99+
The same logic is used in workflow in [this repo](/.github/workflows/test.yml).
57100
58101
```yml
59102
- name: check test coverage

0 commit comments

Comments
 (0)