Skip to content

Commit eda241a

Browse files
committed
Add Codecov upload step to "Test Go" workflow
This will record the project's test coverage data on Codecov. Markup is provided for badges that will display the % coverage and link to the project's data.
1 parent bc14b21 commit eda241a

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

workflow-templates/dependabot/workflow-template-copies/.github/workflows/test-go-task.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
push:
1111
paths:
1212
- ".github/workflows/test-go-task.ya?ml"
13+
- "codecov.ya?ml"
1314
- "go.mod"
1415
- "go.sum"
1516
- "Taskfile.ya?ml"
@@ -18,6 +19,7 @@ on:
1819
pull_request:
1920
paths:
2021
- ".github/workflows/test-go-task.ya?ml"
22+
- "codecov.ya?ml"
2123
- "go.mod"
2224
- "go.sum"
2325
- "Taskfile.ya?ml"
@@ -54,3 +56,11 @@ jobs:
5456

5557
- name: Run tests
5658
run: task go:test
59+
60+
- name: Send unit tests coverage to Codecov
61+
if: matrix.operating-system == 'ubuntu-latest'
62+
uses: codecov/codecov-action@v2
63+
with:
64+
file: ./coverage_unit.txt
65+
flags: unit
66+
fail_ci_if_error: true

workflow-templates/test-go-task.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,23 @@ Markdown badge:
4040

4141
```markdown
4242
[![Test Go status](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/test-go-task.yml/badge.svg)](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/test-go-task.yml)
43+
[![Codecov](https://codecov.io/gh/REPO_OWNER/REPO_NAME/branch/main/graph/badge.svg)](https://codecov.io/gh/REPO_OWNER/REPO_NAME)
4344
```
4445

45-
Replace the `REPO_OWNER` and `REPO_NAME` placeholders in the URLs with the final repository owner and name ([example](https://raw.githubusercontent.com/arduino-libraries/ArduinoIoTCloud/master/README.md)).
46+
- Replace the `REPO_OWNER` and `REPO_NAME` placeholders in the URLs with the final repository owner and name ([example](https://raw.githubusercontent.com/arduino-libraries/ArduinoIoTCloud/master/README.md)).
47+
- If the coverage badge should reflect the coverage for a branch named something other than `main`, adjust the badge URL accordingly.
4648

4749
---
4850

4951
Asciidoc badge:
5052

5153
```adoc
5254
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/test-go-task.yml/badge.svg["Test Go status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/test-go-task.yml"]
55+
image:https://codecov.io/gh/{repository-owner}/{repository-name}/branch/main/graph/badge.svg["Codecov", link="https://codecov.io/gh/{repository-owner}/{repository-name}"]
5356
```
5457

55-
Define the `{repository-owner}` and `{repository-name}` attributes and use them throughout the readme ([example](https://raw.githubusercontent.com/arduino-libraries/WiFiNINA/master/README.adoc)).
58+
- Define the `{repository-owner}` and `{repository-name}` attributes and use them throughout the readme ([example](https://raw.githubusercontent.com/arduino-libraries/WiFiNINA/master/README.adoc)).
59+
- If the coverage badge should reflect the coverage for a branch named something other than `main`, adjust the badge URL accordingly.
5660
5761
## Commit message
5862

workflow-templates/test-go-task.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
push:
1111
paths:
1212
- ".github/workflows/test-go-task.ya?ml"
13+
- "codecov.ya?ml"
1314
- "go.mod"
1415
- "go.sum"
1516
- "Taskfile.ya?ml"
@@ -18,6 +19,7 @@ on:
1819
pull_request:
1920
paths:
2021
- ".github/workflows/test-go-task.ya?ml"
22+
- "codecov.ya?ml"
2123
- "go.mod"
2224
- "go.sum"
2325
- "Taskfile.ya?ml"
@@ -54,3 +56,11 @@ jobs:
5456

5557
- name: Run tests
5658
run: task go:test
59+
60+
- name: Send unit tests coverage to Codecov
61+
if: matrix.operating-system == 'ubuntu-latest'
62+
uses: codecov/codecov-action@v2
63+
with:
64+
file: ./coverage_unit.txt
65+
flags: unit
66+
fail_ci_if_error: true

0 commit comments

Comments
 (0)