Skip to content

Commit c881804

Browse files
authored
fix(sonar): run on ubuntu and the lowest Go version (testcontainers#3037)
* fix(sonar): run on ubuntu and the lowest Go version * fix(sonar): exclude modules and examples from the core * chore: calculate filter first * chore: fix
1 parent dca6a9b commit c881804

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

.github/workflows/ci-test-go.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
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) }}
@@ -95,20 +96,35 @@ jobs:
9596
paths: "**/${{ inputs.project-directory }}/TEST-unit*.xml"
9697
if: always()
9798

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+
98110
- name: Set Sonar Cloud environment variables
99-
if: ${{ !inputs.rootless-docker && !inputs.ryuk-disabled && github.ref_name == 'main' && github.repository_owner == 'testcontainers' }}
111+
if: ${{ env.SHOULD_RUN_SONAR == 'true' }}
100112
run: |
101113
echo "PROJECT_VERSION=$(grep 'latest_version' mkdocs.yml | cut -d':' -f2 | tr -d ' ')" >> $GITHUB_ENV
102114
if [ "${{ inputs.project-directory }}" == "" ]; then
103115
echo "PROJECT_KEY=testcontainers_testcontainers-go" >> $GITHUB_ENV
104116
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
105119
else
106120
echo "PROJECT_KEY=testcontainers_testcontainers-go_$(echo ${{ inputs.project-directory }} | tr '/' '_')" >> $GITHUB_ENV
107121
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
108124
fi
109125
110126
- name: SonarQube Scan
111-
if: ${{ !inputs.rootless-docker && !inputs.ryuk-disabled && github.ref_name == 'main' && github.repository_owner == 'testcontainers' }}
127+
if: ${{ env.SHOULD_RUN_SONAR == 'true' }}
112128
uses: SonarSource/sonarqube-scan-action@0303d6b62e310685c0e34d0b9cde218036885c4d # v5.0.0
113129
env:
114130
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
@@ -121,9 +137,9 @@ jobs:
121137
-Dsonar.projectVersion=${{ env.PROJECT_VERSION }}
122138
-Dsonar.project.monorepo.enabled=true
123139
-Dsonar.sources=.
124-
-Dsonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/**
140+
-Dsonar.exclusions=${{ env.PROJECT_SRC_EXCLUSIONS }}
125141
-Dsonar.tests=.
126142
-Dsonar.test.inclusions=**/*_test.go
127-
-Dsonar.test.exclusions=**/vendor/**
143+
-Dsonar.test.exclusions=${{ env.PROJECT_TEST_EXCLUSIONS }}
128144
-Dsonar.go.coverage.reportPaths=coverage.out
129145
-Dsonar.go.tests.reportPaths=TEST-unit.xml

scripts/bump-go.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ function bumpCIMatrix() {
6262
if [[ "${DRY_RUN}" == "true" ]]; then
6363
echo "sed \"s/go-version: \[${oldGoVersion}/go-version: \[${newGoVersion}/g\" ${file} > ${file}.tmp"
6464
echo "sed \"s/go-version: \\"${oldGoVersion}.x\"/go-version: \\"${newGoVersion}.x\"/g\" ${file}.tmp > ${file}.tmp"
65+
echo "sed \"s/go-version == '\"${oldGoVersion}\.x\"'/go-version == '\"${newGoVersion}\.x\"'/g\" ${file}.tmp > ${file}.tmp"
6566
echo "mv ${file}.tmp ${file}"
6667
else
6768
sed "s/go-version: \[${oldGoVersion}/go-version: \[${newGoVersion}/g" ${file} > ${file}.tmp
6869
mv ${file}.tmp ${file}
6970
sed "s/go-version: \"${oldGoVersion}\.x\"/go-version: \"${newGoVersion}\.x\"/g" ${file} > ${file}.tmp
7071
mv ${file}.tmp ${file}
72+
sed "s/go-version == '\"${oldGoVersion}\.x\"'/go-version == '\"${newGoVersion}\.x\"'/g" ${file} > ${file}.tmp
73+
mv ${file}.tmp ${file}
7174
fi
7275
}
7376

0 commit comments

Comments
 (0)