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

chore(ci): enable code coverage on Sonarcloud #1518

Merged
merged 6 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
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
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
mmorel-35 marked this conversation as resolved.
Show resolved Hide resolved
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
mmorel-35 marked this conversation as resolved.
Show resolved Hide resolved

# Project key from sonarcloud dashboard for Github Action, otherwise pick a project key you like
sonar.projectKey=testcontainers_testcontainers-go

sonar.projectName=testcontainers-go
Comment on lines +5 to +7
Copy link
Contributor Author

@mmorel-35 mmorel-35 Aug 24, 2023

Choose a reason for hiding this comment

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

I imagine that for modulegen, it could be :

sonar.projectKey=testcontainers_testcontainers-go_modulegen
sonar.projectName=testcontainers-go/modulegen

For examples/bigtable it could be :

sonar.projectKey=testcontainers_testcontainers-go_examples_bigtable
sonar.projectName=testcontainers-go/examples/bigtable

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