From a7430478497f62edb9e7089321969fb4beba13b7 Mon Sep 17 00:00:00 2001 From: Jean Deruelle Date: Tue, 17 Sep 2024 19:59:01 +0200 Subject: [PATCH 1/2] Update #8711 Update test.yml Github Action to report code analysis and unit test coverage to sonarcloud --- .github/workflows/test.yml | 43 +++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d9ec84eefda..1e641f5079b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -103,7 +103,14 @@ 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 -coverprofile=coverage.out -covermode=count -json -race -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 @@ -155,3 +162,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 }} From 629cab4430674d71a2fbbe9f4ae907a6a88ff73f Mon Sep 17 00:00:00 2001 From: Jean Deruelle Date: Wed, 18 Sep 2024 10:22:54 +0200 Subject: [PATCH 2/2] Update test.yml to fix incompatibility between covermode and race flags --- .github/workflows/test.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1e641f5079b..2ccf114a1a9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -103,7 +103,13 @@ 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 -coverprofile=coverage.out -covermode=count -json -race -mod=readonly -tags='ledger test_ledger_mock norace' $TESTS > report.json; + 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: