From ae91105fec27396474575140dff7480adc44128a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 23 Nov 2022 11:47:18 +0100 Subject: [PATCH] ci: configure monorepo sonarcloud (#13944) --- .build.sh | 44 -- .codecov.yml | 62 --- .github/workflows/build.yml | 1 - .github/workflows/sims.yml | 16 - .github/workflows/test-e2e-skip.yml | 15 - .github/workflows/test-e2e.yml | 30 -- .github/workflows/test-integration-skip.yml | 15 - .github/workflows/test-integration.yml | 30 -- .github/workflows/test-legacy.yml | 78 ---- .github/workflows/test-skip.yml | 111 +++++ .github/workflows/test.yml | 456 ++++++++++++++------ .gitignore | 3 +- CONTRIBUTING.md | 58 ++- Makefile | 13 +- client/v2/sonar-project.properties | 15 + contrib/test_cover.sh | 14 - core/sonar-project.properties | 15 + depinject/sonar-project.properties | 15 + errors/sonar-project.properties | 15 + go.work.example | 2 +- math/sonar-project.properties | 15 + scripts/module-tests.sh | 48 --- simapp/sonar-project.properties | 15 + sonar-project.properties | 4 +- tests/Makefile | 6 + tools/cosmovisor/sonar-project.properties | 15 + tools/rosetta/sonar-project.properties | 15 + tx/sonar-project.properties | 15 + 28 files changed, 633 insertions(+), 508 deletions(-) delete mode 100755 .build.sh delete mode 100644 .codecov.yml delete mode 100644 .github/workflows/test-e2e-skip.yml delete mode 100644 .github/workflows/test-e2e.yml delete mode 100644 .github/workflows/test-integration-skip.yml delete mode 100644 .github/workflows/test-integration.yml delete mode 100644 .github/workflows/test-legacy.yml create mode 100644 .github/workflows/test-skip.yml create mode 100644 client/v2/sonar-project.properties delete mode 100644 contrib/test_cover.sh create mode 100644 core/sonar-project.properties create mode 100644 depinject/sonar-project.properties create mode 100644 errors/sonar-project.properties create mode 100644 math/sonar-project.properties delete mode 100644 scripts/module-tests.sh create mode 100644 simapp/sonar-project.properties create mode 100644 tools/cosmovisor/sonar-project.properties create mode 100644 tools/rosetta/sonar-project.properties create mode 100644 tx/sonar-project.properties diff --git a/.build.sh b/.build.sh deleted file mode 100755 index 1f7a148837..0000000000 --- a/.build.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -set -ue - -# Expect the following envvars to be set: -# - APP -# - VERSION -# - COMMIT -# - TARGET_OS -# - LEDGER_ENABLED -# - DEBUG - -# Source builder's functions library -. /usr/local/share/tendermint/buildlib.sh - -# These variables are now available -# - BASEDIR -# - OUTDIR - -# Build for each os-architecture pair -for platform in ${TARGET_PLATFORMS} ; do - # This function sets GOOS, GOARCH, and OS_FILE_EXT environment variables - # according to the build target platform. OS_FILE_EXT is empty in all - # cases except when the target platform is 'windows'. - setup_build_env_for_platform "${platform}" - - make clean - echo Building for $(go env GOOS)/$(go env GOARCH) >&2 - GOROOT_FINAL="$(go env GOROOT)" \ - make build \ - LDFLAGS=-buildid=${VERSION} \ - VERSION=${VERSION} \ - COMMIT=${COMMIT} \ - LEDGER_ENABLED=${LEDGER_ENABLED} - mv ./build/${APP}${OS_FILE_EXT} ${OUTDIR}/${APP}-${VERSION}-$(go env GOOS)-$(go env GOARCH)${OS_FILE_EXT} - - # This function restore the build environment variables to their - # original state. - restore_build_env -done - -# Generate and display build report. -generate_build_report -cat ${OUTDIR}/build_report diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index 97c516774b..0000000000 --- a/.codecov.yml +++ /dev/null @@ -1,62 +0,0 @@ -# -# This codecov.yml is the default configuration for -# all repositories on Codecov. You may adjust the settings -# below in your own codecov.yml in your repository. -# -coverage: - precision: 2 - round: down - range: 70...100 - - status: - # Learn more at https://docs.codecov.io/docs/commit-status - project: - default: - threshold: 1% # allow this much decrease on project - app: - target: 70% - flags: - - app - modules: - target: 70% - flags: - - modules - client: - flags: - - client - changes: false - -comment: - layout: "reach, diff, files" - behavior: default # update if exists else create new - require_changes: true - -flags: - app: - paths: - - "app/" - - "baseapp/" - modules: - paths: - - "x/" - - "!x/**/client/" # ignore client package - client: - paths: - - "client/" - - "x/**/client/" - -ignore: - - "docs" - - "*.md" - - "*.rst" - - "**/*.pb.go" - - "types/*.pb.go" - - "tests/*" - - "tests/**/*" - - "x/**/*.pb.go" - - "x/**/test_common.go" - - "scripts/" - - "contrib" - - "**/*.pb.gw.go" - - "**/*.pulsar.go" - - "tests/mocks/*.go" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 00e45a2372..7227bf9e3c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,6 +36,5 @@ jobs: run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make build - name: Build Legacy run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false COSMOS_BUILD_OPTIONS=legacy make build - - name: Build Cosmovisor run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make cosmovisor diff --git a/.github/workflows/sims.yml b/.github/workflows/sims.yml index 5942c5fff2..36e581c0d8 100644 --- a/.github/workflows/sims.yml +++ b/.github/workflows/sims.yml @@ -15,7 +15,6 @@ jobs: build: permissions: contents: read # for actions/checkout to fetch code - pull-requests: read # for technote-space/get-diff-action to get git reference runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, 'skip-sims')" steps: @@ -23,21 +22,6 @@ jobs: - uses: actions/setup-go@v3 with: go-version: 1.19.2 - - uses: technote-space/get-diff-action@v6.1.1 - with: - PATTERNS: | - **/**.go - go.mod - go.sum - - name: Get data from Go build cache - if: ${{ false }} - uses: actions/cache@v3 - with: - path: | - ~/go/pkg/mod - ~/.cache/golangci-lint - ~/.cache/go-build - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - run: make build - name: Install runsim run: go install github.com/cosmos/tools/cmd/runsim@v1.0.0 diff --git a/.github/workflows/test-e2e-skip.yml b/.github/workflows/test-e2e-skip.yml deleted file mode 100644 index 41ab541522..0000000000 --- a/.github/workflows/test-e2e-skip.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Tests E2E -# This workflow allows to skip the e2e step if the PR does not contain any changes to the code -# See https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks -on: - pull_request: - paths-ignore: - - "**/*.go" - - "go.mod" - - "go.sum" - -jobs: - test-e2e: - runs-on: ubuntu-latest - steps: - - run: 'echo "No e2e tests required"' diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml deleted file mode 100644 index bb7f5eea0c..0000000000 --- a/.github/workflows/test-e2e.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Tests E2E -# This workflow is run on pushes to main & every Pull Requests where a .go, .mod, .sum have been changed -on: - pull_request: - paths: - - "**/*.go" - - "go.mod" - - "go.sum" - push: - branches: - - main - paths: - - "**/*.go" - - "go.mod" - - "go.sum" - -permissions: - contents: read - -jobs: - test-e2e: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 - with: - go-version: 1.19.2 - - name: e2e tests - run: | - make test-e2e diff --git a/.github/workflows/test-integration-skip.yml b/.github/workflows/test-integration-skip.yml deleted file mode 100644 index e8621fdc5e..0000000000 --- a/.github/workflows/test-integration-skip.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Tests Integration -# This workflow allows to skip the integration step if the PR does not contain any changes to the code -# See https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks -on: - pull_request: - paths-ignore: - - "**/*.go" - - "go.mod" - - "go.sum" - -jobs: - test-integration: - runs-on: ubuntu-latest - steps: - - run: 'echo "No integration tests required"' diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml deleted file mode 100644 index bbd866941e..0000000000 --- a/.github/workflows/test-integration.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Tests Integration -# This workflow is run on pushes to main & every Pull Requests where a .go, .mod, .sum have been changed -on: - pull_request: - paths: - - "**/*.go" - - "go.mod" - - "go.sum" - push: - branches: - - main - paths: - - "**/*.go" - - "go.mod" - - "go.sum" - -permissions: - contents: read - -jobs: - test-integration: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 - with: - go-version: 1.19.2 - - name: integration tests - run: | - make test-integration diff --git a/.github/workflows/test-legacy.yml b/.github/workflows/test-legacy.yml deleted file mode 100644 index d9ca0f6a4a..0000000000 --- a/.github/workflows/test-legacy.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: Tests (App V1) -on: - schedule: - - cron: "0 0,12 * * *" - release: - types: [published] - -concurrency: - group: ci-${{ github.ref }}-tests-legacy - cancel-in-progress: true - -jobs: - test-submodules: - runs-on: ubuntu-latest - container: tendermintdev/docker-tm-db-testing - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 - with: - go-version: 1.19.2 - - name: Run submodule tests and create test coverage profile. - run: bash scripts/module-tests.sh - - uses: actions/upload-artifact@v3 - with: - name: "${{ github.sha }}-go-submodules-coverage" - path: ./coverage-go-submod-profile.out - - split-test-files: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 - with: - go-version: 1.19.2 - - name: Create a file with all core Cosmos SDK pkgs - run: go list ./... > pkgs.txt - - name: Split pkgs into 4 files - run: split -d -n l/4 pkgs.txt pkgs.txt.part. - # cache multiple - - uses: actions/upload-artifact@v3 - with: - name: "${{ github.sha }}-00" - path: ./pkgs.txt.part.00 - - uses: actions/upload-artifact@v3 - with: - name: "${{ github.sha }}-01" - path: ./pkgs.txt.part.01 - - uses: actions/upload-artifact@v3 - with: - name: "${{ github.sha }}-02" - path: ./pkgs.txt.part.02 - - uses: actions/upload-artifact@v3 - with: - name: "${{ github.sha }}-03" - path: ./pkgs.txt.part.03 - - tests: - runs-on: ubuntu-latest - needs: split-test-files - strategy: - fail-fast: false - matrix: - part: ["00", "01", "02", "03"] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 - with: - go-version: 1.19.2 - - uses: actions/download-artifact@v3 - with: - name: "${{ github.sha }}-${{ matrix.part }}" - - name: test & coverage report creation - run: | - cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 30m -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tags='app_v1 norace ledger test_ledger_mock' - - uses: actions/upload-artifact@v3 - with: - name: "${{ github.sha }}-${{ matrix.part }}-coverage" - path: ./${{ matrix.part }}profile.out diff --git a/.github/workflows/test-skip.yml b/.github/workflows/test-skip.yml new file mode 100644 index 0000000000..00acbb2386 --- /dev/null +++ b/.github/workflows/test-skip.yml @@ -0,0 +1,111 @@ +name: Tests / Code Coverage +# This workflow allows to skip the test step if the PR does not contain any changes to the code +# See https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks +on: + pull_request: + paths-ignore: + - "**/*.go" + - "go.mod" + - "go.sum" + +concurrency: + group: ci-${{ github.ref }}-tests + cancel-in-progress: true + +jobs: + test-submodules: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + part: ["00", "01", "02", "03"] + steps: + - run: 'echo "No tests required"' + + tests-legacy: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + part: ["00", "01", "02", "03"] + steps: + - run: 'echo "No tests required"' + + test-integration: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + test-e2e: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + repo-analysis: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + liveness-test: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + test-sim-nondeterminism: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + ################################## + #### Cosmos SDK Go Submodules #### + ################################## + + test-clientv2: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + test-core: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + test-depinject: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + test-errors: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + test-math: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + test-simapp: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + test-tx: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + test-rosetta: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' + + test-cosmovisor: + runs-on: ubuntu-latest + steps: + - run: 'echo "No tests required"' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9f3fb504ca..80951dab50 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,11 +1,17 @@ name: Tests / Code Coverage -# Tests / Code Coverage workflow runs unit tests and uploads a code coverage report -# This workflow is run on pushes to main & every Pull Requests where a .go, .mod, .sum have been changed on: pull_request: + paths: + - "**/*.go" + - "go.mod" + - "go.sum" push: branches: - main + paths: + - "**/*.go" + - "go.mod" + - "go.sum" permissions: contents: read @@ -15,40 +21,6 @@ concurrency: cancel-in-progress: true jobs: - test-submodules: - runs-on: ubuntu-latest - container: tendermintdev/docker-tm-db-testing - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 - with: - go-version: 1.19.2 - - uses: technote-space/get-diff-action@v6.1.1 - id: git_diff - with: - PATTERNS: | - **/**.go - go.mod - go.sum - - name: Get data from Go build cache - # if: env.GIT_DIFF - if: ${{ false }} - uses: actions/cache@v3 - with: - path: | - ~/go/pkg/mod - ~/.cache/golangci-lint - ~/.cache/go-build - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - - name: Run submodule tests and create test coverage profile. - # GIT_DIFF is passed to the scripts - run: bash scripts/module-tests.sh - if: env.GIT_DIFF - - uses: actions/upload-artifact@v3 - with: - name: "${{ github.sha }}-go-submodules-coverage" - path: ./coverage-go-submod-profile.out - split-test-files: runs-on: ubuntu-latest steps: @@ -60,7 +32,6 @@ jobs: run: go list ./... > pkgs.txt - name: Split pkgs into 4 files run: split -d -n l/4 pkgs.txt pkgs.txt.part. - # cache multiple - uses: actions/upload-artifact@v3 with: name: "${{ github.sha }}-00" @@ -90,100 +61,97 @@ jobs: - uses: actions/setup-go@v3 with: go-version: 1.19.2 - - uses: technote-space/get-diff-action@v6.1.1 - with: - PATTERNS: | - **/**.go - go.mod - go.sum - - name: Get data from Go build cache - # if: env.GIT_DIFF - if: ${{ false }} - uses: actions/cache@v3 - with: - path: | - ~/go/pkg/mod - ~/.cache/golangci-lint - ~/.cache/go-build - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - uses: actions/download-artifact@v3 with: name: "${{ github.sha }}-${{ matrix.part }}" - if: env.GIT_DIFF - name: test & coverage report creation run: | cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -race -timeout 30m -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tags='ledger test_ledger_mock' - if: env.GIT_DIFF - uses: actions/upload-artifact@v3 with: name: "${{ github.sha }}-${{ matrix.part }}-coverage" path: ./${{ matrix.part }}profile.out + tests-legacy: + runs-on: ubuntu-latest + needs: split-test-files + strategy: + fail-fast: false + matrix: + part: ["00", "01", "02", "03"] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: actions/download-artifact@v3 + with: + name: "${{ github.sha }}-${{ matrix.part }}" + - name: test app (v1) + run: | + cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 30m -tags='app_v1 norace ledger test_ledger_mock' + + test-integration: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - name: integration tests + run: | + make test-integration-cov + - uses: actions/upload-artifact@v3 + with: + name: "${{ github.sha }}-integration-coverage" + path: ./tests/integration-profile.out + + test-e2e: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - name: e2e tests + run: | + make test-e2e-cov + - uses: actions/upload-artifact@v3 + with: + name: "${{ github.sha }}-e2e-coverage" + path: ./tests/e2e-profile.out + repo-analysis: runs-on: ubuntu-latest - needs: tests + needs: [tests, tests-integration, tests-e2e] steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: technote-space/get-diff-action@v6.1.1 - with: - PATTERNS: | - **/**.go - go.mod - go.sum - uses: actions/download-artifact@v3 with: name: "${{ github.sha }}-00-coverage" - if: env.GIT_DIFF - uses: actions/download-artifact@v3 with: name: "${{ github.sha }}-01-coverage" - if: env.GIT_DIFF - uses: actions/download-artifact@v3 with: name: "${{ github.sha }}-02-coverage" - if: env.GIT_DIFF - uses: actions/download-artifact@v3 with: name: "${{ github.sha }}-03-coverage" - if: env.GIT_DIFF - uses: actions/download-artifact@v3 with: - name: "${{ github.sha }}-go-submodules-coverage" - if: env.GIT_DIFF + name: "${{ github.sha }}-integration-coverage" + - uses: actions/download-artifact@v3 + with: + name: "${{ github.sha }}-e2e-coverage" continue-on-error: true - - run: | - cat ./*profile.out | grep -v "mode: atomic" >> coverage.txt - if: env.GIT_DIFF - - name: SonarCloud Scan + - name: sonarcloud uses: SonarSource/sonarcloud-github-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - uses: codecov/codecov-action@v3 - with: - file: ./coverage.txt - - test-rosetta: - runs-on: ubuntu-latest - timeout-minutes: 30 - steps: - - uses: actions/checkout@v3 - - uses: technote-space/get-diff-action@v6.1.1 - id: git_diff - with: - PATTERNS: | - **/**.go - go.mod - go.sum - - uses: actions/setup-go@v3 - with: - go-version: 1.19.2 - - name: test rosetta - run: | - make test-rosetta-unit - make test-rosetta liveness-test: runs-on: ubuntu-latest @@ -193,31 +161,12 @@ jobs: - uses: actions/setup-go@v3 with: go-version: 1.19.2 - - uses: technote-space/get-diff-action@v6.1.1 - id: git_diff - with: - PATTERNS: | - **/**.go - go.mod - go.sum - - name: Get data from Go build cache - # if: env.GIT_DIFF - if: ${{ false }} - uses: actions/cache@v3 - with: - path: | - ~/go/pkg/mod - ~/.cache/golangci-lint - ~/.cache/go-build - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - name: start localnet run: | make clean localnet-start - if: env.GIT_DIFF - name: test liveness run: | ./contrib/localnet_liveness.sh 100 5 50 localhost - if: env.GIT_DIFF test-sim-nondeterminism: runs-on: ubuntu-latest @@ -226,13 +175,280 @@ jobs: - uses: actions/setup-go@v3 with: go-version: 1.19.2 - - uses: technote-space/get-diff-action@v6.1.1 - with: - PATTERNS: | - **/**.go - go.mod - go.sum - name: test-sim-nondeterminism run: | make test-sim-nondeterminism + + ################################## + #### Cosmos SDK Go Submodules #### + ################################## + + # NOTE: The following jobs are used to test the Cosmos SDK Go submodules. + # They run when there is a diff in their respective directories. + + test-clientv2: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: technote-space/get-diff-action@v6.1.1 + id: git_diff + with: + PATTERNS: | + client/v2/**/*.go + client/v2/go.mod + client/v2/go.sum + - name: tests if: env.GIT_DIFF + run: | + cd client/v2 + go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./... + - name: sonarcloud + if: env.GIT_DIFF + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_CLIENT_V2 }} + with: + projectBaseDir: client/v2/ + + test-core: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: technote-space/get-diff-action@v6.1.1 + id: git_diff + with: + PATTERNS: | + core/**/*.go + core/go.mod + core/go.sum + - name: tests + if: env.GIT_DIFF + run: | + cd core + go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./... + - name: sonarcloud + if: env.GIT_DIFF + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_CORE }} + with: + projectBaseDir: core/ + + test-depinject: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: technote-space/get-diff-action@v6.1.1 + id: git_diff + with: + PATTERNS: | + depinject/**/*.go + depinject/go.mod + depinject/go.sum + - name: tests + if: env.GIT_DIFF + run: | + cd depinject + go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./... + - name: sonarcloud + if: env.GIT_DIFF + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_DEPINJECT }} + + test-errors: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: technote-space/get-diff-action@v6.1.1 + id: git_diff + with: + PATTERNS: | + errors/**/*.go + errors/go.mod + errors/go.sum + - name: tests + if: env.GIT_DIFF + run: | + cd tests + go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./... + - name: sonarcloud + if: env.GIT_DIFF + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_ERRORS }} + with: + projectBaseDir: errors/ + + test-math: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: technote-space/get-diff-action@v6.1.1 + id: git_diff + with: + PATTERNS: | + math/**/*.go + math/go.mod + math/go.sum + - name: tests + if: env.GIT_DIFF + run: | + cd math + go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./... + - name: sonarcloud + if: env.GIT_DIFF + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_MATH }} + with: + projectBaseDir: math/ + + test-simapp: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: technote-space/get-diff-action@v6.1.1 + id: git_diff + with: + PATTERNS: | + simapp/**/*.go + simapp/go.mod + simapp/go.sum + - name: tests simapp + if: env.GIT_DIFF + run: | + cd simapp + go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./... + - name: tests simapp v1 + if: env.GIT_DIFF + run: | + cd simapp + go test -mod=readonly -timeout 30m -tags='app_v1 norace ledger test_ledger_mock rocksdb_build' ./... + - name: sonarcloud + if: env.GIT_DIFF + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_SIMAPP }} + with: + projectBaseDir: simapp/ + + test-tx: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: technote-space/get-diff-action@v6.1.1 + id: git_diff + with: + PATTERNS: | + tx/**/*.go + tx/go.mod + tx/go.sum + - name: tests + if: env.GIT_DIFF + run: | + cd tx + go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./... + - name: sonarcloud + if: env.GIT_DIFF + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_TX }} + with: + projectBaseDir: tx/ + + test-rosetta: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: technote-space/get-diff-action@v6.1.1 + id: git_diff + with: + PATTERNS: | + tools/rosetta/**/*.go + tools/rosetta/go.mod + tools/rosetta/go.sum + - name: tests + if: env.GIT_DIFF + run: | + make test-rosetta + cd tools/rosetta + go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./... + - name: sonarcloud + if: env.GIT_DIFF + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_ROSETTA }} + with: + projectBaseDir: tools/rosetta/ + + test-cosmovisor: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: technote-space/get-diff-action@v6.1.1 + id: git_diff + with: + PATTERNS: | + tools/cosmovisor/**/*.go + tools/cosmovisor/go.mod + tools/cosmovisor/go.sum + - name: tests + if: env.GIT_DIFF + run: | + cd tools/cosmovisor + go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./... + - name: sonarcloud + if: env.GIT_DIFF + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_COSMOVISOR }} + with: + projectBaseDir: tools/cosmovisor/ diff --git a/.gitignore b/.gitignore index 195f47915e..6183aeafdd 100644 --- a/.gitignore +++ b/.gitignore @@ -29,8 +29,9 @@ client/lcd/keys/* .testnets # Testing +coverage.out coverage.txt -profile.out +*profile.out sim_log_file x/genutil/config x/genutil/data diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5664c578cd..0f77a4086f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,28 +1,28 @@ # Contributing -* [Contributing](#contributing) - * [Teams Dev Calls](#teams-dev-calls) - * [Architecture Decision Records (ADR)](#architecture-decision-records-adr) - * [Development Procedure](#development-procedure) - * [Testing](#testing) - * [Pull Requests](#pull-requests) - * [Pull Request Templates](#pull-request-templates) - * [Requesting Reviews](#requesting-reviews) - * [Updating Documentation](#updating-documentation) - * [Dependencies](#dependencies) - * [`go.work`](#gowork) - * [Protobuf](#protobuf) - * [Branching Model and Release](#branching-model-and-release) - * [PR Targeting](#pr-targeting) - * [Code Owner Membership](#code-owner-membership) - * [Concept & Feature Approval Process](#concept--feature-approval-process) - * [Strategy Discovery](#strategy-discovery) - * [Concept Approval](#concept-approval) - * [Time Bound Period](#time-bound-period) - * [Approval Committee & Decision Making](#approval-committee--decision-making) - * [Committee Members](#committee-members) - * [Committee Criteria](#committee-criteria) - * [Implementation & Release Approval](#implementation--release-approval) +* [Teams Dev Calls](#teams-dev-calls) +* [Architecture Decision Records (ADR)](#architecture-decision-records-adr) +* [Development Procedure](#development-procedure) + * [Testing](#testing) + * [Pull Requests](#pull-requests) + * [Pull Request Templates](#pull-request-templates) + * [Requesting Reviews](#requesting-reviews) + * [Updating Documentation](#updating-documentation) +* [Dependencies](#dependencies) + * [`go.work`](#gowork) + * [`go.mod`](#gomod) +* [Protobuf](#protobuf) +* [Branching Model and Release](#branching-model-and-release) + * [PR Targeting](#pr-targeting) +* [Code Owner Membership](#code-owner-membership) +* [Concept & Feature Approval Process](#concept--feature-approval-process) + * [Strategy Discovery](#strategy-discovery) + * [Concept Approval](#concept-approval) + * [Time Bound Period](#time-bound-period) + * [Approval Committee & Decision Making](#approval-committee--decision-making) + * [Committee Members](#committee-members) + * [Committee Criteria](#committee-criteria) + * [Implementation & Release Approval](#implementation--release-approval) Thank you for considering making contributions to the Cosmos SDK and related repositories! @@ -182,6 +182,18 @@ We provide a [`go.work.example`](./go.work.example) that contains all the module Do note that contributions modifying multiple Go modules should be submitted as separate PRs, this allows us to tag the changes and avoid `replace`s. For consistency between our CI and the local tests, `GOWORK=off` is set in the `Makefile`. This means that the `go.work` file is not used when using `make test` or any other `make` command. +### `go.mod` + +When extracting a package to its own go modules, some extra steps are required, for keeping our CI checks and Dev UX: + +* Add the package in [`go.work.example`](./go.work.example) +* Add weekly dependabot checks (see [dependabot.yml](./.github/dependabot.yml)) +* Pre-configure SonarCloud + * Add `sonar-projects.properties` (see math [sonar-projects.properties](./math/sonar-projects.properties) for example) + * Add a GitHub Workflow entry for running the scans (see [test.yml](.github/workflows/test.yml)) + * Add an entry for skipping the tests (see [test-skip.yml](.github/workflows/test-skip.yml)) + * Ask the team to add the project to SonarCloud + ## Protobuf We use [Protocol Buffers](https://developers.google.com/protocol-buffers) along with [gogoproto](https://github.com/cosmos/gogoproto) to generate code for use in Cosmos SDK. diff --git a/Makefile b/Makefile index aeeba45e9e..3fa4d9e264 100644 --- a/Makefile +++ b/Makefile @@ -196,9 +196,13 @@ build-docs: test: test-unit test-e2e: $(MAKE) -C tests test-e2e +test-e2e-cov: + $(MAKE) -C tests test-e2e-cov test-integration: $(MAKE) -C tests test-integration -test-all: test-unit test-e2e test-integration test-ledger-mock test-race test-cover +test-integration-cov: + $(MAKE) -C tests test-integration-cov +test-all: test-unit test-e2e test-integration test-ledger-mock test-race TEST_PACKAGES=./... TEST_TARGETS := test-unit test-unit-amino test-unit-proto test-ledger-mock test-race test-ledger test-race @@ -317,13 +321,6 @@ test-sim-profile: .PHONY: test-sim-profile test-sim-benchmark -test-cover: - @export VERSION=$(VERSION); bash -x contrib/test_cover.sh -.PHONY: test-cover - -test-rosetta-unit: - $(MAKE) -C tools/rosetta test - test-rosetta: docker build -t rosetta-ci:latest -f contrib/rosetta/rosetta-ci/Dockerfile . docker-compose -f contrib/rosetta/docker-compose.yaml up --abort-on-container-exit --exit-code-from test_rosetta --build diff --git a/client/v2/sonar-project.properties b/client/v2/sonar-project.properties new file mode 100644 index 0000000000..f435ba2424 --- /dev/null +++ b/client/v2/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=cosmos-sdk-client-v2 +sonar.organization=cosmos + +sonar.projectName=Cosmos SDK - Client V2 +sonar.project.monorepo.enabled=true + +sonar.sources=. +sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.coverage.reportPaths=coverage.out + +sonar.sourceEncoding=UTF-8 +sonar.scm.provider=git +sonar.pullrequest.github.summary_comment=true \ No newline at end of file diff --git a/contrib/test_cover.sh b/contrib/test_cover.sh deleted file mode 100644 index 24f7804b51..0000000000 --- a/contrib/test_cover.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -set -e - -PKGS=$(go list ./... | grep -v '/simapp') - -set -e -echo "mode: atomic" > coverage.txt -for pkg in ${PKGS[@]}; do - go test -v -timeout 30m -race -coverprofile=profile.out -covermode=atomic -tags='ledger test_ledger_mock' "$pkg" - if [ -f profile.out ]; then - tail -n +2 profile.out >> coverage.txt; - rm profile.out - fi -done diff --git a/core/sonar-project.properties b/core/sonar-project.properties new file mode 100644 index 0000000000..8db28773d8 --- /dev/null +++ b/core/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=cosmos-sdk-core +sonar.organization=cosmos + +sonar.projectName=Cosmos SDK Core +sonar.project.monorepo.enabled=true + +sonar.sources=. +sonar.exclusions=**/*_test.go,**/*.pulsar.go +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.coverage.reportPaths=coverage.out + +sonar.sourceEncoding=UTF-8 +sonar.scm.provider=git +sonar.pullrequest.github.summary_comment=true \ No newline at end of file diff --git a/depinject/sonar-project.properties b/depinject/sonar-project.properties new file mode 100644 index 0000000000..c3f568fdbf --- /dev/null +++ b/depinject/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=cosmos-sdk-depinject +sonar.organization=cosmos + +sonar.projectName=Cosmos SDK Depinject +sonar.project.monorepo.enabled=true + +sonar.sources=. +sonar.exclusions=**/*_test.go,**/*.pulsar.go +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.coverage.reportPaths=coverage.out + +sonar.sourceEncoding=UTF-8 +sonar.scm.provider=git +sonar.pullrequest.github.summary_comment=true \ No newline at end of file diff --git a/errors/sonar-project.properties b/errors/sonar-project.properties new file mode 100644 index 0000000000..2413993d8f --- /dev/null +++ b/errors/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=cosmos-sdk-errors +sonar.organization=cosmos + +sonar.projectName=Cosmos SDK Errors +sonar.project.monorepo.enabled=true + +sonar.sources=. +sonar.exclusions=**/*_test.go +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.coverage.reportPaths=coverage.out + +sonar.sourceEncoding=UTF-8 +sonar.scm.provider=git +sonar.pullrequest.github.summary_comment=true \ No newline at end of file diff --git a/go.work.example b/go.work.example index cd541eb3bf..d5f05768f1 100644 --- a/go.work.example +++ b/go.work.example @@ -5,7 +5,6 @@ use ( ./api ./client/v2 ./core - ./tools/cosmovisor ./depinject ./errors ./math @@ -14,4 +13,5 @@ use ( ./simapp ./tests ./tools/rosetta + ./tools/cosmovisor ) diff --git a/math/sonar-project.properties b/math/sonar-project.properties new file mode 100644 index 0000000000..ed9f047121 --- /dev/null +++ b/math/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=cosmos-sdk-math +sonar.organization=cosmos + +sonar.projectName=Cosmos SDK - Math +sonar.project.monorepo.enabled=true + +sonar.sources=. +sonar.exclusions=**/*_test.go +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.coverage.reportPaths=coverage.out + +sonar.sourceEncoding=UTF-8 +sonar.scm.provider=git +sonar.pullrequest.github.summary_comment=true \ No newline at end of file diff --git a/scripts/module-tests.sh b/scripts/module-tests.sh deleted file mode 100644 index b6be64240e..0000000000 --- a/scripts/module-tests.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash - -# this script is used by Github CI to tranverse all modules an run module tests. -# the script expects a diff to be generated in order to skip some modules. - -# Executes go module tests and merges the coverage profile. -# If GIT_DIFF variable is set then it's used to test if a module has any file changes - if -# it doesn't have any file changes then we will ignore the module tests. -execute_mod_tests() { - go_mod=$1; - mod_dir=$(dirname "$go_mod"); - mod_dir=${mod_dir:2}; # remove "./" prefix - root_dir=$(pwd); - - # TODO: in the future we will need to disable it once we go into multi module setup, because - # we will have cross module dependencies. - if [ -n "$GIT_DIFF" ] && ! grep $mod_dir <<< $GIT_DIFF; then - echo ">>> ignoring module $mod_dir - no changes in the module"; - return; - fi; - - echo ">>> running $go_mod tests" - cd $mod_dir; - go test -mod=readonly -timeout 30m -coverprofile=${root_dir}/${coverage_file}.tmp -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./... - local ret=$? - echo "test return: " $ret; - cd -; - # strip mode statement - tail -n +1 ${coverage_file}.tmp >> ${coverage_file} - rm ${coverage_file}.tmp; - return $ret; -} - -# GIT_DIFF=`git status --porcelain` - -echo "GIT_DIFF: " $GIT_DIFF - -coverage_file=coverage-go-submod-profile.out -return_val=0; - -for f in $(find -name go.mod -not -path "./go.mod"); do - execute_mod_tests $f; - if [[ $? -ne 0 ]] ; then - return_val=2; - fi; -done - -exit $return_val; diff --git a/simapp/sonar-project.properties b/simapp/sonar-project.properties new file mode 100644 index 0000000000..614f5badaf --- /dev/null +++ b/simapp/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=cosmos-sdk-simapp +sonar.organization=cosmos + +sonar.projectName=Cosmos SDK - SimApp +sonar.project.monorepo.enabled=true + +sonar.sources=. +sonar.exclusions=**/*_test.go +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.coverage.reportPaths=coverage.out + +sonar.sourceEncoding=UTF-8 +sonar.scm.provider=git +sonar.pullrequest.github.summary_comment=true \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties index ba6b617b30..b447e8231f 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -5,9 +5,9 @@ sonar.projectName=Cosmos SDK sonar.project.monorepo.enabled=true sonar.sources=. -sonar.exclusions=**/*_test.go,tests/**,**/*.pb.go,**/*.pb.gw.go,**/*.pulsar.go,test_helpers.go,docs/**,testutil/testdata/**,testutil/testdata_pulsar/**,**/*.java,client/docs/** +sonar.exclusions=**/*_test.go,tests/**,**/testutil/**,**/*.pb.go,**/*.pb.gw.go,**/*.pulsar.go,test_helpers.go,docs/**,**/*.java,client/docs/**, sonar.tests=. -sonar.test.inclusions=**/*_test.go,tests/** +sonar.test.inclusions=**/*_test.go,tests/**,**/testutil/** sonar.go.coverage.reportPaths=coverage.out,*profile.out sonar.python.version=3 diff --git a/tests/Makefile b/tests/Makefile index 2aff22faa9..95df468c77 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,5 +1,11 @@ test-integration: go test ./integration/... -timeout 30m +test-integration-cov: + go test ./integration/... -timeout 30m -coverpkg=../... -coverprofile=integration-profile.out -covermode=atomic + test-e2e: go test ./e2e/... -mod=readonly -timeout 30m -race -tags='e2e' + +test-e2e-cov: + go test ./e2e/... -mod=readonly -timeout 30m -race -tags='e2e' -coverpkg=../... -coverprofile=e2e-profile.out -covermode=atomic \ No newline at end of file diff --git a/tools/cosmovisor/sonar-project.properties b/tools/cosmovisor/sonar-project.properties new file mode 100644 index 0000000000..02c95832b8 --- /dev/null +++ b/tools/cosmovisor/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=cosmos-sdk-tools-cosmovisor +sonar.organization=cosmos + +sonar.projectName=Cosmos SDK - Cosmovisor +sonar.project.monorepo.enabled=true + +sonar.sources=. +sonar.exclusions=**/*_test.go +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.coverage.reportPaths=coverage.out + +sonar.sourceEncoding=UTF-8 +sonar.scm.provider=git +sonar.pullrequest.github.summary_comment=true \ No newline at end of file diff --git a/tools/rosetta/sonar-project.properties b/tools/rosetta/sonar-project.properties new file mode 100644 index 0000000000..b483a79f09 --- /dev/null +++ b/tools/rosetta/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=cosmos-sdk-tools-rosetta +sonar.organization=cosmos + +sonar.projectName=Cosmos SDK - Rosetta +sonar.project.monorepo.enabled=true + +sonar.sources=. +sonar.exclusions=**/*_test.go +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.coverage.reportPaths=coverage.out + +sonar.sourceEncoding=UTF-8 +sonar.scm.provider=git +sonar.pullrequest.github.summary_comment=true \ No newline at end of file diff --git a/tx/sonar-project.properties b/tx/sonar-project.properties new file mode 100644 index 0000000000..72a0cb4e00 --- /dev/null +++ b/tx/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=cosmos-sdk-tx +sonar.organization=cosmos + +sonar.projectName=Cosmos SDK - Tx +sonar.project.monorepo.enabled=true + +sonar.sources=. +sonar.exclusions=**/*_test.go,**/*.pulsar.go +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.coverage.reportPaths=coverage.out + +sonar.sourceEncoding=UTF-8 +sonar.scm.provider=git +sonar.pullrequest.github.summary_comment=true \ No newline at end of file