Skip to content

[no-relnote] Enable Coveralls for code coverage #958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025

Conversation

ArangoGutierrez
Copy link
Collaborator

@ArangoGutierrez ArangoGutierrez commented Mar 4, 2025

Add Coveralls to track repo code coverage

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR enables CodeCov integration to track Go unit test coverage. It adds a new CodeCov upload step under the "test" job and makes minor adjustments to the GitHub Actions workflow configuration.

  • Added CodeCov action in the "test" job.
  • Configured environment variables for Go version extraction.
  • Maintained setup consistency across testing and build steps.

Reviewed Changes

File Description
.github/workflows/golang.yaml Added CodeCov step for coverage reporting and adjusted version setup

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

.github/workflows/golang.yaml:96

  • The variable substitution operator differs from the one in the test job (':='). Consider using the consistent syntax ':=' for extracting GOLANG_VERSION unless the differing behavior is intentional.
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV

@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@ArangoGutierrez ArangoGutierrez marked this pull request as draft March 4, 2025 11:21
@ArangoGutierrez
Copy link
Collaborator Author

umm let's leave this for later on, we might need to move Go actions to hosted runners if we want to pass the secret during PR

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}

- run: make test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to make coverage instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it actually makes sense from the perspective of a Makefile file functionality; make coverage would actually generate an output artifact. So I am not against it, I'll leave it as your call

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need the coverage.out artifact?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it actually makes sense from the perspective of a Makefile file functionality; make coverage would actually generate an output artifact. So I am not against it, I'll leave it as your call

Sorry, I don't understand what you're saying here. We have two targets:

  • make test
  • make coverage

The first generates coverage.out and the second filters out coverage related to mocks to generate a .no-mocks file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I was not aware of the make coverage but for codecov we need the output file from make test

with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out
fail_ci_if_error: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to block CI on an external system failing?

@elezar
Copy link
Member

elezar commented Mar 6, 2025

umm let's leave this for later on, we might need to move Go actions to hosted runners if we want to pass the secret during PR

That's not true. Secrets are not available on PRs from forks, but should be available from the pull-request branches. (or is this not essentially the same issue as publishing images). Another note, we only need to run the "upload to codecove" step in the internal runners consuming the coverage file generated in a previous step.

@ArangoGutierrez
Copy link
Collaborator Author

umm let's leave this for later on, we might need to move Go actions to hosted runners if we want to pass the secret during PR

That's not true. Secrets are not available on PRs from forks, but should be available from the pull-request branches. (or is this not essentially the same issue as publishing images). Another note, we only need to run the "upload to codecove" step in the internal runners consuming the coverage file generated in a previous step.

ture, I forgot about copy-pr-bot I was thinking in the old way o passing secrets. still will retake this PR after we cut the release

@ArangoGutierrez ArangoGutierrez marked this pull request as ready for review March 6, 2025 14:28
@ArangoGutierrez
Copy link
Collaborator Author

/ok to test

@ArangoGutierrez ArangoGutierrez force-pushed the codecov branch 2 times, most recently from f8b888e to ce27020 Compare March 6, 2025 14:34
@ArangoGutierrez
Copy link
Collaborator Author

Here's a look of how we would be able to visualize the results

https://app.codecov.io/gh/NVIDIA/nvidia-container-toolkit

image

@ArangoGutierrez ArangoGutierrez requested a review from elezar March 6, 2025 14:40
@ArangoGutierrez
Copy link
Collaborator Author

@tariq1890 if you like this, we could replace the coversall implementation on the other repos

@elezar
Copy link
Member

elezar commented Mar 7, 2025

@ArangoGutierrez as a general question, how does CodeCov compare to coversall that @tariq1890 was using? I was under the impression that CodeCov is a paid service.

@ArangoGutierrez
Copy link
Collaborator Author

@ArangoGutierrez as a general question, how does CodeCov compare to coversall that @tariq1890 was using? I was under the impression that CodeCov is a paid service.

It is free for OSS repos.

