Skip to content

[CONFIG] [REFACTOR] [Github Actions] codecov and sonarcloud now runs … #367

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
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

fixes:
- "gon.cl/algorithms/::"
- "/home/runner/work/algorithm-exercises-go/algorithm-exercises-go/::"
45 changes: 40 additions & 5 deletions .github/workflows/go-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:

jobs:

coverage:
build-and-test:
name: "Go CI Tests Coverage"
strategy:
fail-fast: false
Expand All @@ -41,21 +41,56 @@ jobs:
run: >
go test -v
-covermode=atomic
-coverprofile="coverage.out"
-coverprofile="coverage/coverage.out"
./exercises/...

- name: Coverage
run: go tool cover -func="coverage.out"
run: go tool cover -func="coverage/coverage.out"

- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage

codecov:
name: Upload to Codecov
runs-on: ubuntu-24.04
needs: build-and-test

steps:
- name: Download coverage artifact
uses: actions/download-artifact@v5
with:
name: coverage-report
path: coverage

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v5
with:
files: coverage/coverage.out
token: ${{ secrets.CODECOV_TOKEN }} # required
verbose: true # optional (default = false)

- name: Analyze with SonarCloud
sonarqube:
name: Analyze with SonarQube
runs-on: ubuntu-24.04
needs: build-and-test

steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Download coverage artifact
uses: actions/download-artifact@v5
with:
name: coverage-report
path: coverage

- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# Needed to get PR information, if any
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ COPY ./go.mod ${WORKDIR}/
COPY ./go.sum ${WORKDIR}/
COPY ./Makefile ${WORKDIR}/

RUN mkdir ${WORKDIR}/coverage

# CMD []
###############################################################################
FROM development AS builder
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ format:
$(GO) run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix ./...

coverage.out: env dependencies
$(GOTEST) -v -covermode=atomic -coverprofile="coverage.out" ./exercises/...
$(GOTEST) -v -covermode=atomic -coverprofile="coverage/coverage.out" ./exercises/...

test: env dependencies coverage.out
$(GOCOVER) -func=coverage.out
$(GOCOVER) -func=coverage/coverage.out

coverage: test

coverage/html: coverage.out
$(GOCOVER) -html=coverage.out -o ./coverage/coverage.html
$(GOCOVER) -html=coverage/coverage.out -o ./coverage/coverage.html
open ./coverage/coverage.html

outdated:
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sonar.exclusions=
sonar.tests=exercises
sonar.test.inclusions=**/*_test.go

sonar.go.coverage.reportPaths=coverage.out
sonar.go.coverage.reportPaths=coverage/coverage.out

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
Expand Down