Skip to content

Commit 4147bce

Browse files
authored
chore(docs): remove yml code indentation
1 parent 6626199 commit 4147bce

File tree

1 file changed

+93
-93
lines changed

1 file changed

+93
-93
lines changed

docs/github_action.md

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,41 @@ Action inputs and outputs are documented in [action.yml](/action.yml) file.
1818
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.
1919

2020
```yml
21-
- name: check test coverage
22-
uses: vladopajic/go-test-coverage@v2
23-
with:
24-
config: ./.testcoverage.yml
21+
- name: check test coverage
22+
uses: vladopajic/go-test-coverage@v2
23+
with:
24+
config: ./.testcoverage.yml
2525
```
2626
2727
Alternatively, if you don't need advanced configuration options from a config file, you can specify thresholds directly in the action properties.
2828
2929
```yml
30-
- name: check test coverage
31-
uses: vladopajic/go-test-coverage@v2
32-
with:
33-
profile: cover.out
34-
threshold-file: 80
35-
threshold-package: 80
36-
threshold-total: 95
30+
- name: check test coverage
31+
uses: vladopajic/go-test-coverage@v2
32+
with:
33+
profile: cover.out
34+
threshold-file: 80
35+
threshold-package: 80
36+
threshold-total: 95
3737
```
3838
3939
Note: When using a config file alongside action properties, specifying these parameters will override the corresponding values in the config file.
4040
41+
## Generate Coverage Badge
42+
43+
Instructions for badge creation are available [here](./badge.md).
44+
4145
## Source Directory
4246
4347
Some projects, such as monorepos with multiple projects under the root directory, may require specifying the path to a project's source.
4448
In such cases, the `source-dir` property can be used to specify the source files location relative to the root directory.
4549

4650
```yml
47-
- name: check test coverage
48-
uses: vladopajic/go-test-coverage@v2
49-
with:
50-
config: ./.testcoverage.yml
51-
source-dir: ./some_project
51+
- name: check test coverage
52+
uses: vladopajic/go-test-coverage@v2
53+
with:
54+
config: ./.testcoverage.yml
55+
source-dir: ./some_project
5256
```
5357

5458
## Liberal Coverage Check
@@ -57,13 +61,13 @@ The `go-test-coverage` GitHub Action can be configured to report the current tes
5761

5862
Below is an example that reports files with coverage below 80% without causing the workflow to fail:
5963
```yml
60-
- name: check test coverage
61-
id: coverage
62-
uses: vladopajic/go-test-coverage@v2
63-
continue-on-error: true
64-
with:
65-
profile: cover.out
66-
threshold-file: 80
64+
- name: check test coverage
65+
id: coverage
66+
uses: vladopajic/go-test-coverage@v2
67+
continue-on-error: true
68+
with:
69+
profile: cover.out
70+
threshold-file: 80
6771
```
6872

