Skip to content

Commit

Permalink
chore(ci): enable code coverage on Sonarcloud (#1518)
Browse files Browse the repository at this point in the history
* Setup Sonarcloud

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

* Update commons-test.mk

* Update ci.yml.tmpl

* Update main_test.go

* Update ci-test-go.yml

* Update ci-test-go.yml

---------

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 committed Sep 11, 2023
1 parent 58f1778 commit 721aed7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci-test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions commons-test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test-%:
--packages="./..." \
--junitfile TEST-$*.xml \
-- \
-coverprofile=coverage.out \
-timeout=30m

.PHONY: tools
Expand Down
6 changes: 6 additions & 0 deletions modulegen/_template/ci.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modulegen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 721aed7

Please sign in to comment.