From cd66009e5c47c429ff27fb349434e9c20b6d7e15 Mon Sep 17 00:00:00 2001 From: Oleg Balunenko Date: Mon, 16 Nov 2026 01:07:14 +0400 Subject: [PATCH] ci: bring back the SonarCloud scan #230 dropped the scan, and Sonar has not analyzed anything since. Restore it in the reports job with its inputs: the coverage profile, the go test JSON report and the golangci-lint checkstyle report. The checkstyle report is now requested with a flag in that one step, not in .golangci.yml, so local lint runs no longer leave linters-report.xml behind. sonar-project.properties drops the stale projectVersion and the vendor/ exclusions, as vendor/ is gone. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/go.yml | 19 +++++++++++++++++++ .gitignore | 2 ++ README.md | 1 + scripts/tests/coverage.sh | 2 +- sonar-project.properties | 31 +++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 sonar-project.properties diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index bacca0ba..ca8defda 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -143,11 +143,25 @@ jobs: go version shell: bash + # Also writes tests-report.json for Sonar. - name: Test coverage run: | make test-cover shell: bash + - name: Get golangci-lint version + id: golangci-lint + run: | + echo "version=$(awk '$1 == "github.com/golangci/golangci-lint/v2" { print $2 }' tools/golangci-lint/go.mod)" >> "$GITHUB_OUTPUT" + shell: bash + + # The checkstyle report is for Sonar only, so the flag is here and not in .golangci.yml. + - name: Prepare lint report + uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 + with: + version: ${{ steps.golangci-lint.outputs.version }} + args: --config .golangci.yml --output.checkstyle.path=linters-report.xml + # Codecov rejects tokenless uploads to the default branch; authenticate with OIDC. - name: Cover report upload if: success() @@ -157,3 +171,8 @@ jobs: disable_search: true use_oidc: true fail_ci_if_error: true + + - name: SonarCloud report upload + uses: SonarSource/sonarqube-scan-action@59202af334b4ba7b5db01b701b8e79f8b3bef0f4 # v8.5.0 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.gitignore b/.gitignore index dd2247dd..c7b0a8a9 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ dist/ coverage/ .DS_Store README_doc.md +tests-report.json +linters-report.xml .vscode/ # Codecov CLI downloaded by codecov-action in CI diff --git a/README.md b/README.md index 77b94654..92d4a36b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Go Reference](https://pkg.go.dev/badge/github.com/obalunenko/getenv.svg)](https://pkg.go.dev/github.com/obalunenko/getenv) [![Go Report Card](https://goreportcard.com/badge/github.com/obalunenko/getenv)](https://goreportcard.com/report/github.com/obalunenko/getenv) [![codecov](https://codecov.io/gh/obalunenko/getenv/branch/master/graph/badge.svg)](https://codecov.io/gh/obalunenko/getenv) +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=obalunenko_getenv&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=obalunenko_getenv) # getenv diff --git a/scripts/tests/coverage.sh b/scripts/tests/coverage.sh index a52a5953..ef300988 100755 --- a/scripts/tests/coverage.sh +++ b/scripts/tests/coverage.sh @@ -15,6 +15,6 @@ echo "${SCRIPT_NAME} is running... " rm -rf "${COVER_DIR}" mkdir -p "${COVER_DIR}" -go test --count=1 -coverprofile "${COVER_DIR}/full.cov" -covermode=atomic ./... +go test --count=1 -coverprofile "${COVER_DIR}/full.cov" -covermode=atomic -json ./... >tests-report.json echo "${SCRIPT_NAME} is done... " diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..6d110061 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,31 @@ +# ===================================================== +# Standard properties +# ===================================================== + +sonar.projectKey=obalunenko_getenv +sonar.projectName=getenv +sonar.organization=obalunenko + +sonar.host.url=https://sonarcloud.io +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +# This property is optional if sonar.modules is set. +sonar.sources=. +sonar.exclusions=**/*_test.go + +sonar.tests=. +sonar.test.inclusions=**/*_test.go +# ===================================================== +# Meta-data for the project +# ===================================================== + +sonar.links.homepage=https://github.com/obalunenko/getenv +sonar.links.ci=https://github.com/obalunenko/getenv/actions +sonar.links.issue=https://github.com/obalunenko/getenv/issues + +# ===================================================== +# Properties specific to Go +# ===================================================== + +sonar.go.golangci-lint.reportPaths=linters-report.xml +sonar.go.tests.reportPaths=tests-report.json +sonar.go.coverage.reportPaths=coverage/full.cov \ No newline at end of file