6973
## Report Coverage Difference
@@ -74,37 +78,37 @@ The same logic is used in workflow in [this repo](/.github/workflows/test.yml).
7478
Example of report that includes coverage difference is [this PR](https://github.com/vladopajic/go-test-coverage/pull/129).
7579

7680
```yml
77-
# Download main (aka base) branch breakdown
78-
- name: download artifact (main.breakdown)
79-
id: download-main-breakdown
80-
uses: dawidd6/action-download-artifact@v6
81-
with:
82-
branch: main
83-
workflow_conclusion: success
84-
name: main.breakdown
85-
if_no_artifact_found: warn
86-
87-
- name: check test coverage
88-
uses: vladopajic/go-test-coverage@v2
89-
with:
90-
config: ./.github/.testcoverage.yml
91-
profile: ubuntu-latest-profile,macos-latest-profile,windows-latest-profile
92-
93-
# Save current coverage breakdown if current branch is main. It will be
94-
# uploaded as artifact in step below.
95-
breakdown-file-name: ${{ github.ref_name == 'main' && 'main.breakdown' || '' }}
96-
97-
# If this is not main brach we want to show report including
98-
# file coverage difference from main branch.
99-
diff-base-breakdown-file-name: ${{ steps.download-main-breakdown.outputs.found_artifact == 'true' && 'main.breakdown' || '' }}
100-
101-
- name: upload artifact (main.breakdown)
102-
uses: actions/upload-artifact@v4
103-
if: github.ref_name == 'main'
104-
with:
105-
name: main.breakdown
106-
path: main.breakdown # as specified via `breakdown-file-name`
107-
if-no-files-found: error
81+
# Download main (aka base) branch breakdown
82+
- name: download artifact (main.breakdown)
83+
id: download-main-breakdown
84+
uses: dawidd6/action-download-artifact@v6
85+
with:
86+
branch: main
87+
workflow_conclusion: success
88+
name: main.breakdown
89+
if_no_artifact_found: warn
90+
91+
- name: check test coverage
92+
uses: vladopajic/go-test-coverage@v2
93+
with:
94+
config: ./.github/.testcoverage.yml
95+
profile: ubuntu-latest-profile,macos-latest-profile,windows-latest-profile
96+
97+
# Save current coverage breakdown if current branch is main. It will be
98+
# uploaded as artifact in step below.
99+
breakdown-file-name: ${{ github.ref_name == 'main' && 'main.breakdown' || '' }}
100+
101+
# If this is not main brach we want to show report including
102+
# file coverage difference from main branch.
103+
diff-base-breakdown-file-name: ${{ steps.download-main-breakdown.outputs.found_artifact == 'true' && 'main.breakdown' || '' }}
104+
105+
- name: upload artifact (main.breakdown)
106+
uses: actions/upload-artifact@v4
107+
if: github.ref_name == 'main'
108+
with:
109+
name: main.breakdown
110+
path: main.breakdown # as specified via `breakdown-file-name`
111+
if-no-files-found: error
108112
```
109113
110114
## Post Coverage Report to PR
@@ -115,47 +119,43 @@ The same logic is used in workflow in [this repo](/.github/workflows/test.yml).
115119
Example of report is in [this PR](https://github.com/vladopajic/go-test-coverage/pull/129).
116120
117121
```yml
118-
- name: check test coverage
119-
id: coverage
120-
uses: vladopajic/go-test-coverage@v2
121-
continue-on-error: true # Should fail after coverage comment is posted
122-
with:
123-
config: ./.github/.testcoverage.yml
124-
125-
# Post coverage report as comment (in 2 steps)
126-
- name: find pull request ID
127-
run: |
128-
PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
129-
"https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref_name }}&state=open")
130-
PR_ID=$(echo "$PR_DATA" | jq -r '.[0].number')
131-
132-
if [ "$PR_ID" != "null" ]; then
133-
echo "pull_request_id=$PR_ID" >> $GITHUB_ENV
134-
else
135-
echo "No open pull request found for this branch."
136-
fi
137-
- name: post coverage report
138-
if: env.pull_request_id
139-
uses: thollander/actions-comment-pull-request@v3
140-
with:
141-
github-token: ${{ secrets.GITHUB_TOKEN }}
142-
comment-tag: coverage-report
143-
pr-number: ${{ env.pull_request_id }}
144-
message: |
145-
go-test-coverage report:
146-
```
147-
${{ fromJSON(steps.coverage.outputs.report) }}```
148-
149-
- name: "finally check coverage"
150-
if: steps.coverage.outcome == 'failure'
151-
shell: bash
152-
run: echo "coverage check failed" && exit 1
122+
- name: check test coverage
123+
id: coverage
124+
uses: vladopajic/go-test-coverage@v2
125+
continue-on-error: true # Should fail after coverage comment is posted
126+
with:
127+
config: ./.github/.testcoverage.yml
128+
129+
# Post coverage report as comment (in 2 steps)
130+
- name: find pull request ID
131+
run: |
132+
PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
133+
"https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref_name }}&state=open")
134+
PR_ID=$(echo "$PR_DATA" | jq -r '.[0].number')
135+
136+
if [ "$PR_ID" != "null" ]; then
137+
echo "pull_request_id=$PR_ID" >> $GITHUB_ENV
138+
else
139+
echo "No open pull request found for this branch."
140+
fi
141+
- name: post coverage report
142+
if: env.pull_request_id
143+
uses: thollander/actions-comment-pull-request@v3
144+
with:
145+
github-token: ${{ secrets.GITHUB_TOKEN }}
146+
comment-tag: coverage-report
147+
pr-number: ${{ env.pull_request_id }}
148+
message: |
149+
go-test-coverage report:
150+
```
151+
${{ fromJSON(steps.coverage.outputs.report) }}```
152+
153+
- name: "finally check coverage"
154+
if: steps.coverage.outcome == 'failure'
155+
shell: bash
156+
run: echo "coverage check failed" && exit 1
153157
```
154158
155-
## Generate Coverage Badge
156-
157-
Instructions for badge creation are available [here](./badge.md).
158-
159159
160160
---
161161

0 commit comments

Comments
 (0)