diff --git a/.github/workflows/ci-test-go.yml b/.github/workflows/ci-test-go.yml index 76f7d88d31..201316d0ba 100644 --- a/.github/workflows/ci-test-go.yml +++ b/.github/workflows/ci-test-go.yml @@ -107,6 +107,15 @@ jobs: run: | go install gotest.tools/gotestsum@latest make test-unit + + - name: Analyze with SonarCloud + if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' && inputs.run-tests && inputs.project-directory == '.' }} + uses: sonarsource/sonarcloud-github-action@master + with: + projectBaseDir: ${{ inputs.project-directory }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - name: Run checker run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index beb16cc408..d9fe9e1208 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,7 @@ jobs: go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: ${{ matrix.go-version }} fail-fast: true @@ -51,6 +52,7 @@ jobs: matrix: go-version: [1.20.x, 1.x] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: ${{ matrix.go-version }} fail-fast: true @@ -72,6 +74,7 @@ jobs: go-version: [1.20.x, 1.x] platform: [ubuntu-latest] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: ${{ matrix.go-version }} fail-fast: true @@ -89,6 +92,7 @@ jobs: go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest, windows-latest] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: ${{ matrix.go-version }} fail-fast: true @@ -108,6 +112,7 @@ jobs: platform: [ubuntu-latest, macos-latest] module: [artemis, clickhouse, compose, couchbase, elasticsearch, k3s, localstack, mariadb, mongodb, mysql, nats, neo4j, postgres, pulsar, redis, redpanda, vault] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: ${{ matrix.go-version }} fail-fast: false @@ -125,6 +130,7 @@ jobs: matrix: module: [bigtable, cockroachdb, consul, datastore, firestore, nginx, pubsub, spanner, toxiproxy] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: "1.20.x" fail-fast: true diff --git a/commons-test.mk b/commons-test.mk index 2f7b5672e5..c17d192598 100644 --- a/commons-test.mk +++ b/commons-test.mk @@ -12,6 +12,7 @@ test-%: --packages="./..." \ --junitfile TEST-$*.xml \ -- \ + -coverprofile=coverage.out \ -timeout=30m .PHONY: tools diff --git a/modulegen/_template/ci.yml.tmpl b/modulegen/_template/ci.yml.tmpl index ecc4ebc82d..11236ed8d9 100644 --- a/modulegen/_template/ci.yml.tmpl +++ b/modulegen/_template/ci.yml.tmpl @@ -31,6 +31,7 @@ jobs: go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: {{ "${{ matrix.go-version }}" }} fail-fast: true @@ -51,6 +52,7 @@ jobs: matrix: go-version: [1.20.x, 1.x] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: {{ "${{ matrix.go-version }}" }} fail-fast: true @@ -72,6 +74,7 @@ jobs: go-version: [1.20.x, 1.x] platform: [ubuntu-latest] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: {{ "${{ matrix.go-version }}" }} fail-fast: true @@ -89,6 +92,7 @@ jobs: go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest, windows-latest] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: {{ "${{ matrix.go-version }}" }} fail-fast: true @@ -108,6 +112,7 @@ jobs: platform: [ubuntu-latest, macos-latest] module: [{{ .Modules }}] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: {{ "${{ matrix.go-version }}" }} fail-fast: false @@ -125,6 +130,7 @@ jobs: matrix: module: [{{ .Examples }}] uses: ./.github/workflows/ci-test-go.yml + secrets: inherit with: go-version: "1.20.x" fail-fast: true diff --git a/modulegen/main_test.go b/modulegen/main_test.go index 6b0dcad208..0dce6bc211 100644 --- a/modulegen/main_test.go +++ b/modulegen/main_test.go @@ -480,11 +480,11 @@ func assertModuleGithubWorkflowContent(t *testing.T, module context.Testcontaine modulesList, err := ctx.GetModules() assert.Nil(t, err) - assert.Equal(t, " module: ["+strings.Join(modulesList, ", ")+"]", data[108]) + assert.Equal(t, " module: ["+strings.Join(modulesList, ", ")+"]", data[112]) examplesList, err := ctx.GetExamples() assert.Nil(t, err) - assert.Equal(t, " module: ["+strings.Join(examplesList, ", ")+"]", data[125]) + assert.Equal(t, " module: ["+strings.Join(examplesList, ", ")+"]", data[130]) } // assert content go.mod diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000000..acf0372bcd --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,17 @@ +# Github organization linked to sonarcloud +sonar.organization==testcontainers + +# Project key from sonarcloud dashboard for Github Action, otherwise pick a project key you like +sonar.projectKey=testcontainers_testcontainers-go + +sonar.projectName=testcontainers-go +sonar.projectVersion=v0.23.0 + +sonar.sources=. +sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/* + +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.test.exclusions=**/vendor/** +sonar.go.tests.reportPaths=TEST-*.xml +sonar.go.coverage.reportPaths=coverage.out