From d033fff139fd81d398c9f15477882bb9f5f6b5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Wed, 5 Mar 2025 12:03:36 +0100 Subject: [PATCH 1/7] choe(ci): use new sonarqube GH action --- .github/workflows/ci.yml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6de22c962..f39b2e69fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -140,14 +140,10 @@ jobs: with: # Disabling shallow clone is recommended for improving relevancy of reporting fetch-depth: 0 - - - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 - with: - pattern: sonarcloud-* - merge-multiple: true - - - name: Analyze with SonarCloud - uses: sonarsource/sonarcloud-github-action@02ef91109b2d589e757aefcfb2854c2783fd7b19 # v4.0.0 + + - name: SonarQube Scan + uses: SonarSource/sonarqube-scan-action@0303d6b62e310685c0e34d0b9cde218036885c4d # v5.0.0 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + projectBaseDir: "${{ matrix.module }}" From 3c940b8f2d137fdd7fe84050cc5a110a4f215c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Wed, 5 Mar 2025 12:04:07 +0100 Subject: [PATCH 2/7] revert: for testing on CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f39b2e69fa..4352e3c6d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,7 +129,7 @@ jobs: permissions: contents: read # for actions/checkout to fetch code pull-requests: read # for sonarsource/sonarcloud-github-action to determine which PR to decorate - if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' && needs.detect-modules.outputs.modules_count > 0 }} + if: ${{ needs.detect-modules.outputs.modules_count > 0 }} needs: - detect-modules - test From a67cc9a9ebf4258f22265a4d3afd1f4b18fe3be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 13 Mar 2025 14:36:56 +0100 Subject: [PATCH 3/7] chore: generate sonar properties on the fly for each module, supporting monorepo --- .github/workflows/ci-test-go.yml | 30 +++++++++++++ .github/workflows/ci.yml | 26 ++--------- .../_template/sonar-project.properties.tmpl | 21 --------- modulegen/internal/main.go | 2 - modulegen/internal/sonar/main.go | 43 ------------------- modulegen/internal/sonar/types.go | 38 ---------------- sonar-project.properties | 21 --------- 7 files changed, 33 insertions(+), 148 deletions(-) delete mode 100644 modulegen/_template/sonar-project.properties.tmpl delete mode 100644 modulegen/internal/sonar/main.go delete mode 100644 modulegen/internal/sonar/types.go delete mode 100644 sonar-project.properties diff --git a/.github/workflows/ci-test-go.yml b/.github/workflows/ci-test-go.yml index e6b71b1a68..94915272d8 100644 --- a/.github/workflows/ci-test-go.yml +++ b/.github/workflows/ci-test-go.yml @@ -55,6 +55,9 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 - name: Set up Go uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 @@ -108,3 +111,30 @@ jobs: with: paths: "**/${{ inputs.project-directory }}/TEST-unit*.xml" if: always() + + + - name: Extract Testcontainers Go version from mkdocs.yml + if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' }} + run: | + echo "PROJECT_VERSION=$(grep 'latest_version' mkdocs.yml | cut -d':' -f2 | tr -d ' ')" >> $GITHUB_ENV + + - name: SonarQube Scan + if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' }} + uses: SonarSource/sonarqube-scan-action@0303d6b62e310685c0e34d0b9cde218036885c4d # v5.0.0 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + projectBaseDir: "${{ inputs.project-directory == '.' && 'testcontainers-go' || inputs.project-directory }}" + args: > + -Dsonar.organization=testcontainers + -Dsonar.projectKey=${{ inputs.project-directory == '.' && 'testcontainers_testcontainers-go' || format('testcontainers_testcontainers-go_%s', inputs.project-directory) }} + -Dsonar.projectName=${{ inputs.project-directory == '.' && 'testcontainers-go' || 'testcontainers-go/'inputs.project-directory }} + -Dsonar.projectVersion=${{ env.PROJECT_VERSION }} + -Dsonar.project.monorepo.enabled=true + -Dsonar.sources=. + -Dsonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/** + -Dsonar.tests=. + -Dsonar.test.inclusions=**/*_test.go + -Dsonar.test.exclusions=**/vendor/** + -Dsonar.go.coverage.reportPaths=coverage.out + -Dsonar.go.tests.reportPaths=TEST-unit.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4352e3c6d6..8427204786 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,9 @@ jobs: matrix: go-version: [1.23.x, 1.24.x] module: ${{ fromJSON(needs.detect-modules.outputs.modules) }} + permissions: + contents: read # for actions/checkout to fetch code + pull-requests: read # for sonarsource/sonarcloud-github-action to determine which PR to decorate uses: ./.github/workflows/ci-test-go.yml with: go-version: ${{ matrix.go-version }} @@ -124,26 +127,3 @@ jobs: run: exit 1 - run: echo "All tests completed successfully!" - - sonarcloud: - permissions: - contents: read # for actions/checkout to fetch code - pull-requests: read # for sonarsource/sonarcloud-github-action to determine which PR to decorate - if: ${{ needs.detect-modules.outputs.modules_count > 0 }} - needs: - - detect-modules - - test - runs-on: ubuntu-latest - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - - name: SonarQube Scan - uses: SonarSource/sonarqube-scan-action@0303d6b62e310685c0e34d0b9cde218036885c4d # v5.0.0 - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - with: - projectBaseDir: "${{ matrix.module }}" diff --git a/modulegen/_template/sonar-project.properties.tmpl b/modulegen/_template/sonar-project.properties.tmpl deleted file mode 100644 index cde281ed29..0000000000 --- a/modulegen/_template/sonar-project.properties.tmpl +++ /dev/null @@ -1,21 +0,0 @@ -# This file is autogenerated by the 'modulegen' tool. -# 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={{ .ProjectVersion }} - -sonar.sources=. - -sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/** - -sonar.tests=. -sonar.test.inclusions=**/*_test.go -sonar.test.exclusions=**/vendor/** - -sonar.go.coverage.reportPaths=**/coverage.out -sonar.go.tests.reportPaths={{ .Go.Tests.ReportPaths }} diff --git a/modulegen/internal/main.go b/modulegen/internal/main.go index 21084a5a52..0db9d56e4c 100644 --- a/modulegen/internal/main.go +++ b/modulegen/internal/main.go @@ -8,7 +8,6 @@ import ( "github.com/testcontainers/testcontainers-go/modulegen/internal/make" "github.com/testcontainers/testcontainers-go/modulegen/internal/mkdocs" "github.com/testcontainers/testcontainers-go/modulegen/internal/module" - "github.com/testcontainers/testcontainers-go/modulegen/internal/sonar" "github.com/testcontainers/testcontainers-go/modulegen/internal/tools" "github.com/testcontainers/testcontainers-go/modulegen/internal/vscode" ) @@ -82,7 +81,6 @@ func GenerateFiles(ctx context.Context, tcModule context.TestcontainersModule) e // module generation projectGenerators := []ProjectGenerator{ vscode.Generator{}, // update vscode workspace - sonar.Generator{}, // update sonar-project.properties } for _, generator := range projectGenerators { diff --git a/modulegen/internal/sonar/main.go b/modulegen/internal/sonar/main.go deleted file mode 100644 index 64dbd149b5..0000000000 --- a/modulegen/internal/sonar/main.go +++ /dev/null @@ -1,43 +0,0 @@ -package sonar - -import ( - "fmt" - "path/filepath" - "text/template" - - "github.com/testcontainers/testcontainers-go/modulegen/internal/context" - "github.com/testcontainers/testcontainers-go/modulegen/internal/mkdocs" - internal_template "github.com/testcontainers/testcontainers-go/modulegen/internal/template" -) - -type Generator struct{} - -// Generate updates sonar-project.properties -func (g Generator) Generate(ctx context.Context) error { - rootCtx, err := context.GetRootContext() - if err != nil { - return err - } - examples, err := rootCtx.GetExamples() - if err != nil { - return err - } - modules, err := rootCtx.GetModules() - if err != nil { - return err - } - mkdocsConfig, err := mkdocs.ReadConfig(rootCtx.MkdocsConfigFile()) - if err != nil { - fmt.Printf(">> could not read MkDocs config: %v\n", err) - return err - } - tcVersion := mkdocsConfig.Extra.LatestVersion - config := newConfig(tcVersion, examples, modules) - name := "sonar-project.properties.tmpl" - t, err := template.New(name).ParseFiles(filepath.Join("_template", name)) - if err != nil { - return err - } - - return internal_template.GenerateFile(t, ctx.SonarProjectFile(), name, config) -} diff --git a/modulegen/internal/sonar/types.go b/modulegen/internal/sonar/types.go deleted file mode 100644 index 3a7a541444..0000000000 --- a/modulegen/internal/sonar/types.go +++ /dev/null @@ -1,38 +0,0 @@ -package sonar - -import ( - "sort" - "strings" -) - -type Config struct { - Go Go - ProjectVersion string -} - -type Go struct { - Tests Tests -} - -type Tests struct { - ReportPaths string -} - -func newConfig(tcVersion string, examples []string, modules []string) *Config { - reportPaths := []string{"TEST-unit.xml", "modulegen/TEST-unit.xml"} - for _, example := range examples { - reportPaths = append(reportPaths, "examples/"+example+"/TEST-unit.xml") - } - for _, module := range modules { - reportPaths = append(reportPaths, "modules/"+module+"/TEST-unit.xml") - } - sort.Strings(reportPaths) - return &Config{ - Go: Go{ - Tests: Tests{ - ReportPaths: strings.Join(reportPaths, ","), - }, - }, - ProjectVersion: tcVersion, - } -} diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index b24c9bd0e9..0000000000 --- a/sonar-project.properties +++ /dev/null @@ -1,21 +0,0 @@ -# This file is autogenerated by the 'modulegen' tool. -# 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.35.0 - -sonar.sources=. - -sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/** - -sonar.tests=. -sonar.test.inclusions=**/*_test.go -sonar.test.exclusions=**/vendor/** - -sonar.go.coverage.reportPaths=**/coverage.out -sonar.go.tests.reportPaths=TEST-unit.xml,examples/nginx/TEST-unit.xml,examples/toxiproxy/TEST-unit.xml,modulegen/TEST-unit.xml,modules/artemis/TEST-unit.xml,modules/azurite/TEST-unit.xml,modules/cassandra/TEST-unit.xml,modules/chroma/TEST-unit.xml,modules/clickhouse/TEST-unit.xml,modules/cockroachdb/TEST-unit.xml,modules/compose/TEST-unit.xml,modules/consul/TEST-unit.xml,modules/couchbase/TEST-unit.xml,modules/databend/TEST-unit.xml,modules/dolt/TEST-unit.xml,modules/dynamodb/TEST-unit.xml,modules/elasticsearch/TEST-unit.xml,modules/etcd/TEST-unit.xml,modules/gcloud/TEST-unit.xml,modules/grafana-lgtm/TEST-unit.xml,modules/inbucket/TEST-unit.xml,modules/influxdb/TEST-unit.xml,modules/k3s/TEST-unit.xml,modules/k6/TEST-unit.xml,modules/kafka/TEST-unit.xml,modules/localstack/TEST-unit.xml,modules/mariadb/TEST-unit.xml,modules/meilisearch/TEST-unit.xml,modules/milvus/TEST-unit.xml,modules/minio/TEST-unit.xml,modules/mockserver/TEST-unit.xml,modules/mongodb/TEST-unit.xml,modules/mssql/TEST-unit.xml,modules/mysql/TEST-unit.xml,modules/nats/TEST-unit.xml,modules/neo4j/TEST-unit.xml,modules/ollama/TEST-unit.xml,modules/openfga/TEST-unit.xml,modules/openldap/TEST-unit.xml,modules/opensearch/TEST-unit.xml,modules/pinecone/TEST-unit.xml,modules/postgres/TEST-unit.xml,modules/pulsar/TEST-unit.xml,modules/qdrant/TEST-unit.xml,modules/rabbitmq/TEST-unit.xml,modules/redis/TEST-unit.xml,modules/redpanda/TEST-unit.xml,modules/registry/TEST-unit.xml,,modules/scylladb/TEST-unit.xml,modules/surrealdb/TEST-unit.xml,modules/valkey/TEST-unit.xml,modules/vault/TEST-unit.xml,modules/vearch/TEST-unit.xml,modules/weaviate/TEST-unit.xml,modules/yugabytedb/TEST-unit.xml From 52c26f908e6ab4ecf0bdde4f7168bf95c7620c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 13 Mar 2025 14:40:37 +0100 Subject: [PATCH 4/7] fix: remove after merge conflicts --- modulegen/internal/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/modulegen/internal/main.go b/modulegen/internal/main.go index 20254b2ecd..ec3e10fd93 100644 --- a/modulegen/internal/main.go +++ b/modulegen/internal/main.go @@ -71,7 +71,6 @@ func Refresh(ctx context.Context) error { mkdocs.Generator{}, // update examples in mkdocs dependabot.Generator{}, // update examples in dependabot vscode.Generator{}, // update vscode workspace - sonar.Generator{}, // update sonar-project.properties } for _, generator := range generators { From 668f2e1d4076474e71f71833c768735f5a85e7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 13 Mar 2025 14:43:56 +0100 Subject: [PATCH 5/7] chore: more removals --- .github/workflows/ci-test-go.yml | 10 ---------- modulegen/cmd/modules/main.go | 2 +- modulegen/internal/context/context.go | 5 ----- modulegen/main_test.go | 7 ------- scripts/changed-modules.sh | 6 +++--- scripts/pre-release.sh | 10 ---------- scripts/release.sh | 2 -- 7 files changed, 4 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci-test-go.yml b/.github/workflows/ci-test-go.yml index 94915272d8..a42015720a 100644 --- a/.github/workflows/ci-test-go.yml +++ b/.github/workflows/ci-test-go.yml @@ -92,16 +92,6 @@ jobs: run: | echo "ARTIFACT_NAME=$(basename ${{ inputs.project-directory == '.' && 'core' || inputs.project-directory }})-${{ inputs.go-version }}-${{ matrix.platform }}" >> $GITHUB_ENV - - name: Upload SonarCloud files - if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' && matrix.platform == 'ubuntu-latest' && !inputs.rootless-docker && !inputs.ryuk-disabled }} - uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 - with: - name: sonarcloud-${{ env.ARTIFACT_NAME }} - path: | - ./sonar-project.properties - ${{ inputs.project-directory }}/TEST-unit.xml - ${{ inputs.project-directory }}/coverage.out - - name: Run checker run: | ./scripts/check_environment.sh diff --git a/modulegen/cmd/modules/main.go b/modulegen/cmd/modules/main.go index da19887804..13fa5c2097 100644 --- a/modulegen/cmd/modules/main.go +++ b/modulegen/cmd/modules/main.go @@ -20,7 +20,7 @@ var NewCmd = &cobra.Command{ var RefreshModulesCmd = &cobra.Command{ Use: "refresh", Short: "Refresh the module and example files", - Long: "Refresh the module and example files, including the dependabot config, mkdocs config, sonar properties, vscode settings and makefiles for all the modules and examples", + Long: "Refresh the module and example files, including the dependabot config, mkdocs config, vscode settings and makefiles for all the modules and examples", RunE: func(_ *cobra.Command, _ []string) error { ctx, err := context.GetRootContext() if err != nil { diff --git a/modulegen/internal/context/context.go b/modulegen/internal/context/context.go index 132c998ef5..e7618412d7 100644 --- a/modulegen/internal/context/context.go +++ b/modulegen/internal/context/context.go @@ -130,11 +130,6 @@ func (ctx Context) MkdocsConfigFile() string { return filepath.Join(ctx.RootDir, "mkdocs.yml") } -// SonarProjectFile returns, from the root directory, the relative path to the sonar project file, "/sonar-project.properties". -func (ctx Context) SonarProjectFile() string { - return filepath.Join(ctx.RootDir, "sonar-project.properties") -} - // VSCodeWorkspaceFile returns, from the root directory, the relative path to the vscode workspace file, "/.vscode/.testcontainers-go.code-workspace". func (ctx Context) VSCodeWorkspaceFile() string { return filepath.Join(ctx.RootDir, ".vscode", ".testcontainers-go.code-workspace") diff --git a/modulegen/main_test.go b/modulegen/main_test.go index 5e0eeffcad..47a828c9bd 100644 --- a/modulegen/main_test.go +++ b/modulegen/main_test.go @@ -580,13 +580,6 @@ func copyInitialProject(t *testing.T) testProject { err = os.WriteFile(tmpCtx.GoModFile(), goModFile, 0o777) require.NoError(t, err) - // sonar-project.properties - sonarProjectFile, err := os.ReadFile(ctx.SonarProjectFile()) - require.NoError(t, err) - - err = os.WriteFile(tmpCtx.SonarProjectFile(), sonarProjectFile, 0o777) - require.NoError(t, err) - // .vscode/testcontainers-go.code-workspace err = os.MkdirAll(filepath.Dir(tmpCtx.VSCodeWorkspaceFile()), 0o777) require.NoError(t, err) diff --git a/scripts/changed-modules.sh b/scripts/changed-modules.sh index 588660ee96..f42931241d 100755 --- a/scripts/changed-modules.sh +++ b/scripts/changed-modules.sh @@ -57,11 +57,11 @@ set -euxo pipefail # The output should be: no modules. # # 14. A excluded file and a file from the core module are modified: -# ALL_CHANGED_FILES="mkdocs.yml sonar-project.properties go.mod" ./scripts/changed-modules.sh +# ALL_CHANGED_FILES="mkdocs.yml go.mod" ./scripts/changed-modules.sh # The output should be: all modules. # # 15. Only excluded files are modified: -# ALL_CHANGED_FILES="mkdocs.yml sonar-project.properties" ./scripts/changed-modules.sh +# ALL_CHANGED_FILES="mkdocs.yml" ./scripts/changed-modules.sh # The output should be: no modules. # # There is room for improvement in this script. For example, it could detect if the changes applied to the docs or the .github dirs, and then do not include any module in the list. @@ -74,7 +74,7 @@ readonly ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) readonly excluded_modules=(".devcontainer" ".vscode" "docs") # define an array of files that won't be included in the list -readonly excluded_files=("mkdocs.yml" ".github/dependabot.yml" "sonar-project.properties") +readonly excluded_files=("mkdocs.yml" ".github/dependabot.yml") # define an array of modules that won't be part of the build readonly no_build_modules=("modules/k6") diff --git a/scripts/pre-release.sh b/scripts/pre-release.sh index c4047afe10..f9f885f76e 100755 --- a/scripts/pre-release.sh +++ b/scripts/pre-release.sh @@ -14,7 +14,6 @@ readonly DRY_RUN="${DRY_RUN:-true}" readonly CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" readonly ROOT_DIR="$(dirname "$CURRENT_DIR")" readonly MKDOCS_FILE="${ROOT_DIR}/mkdocs.yml" -readonly SONARCLOUD_FILE="${ROOT_DIR}/sonar-project.properties" readonly VERSION_FILE="${ROOT_DIR}/internal/version.go" readonly REPOSITORY="github.com/testcontainers/testcontainers-go" @@ -42,15 +41,6 @@ function bumpVersion() { mv ${MKDOCS_FILE}.tmp ${MKDOCS_FILE} fi - # Bump version in the sonarcloud properties file - if [[ "${DRY_RUN}" == "true" ]]; then - echo "sed \"s/sonar\.projectVersion=.*/sonar\.projectVersion=${versionToBump}/g\" ${SONARCLOUD_FILE} > ${SONARCLOUD_FILE}.tmp" - echo "mv ${SONARCLOUD_FILE}.tmp ${SONARCLOUD_FILE}" - else - sed "s/sonar\.projectVersion=.*/sonar\.projectVersion=${versionToBump}/g" ${SONARCLOUD_FILE} > ${SONARCLOUD_FILE}.tmp - mv ${SONARCLOUD_FILE}.tmp ${SONARCLOUD_FILE} - fi - # Bump version across all modules, in their go.mod files for directory in "${DIRECTORIES[@]}" do diff --git a/scripts/release.sh b/scripts/release.sh index b675cb51e2..ed4bd60764 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -18,7 +18,6 @@ readonly DRY_RUN="${DRY_RUN:-true}" readonly CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" readonly ROOT_DIR="$(dirname "$CURRENT_DIR")" readonly MKDOCS_FILE="${ROOT_DIR}/mkdocs.yml" -readonly SONARCLOUD_FILE="${ROOT_DIR}/sonar-project.properties" readonly VERSION_FILE="${ROOT_DIR}/internal/version.go" readonly REPOSITORY="github.com/testcontainers/testcontainers-go" @@ -126,7 +125,6 @@ function gitCommitVersion() { gitFn add "${VERSION_FILE}" gitFn add "${MKDOCS_FILE}" - gitFn add "${SONARCLOUD_FILE}" gitFn add "docs/**/*.md" gitFn add "examples/**/go.*" gitFn add "modules/**/go.*" From da09a144b91a072035f09b95d260b3516ea8ff78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 13 Mar 2025 17:56:12 +0100 Subject: [PATCH 6/7] chore: set project key and name without slashes --- .github/workflows/ci-test-go.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-test-go.yml b/.github/workflows/ci-test-go.yml index a42015720a..a33b35ffdf 100644 --- a/.github/workflows/ci-test-go.yml +++ b/.github/workflows/ci-test-go.yml @@ -103,10 +103,17 @@ jobs: if: always() - - name: Extract Testcontainers Go version from mkdocs.yml + - name: Set Sonar Cloud environment variables if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' }} run: | echo "PROJECT_VERSION=$(grep 'latest_version' mkdocs.yml | cut -d':' -f2 | tr -d ' ')" >> $GITHUB_ENV + if [ "${{ inputs.project-directory }}" = "." ]; then + echo "PROJECT_KEY=testcontainers_testcontainers-go" >> $GITHUB_ENV + echo "PROJECT_NAME=testcontainers-go" >> $GITHUB_ENV + else + echo "PROJECT_KEY=testcontainers_testcontainers-go_$(echo ${{ inputs.project-directory }} | tr '/' '_')" >> $GITHUB_ENV + echo "PROJECT_NAME=testcontainers-go-$(echo ${{ inputs.project-directory }} | tr '/' '-')" >> $GITHUB_ENV + fi - name: SonarQube Scan if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' }} @@ -117,8 +124,8 @@ jobs: projectBaseDir: "${{ inputs.project-directory == '.' && 'testcontainers-go' || inputs.project-directory }}" args: > -Dsonar.organization=testcontainers - -Dsonar.projectKey=${{ inputs.project-directory == '.' && 'testcontainers_testcontainers-go' || format('testcontainers_testcontainers-go_%s', inputs.project-directory) }} - -Dsonar.projectName=${{ inputs.project-directory == '.' && 'testcontainers-go' || 'testcontainers-go/'inputs.project-directory }} + -Dsonar.projectKey=${{ env.PROJECT_KEY }} + -Dsonar.projectName=${{ env.PROJECT_NAME }} -Dsonar.projectVersion=${{ env.PROJECT_VERSION }} -Dsonar.project.monorepo.enabled=true -Dsonar.sources=. From 2d3d0dec7a421f8d48be4ef70075d29c7524ca38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 13 Mar 2025 18:14:42 +0100 Subject: [PATCH 7/7] chore: do not run sonar for core rootless/ryukless --- .github/workflows/ci-test-go.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-test-go.yml b/.github/workflows/ci-test-go.yml index a33b35ffdf..d0a9a0f6e1 100644 --- a/.github/workflows/ci-test-go.yml +++ b/.github/workflows/ci-test-go.yml @@ -85,13 +85,6 @@ jobs: timeout-minutes: 30 run: make test-unit - - name: Set sonar artifact name - # For the core library, where the project directory is '.', we'll use "core" as artifact name. - # For the modules, we'll remove the slashes, keeping the name of the module - if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' && matrix.platform == 'ubuntu-latest' && !inputs.rootless-docker && !inputs.ryuk-disabled }} - run: | - echo "ARTIFACT_NAME=$(basename ${{ inputs.project-directory == '.' && 'core' || inputs.project-directory }})-${{ inputs.go-version }}-${{ matrix.platform }}" >> $GITHUB_ENV - - name: Run checker run: | ./scripts/check_environment.sh @@ -104,7 +97,7 @@ jobs: - name: Set Sonar Cloud environment variables - if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' }} + if: ${{ !inputs.rootless-docker && !inputs.ryuk-disabled && github.ref_name == 'main' && github.repository_owner == 'testcontainers' }} run: | echo "PROJECT_VERSION=$(grep 'latest_version' mkdocs.yml | cut -d':' -f2 | tr -d ' ')" >> $GITHUB_ENV if [ "${{ inputs.project-directory }}" = "." ]; then @@ -116,7 +109,7 @@ jobs: fi - name: SonarQube Scan - if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' }} + if: ${{ !inputs.rootless-docker && !inputs.ryuk-disabled && github.ref_name == 'main' && github.repository_owner == 'testcontainers' }} uses: SonarSource/sonarqube-scan-action@0303d6b62e310685c0e34d0b9cde218036885c4d # v5.0.0 env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}