4242 TESTCONTAINERS_RYUK_DISABLED : " ${{ inputs.ryuk-disabled }}"
4343 RYUK_CONNECTION_TIMEOUT : " ${{ inputs.project-directory == 'modules/compose' && '5m' || '60s' }}"
4444 RYUK_RECONNECTION_TIMEOUT : " ${{ inputs.project-directory == 'modules/compose' && '30s' || '10s' }}"
45+ SHOULD_RUN_SONAR : " false"
4546 strategy :
4647 matrix :
4748 platform : ${{ fromJSON(inputs.platforms) }}
5556
5657 - name : Check out code into the Go module directory
5758 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
59+ with :
60+ # Disabling shallow clone is recommended for improving relevancy of reporting
61+ fetch-depth : 0
5862
5963 - name : Set up Go
6064 uses : actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
8286 timeout-minutes : 30
8387 run : make test-unit
8488
85- - name : Set sonar artifact name
86- # For the core library, where the project directory is '.', we'll use "core" as artifact name.
87- # For the modules, we'll remove the slashes, keeping the name of the module
88- if : ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' && matrix.platform == 'ubuntu-latest' && !inputs.rootless-docker && !inputs.ryuk-disabled }}
89- run : |
90- echo "ARTIFACT_NAME=$(basename ${{ inputs.project-directory == '.' && 'core' || inputs.project-directory }})-${{ inputs.go-version }}-${{ matrix.platform }}" >> $GITHUB_ENV
91-
92- - name : Upload SonarCloud files
93- if : ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' && matrix.platform == 'ubuntu-latest' && !inputs.rootless-docker && !inputs.ryuk-disabled }}
94- uses : actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
95- with :
96- name : sonarcloud-${{ env.ARTIFACT_NAME }}
97- path : |
98- ./sonar-project.properties
99- ${{ inputs.project-directory }}/TEST-unit.xml
100- ${{ inputs.project-directory }}/coverage.out
101-
10289 - name : Run checker
10390 run : |
10491 ./scripts/check_environment.sh
@@ -108,3 +95,52 @@ jobs:
10895 with :
10996 paths : " **/${{ inputs.project-directory }}/TEST-unit*.xml"
11097 if : always()
98+
99+ - name : Decide if Sonar must be run
100+ if : ${{ matrix.platform == 'ubuntu-latest' }}
101+ run : |
102+ if [[ "1.23.x" == "${{ inputs.go-version }}" ]] && \
103+ [[ "true" != "${{ inputs.rootless-docker }}" ]] && \
104+ [[ "true" != "${{ inputs.ryuk-disabled }}" ]] && \
105+ [[ "main" == "${{ github.ref_name }}" ]] && \
106+ [[ "testcontainers" == "${{ github.repository_owner }}" ]]; then
107+ echo "SHOULD_RUN_SONAR=true" >> $GITHUB_ENV
108+ fi
109+
110+ - name : Set Sonar Cloud environment variables
111+ if : ${{ env.SHOULD_RUN_SONAR == 'true' }}
112+ run : |
113+ echo "PROJECT_VERSION=$(grep 'latest_version' mkdocs.yml | cut -d':' -f2 | tr -d ' ')" >> $GITHUB_ENV
114+ if [ "${{ inputs.project-directory }}" == "" ]; then
115+ echo "PROJECT_KEY=testcontainers_testcontainers-go" >> $GITHUB_ENV
116+ echo "PROJECT_NAME=testcontainers-go" >> $GITHUB_ENV
117+ echo "PROJECT_SRC_EXCLUSIONS=**/*_test.go,**/vendor/**,**/testdata/**,modules/**,examples/**,modulegen/**" >> $GITHUB_ENV
118+ echo "PROJECT_TEST_EXCLUSIONS=**/vendor/**,modules/**,examples/**,modulegen/**" >> $GITHUB_ENV
119+ else
120+ echo "PROJECT_KEY=testcontainers_testcontainers-go_$(echo ${{ inputs.project-directory }} | tr '/' '_')" >> $GITHUB_ENV
121+ echo "PROJECT_NAME=testcontainers-go-$(echo ${{ inputs.project-directory }} | tr '/' '-')" >> $GITHUB_ENV
122+ echo "PROJECT_SRC_EXCLUSIONS=**/*_test.go,**/vendor/**,**/testdata/**" >> $GITHUB_ENV
123+ echo "PROJECT_TEST_EXCLUSIONS=**/vendor/**" >> $GITHUB_ENV
124+ fi
125+
126+ - name : SonarQube Scan
127+ if : ${{ env.SHOULD_RUN_SONAR == 'true' }}
128+ uses : SonarSource/sonarqube-scan-action@0303d6b62e310685c0e34d0b9cde218036885c4d # v5.0.0
129+ env :
130+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
131+ with :
132+ projectBaseDir : " ${{ inputs.project-directory == '' && '.' || inputs.project-directory }}"
133+ args : >
134+ -Dsonar.organization=testcontainers
135+ -Dsonar.projectKey=${{ env.PROJECT_KEY }}
136+ -Dsonar.projectName=${{ env.PROJECT_NAME }}
137+ -Dsonar.projectVersion=${{ env.PROJECT_VERSION }}
138+ -Dsonar.project.monorepo.enabled=true
139+ -Dsonar.branch.name=main
140+ -Dsonar.sources=.
141+ -Dsonar.exclusions=${{ env.PROJECT_SRC_EXCLUSIONS }}
142+ -Dsonar.tests=.
143+ -Dsonar.test.inclusions=**/*_test.go
144+ -Dsonar.test.exclusions=${{ env.PROJECT_TEST_EXCLUSIONS }}
145+ -Dsonar.go.coverage.reportPaths=coverage.out
146+ -Dsonar.go.tests.reportPaths=TEST-unit.xml
0 commit comments