From eda241ac698a80fa48ca90d23a876c159c42cce4 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 6 Aug 2021 00:35:15 -0700 Subject: [PATCH] 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. --- .../.github/workflows/test-go-task.yml | 10 ++++++++++ workflow-templates/test-go-task.md | 8 ++++++-- workflow-templates/test-go-task.yml | 10 ++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/workflow-templates/dependabot/workflow-template-copies/.github/workflows/test-go-task.yml b/workflow-templates/dependabot/workflow-template-copies/.github/workflows/test-go-task.yml index 90194501..a3a83c6e 100644 --- a/workflow-templates/dependabot/workflow-template-copies/.github/workflows/test-go-task.yml +++ b/workflow-templates/dependabot/workflow-template-copies/.github/workflows/test-go-task.yml @@ -10,6 +10,7 @@ on: push: paths: - ".github/workflows/test-go-task.ya?ml" + - "codecov.ya?ml" - "go.mod" - "go.sum" - "Taskfile.ya?ml" @@ -18,6 +19,7 @@ on: pull_request: paths: - ".github/workflows/test-go-task.ya?ml" + - "codecov.ya?ml" - "go.mod" - "go.sum" - "Taskfile.ya?ml" @@ -54,3 +56,11 @@ jobs: - name: Run tests run: task go:test + + - name: Send unit tests coverage to Codecov + if: matrix.operating-system == 'ubuntu-latest' + uses: codecov/codecov-action@v2 + with: + file: ./coverage_unit.txt + flags: unit + fail_ci_if_error: true diff --git a/workflow-templates/test-go-task.md b/workflow-templates/test-go-task.md index 5c5ff8b1..143d7087 100644 --- a/workflow-templates/test-go-task.md +++ b/workflow-templates/test-go-task.md @@ -40,9 +40,11 @@ Markdown badge: ```markdown [![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) +[![Codecov](https://codecov.io/gh/REPO_OWNER/REPO_NAME/branch/main/graph/badge.svg)](https://codecov.io/gh/REPO_OWNER/REPO_NAME) ``` -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)). +- 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)). +- If the coverage badge should reflect the coverage for a branch named something other than `main`, adjust the badge URL accordingly. --- @@ -50,9 +52,11 @@ Asciidoc badge: ```adoc 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"] +image:https://codecov.io/gh/{repository-owner}/{repository-name}/branch/main/graph/badge.svg["Codecov", link="https://codecov.io/gh/{repository-owner}/{repository-name}"] ``` -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)). +- 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)). +- If the coverage badge should reflect the coverage for a branch named something other than `main`, adjust the badge URL accordingly. ## Commit message diff --git a/workflow-templates/test-go-task.yml b/workflow-templates/test-go-task.yml index 90194501..a3a83c6e 100644 --- a/workflow-templates/test-go-task.yml +++ b/workflow-templates/test-go-task.yml @@ -10,6 +10,7 @@ on: push: paths: - ".github/workflows/test-go-task.ya?ml" + - "codecov.ya?ml" - "go.mod" - "go.sum" - "Taskfile.ya?ml" @@ -18,6 +19,7 @@ on: pull_request: paths: - ".github/workflows/test-go-task.ya?ml" + - "codecov.ya?ml" - "go.mod" - "go.sum" - "Taskfile.ya?ml" @@ -54,3 +56,11 @@ jobs: - name: Run tests run: task go:test + + - name: Send unit tests coverage to Codecov + if: matrix.operating-system == 'ubuntu-latest' + uses: codecov/codecov-action@v2 + with: + file: ./coverage_unit.txt + flags: unit + fail_ci_if_error: true