tariq1890
tariq1890 previously approved these changes Mar 7, 2025
@ArangoGutierrez
Copy link
Collaborator Author

@elezar, any thoughts on this?

@elezar
Copy link
Member

elezar commented Apr 2, 2025

@elezar, any thoughts on this?

Please confirm whether this can be run from a PR through the copy bot? You also have not answered by question as to how this compares to coversall (or other tools).

@ArangoGutierrez
Copy link
Collaborator Author

coversall

Here's a detailed comparison

Comparison: Coveralls vs. Codecov (GitHub Actions – Code Coverage)

Feature Coveralls Codecov
GitHub Integration Native support via GitHub Actions, simple setup Native GitHub Actions support, rich status checks
Language Support Broad (C, C++, Go, Python, etc.) Very broad (Go, Python, JVM, Swift, LLVM, etc.)
Coverage Format Support LCOV, Cobertura, SimpleCov LCOV, Cobertura, Jacoco, GCOV, LLVM, etc.
UI & Reporting Basic UI, focuses on coverage delta Advanced UI: trends, per-line coverage, PR annotations
Monorepo Support Limited Strong monorepo support via flags and path-based filters
Test File Upload GitHub Action or manual upload Robust CLI and GitHub Action
Security & Compliance Basic OAuth / GitHub App SOC2, audit logs, role-based permissions (better enterprise fit)
Free for Open Source ✅ Yes ✅ Yes
Private Repo Pricing Limited free tier, paid plans available Free tier for small teams, paid plans for more features

Summary:

  • Coveralls: Good for simple projects needing straightforward coverage tracking.
  • Codecov: Better suited for complex or large codebases (e.g., monorepos), with more detailed insights and security options.

References:

@ArangoGutierrez ArangoGutierrez self-assigned this Apr 10, 2025
@ArangoGutierrez
Copy link
Collaborator Author

@elezar PTAL

@ArangoGutierrez ArangoGutierrez changed the title [no-relnote] Enable CodeCov [no-relnote] Enable Coveralls for code coverage May 22, 2025
@ArangoGutierrez ArangoGutierrez requested a review from Copilot May 22, 2025 16:01
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces a code coverage reporting step into the CI pipeline by uploading coverage reports to Codecov.

  • Added a new Codecov upload step under the "Unit test" job.
  • Introduced minor formatting adjustments and a change in the parameter expansion operator in the build job.
Comments suppressed due to low confidence (1)

.github/workflows/golang.yaml:96

  • The parameter expansion operator in the build job has changed from ':=' in the test job to '?='. This inconsistency might result in unintended behavior. Consider standardizing the operator across both jobs.
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV

@ArangoGutierrez ArangoGutierrez added the testing issue/PR to fix/edit/create/enhance a project unit/e2e test label May 23, 2025
Makefile Outdated
@@ -128,6 +146,12 @@ coverage: test
cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks
go tool cover -func=$(COVERAGE_FILE).no-mocks

cov-report: gcov2lcov test ## Build test coverage report in lcov format
$(GCOV2LCOV) -infile coverage.out -outfile lcov.info
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We should add lcov.info to the .gitignore

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds Coveralls integration for repo-wide code coverage tracking by extending Makefile targets and CI workflow.

  • Updated MAKE_TARGETS to include cov-report and gcov2lcov.
  • Defined a go-install-tool helper in the Makefile to install gcov2lcov and convert coverage.out into lcov.info.
  • Modified GitHub Actions to run make cov-report and upload lcov.info to Coveralls.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Makefile Added cov-report, gcov2lcov targets, and go-install-tool; updated MAKE_TARGETS.
.github/workflows/golang.yaml Added steps to generate LCov report and upload to Coveralls; replaced direct make test with make cov-report.
Comments suppressed due to low confidence (1)

