Skip to content
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

Update test.yml Github Action to report coverage to sonarcloud #8712

Closed
wants to merge 2 commits into from
Closed
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
49 changes: 48 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,20 @@ jobs:
run: |
VERSION=$(echo $(git describe --tags) | sed 's/^v//') || VERSION=${GITHUB_SHA}
TESTS=$(cat pkgs.txt.part.${{ matrix.part }})
VERSION=$VERSION SKIP_WASM_WSL_TESTS="false" go test -race -mod=readonly -tags='ledger test_ledger_mock norace' $TESTS
VERSION=$VERSION SKIP_WASM_WSL_TESTS="false" go test -json -race -mod=readonly -tags='ledger test_ledger_mock norace' $TESTS
# re-run the tests to produce sonarcloud code coverage as covermode count is not compatible with -race option
- name: Code coverage report creation
run: |
VERSION=$(echo $(git describe --tags) | sed 's/^v//') || VERSION=${GITHUB_SHA}
TESTS=$(cat pkgs.txt.part.${{ matrix.part }})
VERSION=$VERSION SKIP_WASM_WSL_TESTS="false" go test -coverprofile=coverage.out -covermode=count -json -mod=readonly -tags='ledger test_ledger_mock norace' $TESTS > report.json;
- name: Archive code coverage results
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: |
coverage.out
report.json

e2e:
needs: get_diff
Expand Down Expand Up @@ -155,3 +168,37 @@ jobs:
with:
name: logs.tgz
path: ./logs.tgz

sonarCloudTrigger:
needs: go
name: SonarCloud Trigger
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@master
with:
fetch-depth: 0
- name: Download code coverage results
uses: actions/download-artifact@v4
with:
name: code-coverage-report
#path: app
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
with:
projectBaseDir: app
args: >
-Dsonar.projectKey=osmosis-labs-osmosis
-Dsonar.organization=osmosis-labs-polaris
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.go.coverage.reportPaths=coverage.out
-Dsonar.go.tests.reportPaths=report.json
-Dsonar.sources=.
-Dsonar.tests=.
-Dsonar.test.inclusions=**/*_test.go,**/testdata/**
-Dsonar.language=go
-Dsonar.go.exclusions=**/vendor/**,**/*_mock.go
-Dsonar.coverage.exclusions=**/mock*/**,**/mock*.go,commands/debug.go
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Comment on lines +172 to +204
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Update SonarCloud projectBaseDir to the repository root.

The app directory does not contain a go.mod file and includes multiple Go source files across various subdirectories. This suggests that app is not a standalone Go module but part of a larger monorepo structure.

Action Required:

  • Change projectBaseDir from app to . in the SonarCloud configuration to ensure that the entire repository is analyzed correctly.
with:
  projectBaseDir: .

This adjustment will help SonarCloud accurately assess the project's structure and dependencies.

Analysis chain

Good addition of SonarCloud integration, but check the projectBaseDir setting.

The new sonarCloudTrigger job is well-structured and comprehensive. It correctly depends on the go job, ensuring that code coverage results are available. The SonarCloud configuration covers essential aspects like coverage paths, test paths, and exclusions.

However, there's a potential issue:

The projectBaseDir is set to app (line 189), but it's not clear if this is the correct base directory for your project. This setting determines the root directory for SonarCloud analysis. If your project structure doesn't have an app directory at the root, this could lead to incorrect analysis results.

Please verify if app is the correct base directory. If not, you should adjust this setting to match your project structure, typically using . for the root of the repository.

To confirm the correct project structure, you can run:

This will display the directory structure, helping you determine the correct projectBaseDir setting.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the project structure
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//  /g' -e 's/^/    /' -e 's/-/|/'

Length of output: 8680


Script:

#!/bin/bash
# Check for go.mod in app directory
if [ -f app/go.mod ]; then
    echo "go.mod found in app directory."
else
    echo "go.mod not found in app directory."
fi

# List Go source files in app directory
echo "Listing Go source files in app:"
rg --files --glob "*.go" app

Length of output: 3406