.github/workflows/golang.yaml:95

  • The prefix stripping here uses ?=, but earlier steps strip :=. This mismatch may prevent the Go version from being set correctly; align this to ${GOLANG_VERSION##GOLANG_VERSION := }.
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV

Comment on lines 75 to 82
- name: Generate coverage report
run: make cov-report

- name: Upload to Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: lcov.info
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the conversion required? According to https://github.com/coverallsapp/coverage-reporter?tab=readme-ov-file#built-in-support there is no built-in support for golang. Was that not working as expected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right, we can simply upload the coverage.out file.

@ArangoGutierrez ArangoGutierrez force-pushed the codecov branch 4 times, most recently from ae151c8 to 46494a9 Compare May 23, 2025 10:10
@ArangoGutierrez ArangoGutierrez requested review from elezar and Copilot May 23, 2025 10:12
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Coveralls integration to track the repository's code coverage.

  • Introduces tool configuration in the Makefile for handling coverage reports.
  • Adds new workflow steps in the GitHub Actions configuration to generate and upload coverage reports to Coveralls.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Makefile Adds tool configuration for gcov2lcov and version pinning.
.github/workflows/golang.yaml Adds steps to generate coverage reports and upload to Coveralls; note potential variable substitution issue.
Comments suppressed due to low confidence (1)

.github/workflows/golang.yaml:95

  • The variable manipulation appears to contain a typo ('?=' instead of ':='), which may lead to unexpected behavior. Please update it to match the syntax used in the test job.
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV

uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set to file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does file work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to make a similar change to the GPU Operator and k8s-operator-libs. cc @tariq1890

Makefile Outdated
Comment on lines 70 to 74
# Tools
TOOLSDIR=$(CURDIR)/bin
GCOV2LCOV ?= $(TOOLSDIR)/gcov2lcov
GCOV2LCOV_VERSION ?= v1.1.1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Member

@elezar elezar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also update the makefile as follows:

diff --git a/Makefile b/Makefile
index ac491762..86433fa2 100644
--- a/Makefile
+++ b/Makefile
@@ -122,11 +122,11 @@ licenses:
 
 COVERAGE_FILE := coverage.out
 test: build cmds
-	go test -coverprofile=$(COVERAGE_FILE) $(MODULE)/...
+	go test -coverprofile=$(COVERAGE_FILE).with-mocks $(MODULE)/...
 
 coverage: test
-	cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks
-	go tool cover -func=$(COVERAGE_FILE).no-mocks
+	cat $(COVERAGE_FILE).with-mocks | grep -v "_mock.go" > $(COVERAGE_FILE)
+	go tool cover -func=$(COVERAGE_FILE)
 
 generate:
 	go generate $(MODULE)/...

So that make coverage generates a coverage.out file that does not include the generated mocks.

.gitignore Outdated
@@ -9,3 +9,4 @@
/release-*
/bin
/toolkit-test
/lcov.info
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also no longer required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ArangoGutierrez
Copy link
Collaborator Author

Let's also update the makefile as follows:

diff --git a/Makefile b/Makefile
index ac491762..86433fa2 100644
--- a/Makefile
+++ b/Makefile
@@ -122,11 +122,11 @@ licenses:
 
 COVERAGE_FILE := coverage.out
 test: build cmds
-	go test -coverprofile=$(COVERAGE_FILE) $(MODULE)/...
+	go test -coverprofile=$(COVERAGE_FILE).with-mocks $(MODULE)/...
 
 coverage: test
-	cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks
-	go tool cover -func=$(COVERAGE_FILE).no-mocks
+	cat $(COVERAGE_FILE).with-mocks | grep -v "_mock.go" > $(COVERAGE_FILE)
+	go tool cover -func=$(COVERAGE_FILE)
 
 generate:
 	go generate $(MODULE)/...

So that make coverage generates a coverage.out file that does not include the generated mocks.

Done

@ArangoGutierrez ArangoGutierrez requested a review from elezar May 23, 2025 11:22
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
- run: make test

- name: Generate coverage report
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This also runs the tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited

Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
Copy link
Contributor

@tariq1890 tariq1890 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@elezar elezar merged commit c8c2216 into NVIDIA:main May 27, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing issue/PR to fix/edit/create/enhance a project unit/e2e test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants