Skip to content

Commit

Permalink
ci(sonarcloud): upload artifact (#1614)
Browse files Browse the repository at this point in the history
* ci(sonarcloud): upload artifact

* Update ci-test-go.yml

* Apply suggestions from code review

* Update ci-test-go.yml

* Update ci-test-go.yml

* Update ci.yml
  • Loading branch information
mmorel-35 committed Sep 13, 2023
1 parent 4c6a989 commit eb91328
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 28 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/ci-test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
# Optional: working directory, useful for monorepos
working-directory: ${{ inputs.project-directory }}
# Optional: golangci-lint command line arguments.
args: --verbose --out-format=checkstyle:golangci-lint.report.xml
args: --verbose
# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
skip-cache: true
Expand Down Expand Up @@ -107,15 +107,16 @@ 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.rootless-docker && inputs.project-directory == '.' }}
uses: sonarsource/sonarcloud-github-action@master
- name: Upload SonarCloud files
if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' && inputs.run-tests && !inputs.rootless-docker }}
uses: actions/upload-artifact@v3
with:
projectBaseDir: ${{ inputs.project-directory }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
name: sonarcloud
path: |
./sonar-project.properties
${{ inputs.project-directory }}/TEST-unit.xml
${{ inputs.project-directory }}/coverage.out
- name: Run checker
run: |
Expand Down
28 changes: 22 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ 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 @@ -52,7 +51,6 @@ 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 @@ -74,7 +72,6 @@ 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 @@ -92,7 +89,6 @@ 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 @@ -112,7 +108,6 @@ 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 @@ -130,7 +125,6 @@ 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 All @@ -139,3 +133,25 @@ jobs:
rootless-docker: false
run-tests: true
ryuk-disabled: false

sonarcloud:
if: ${{ always() && github.ref_name == 'main' && github.repository_owner == 'testcontainers' }}
needs: test-examples
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0

- uses: actions/download-artifact@v3
with:
name: sonarcloud

- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

2 changes: 1 addition & 1 deletion commons-test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test-%:
--format short-verbose \
--rerun-fails=5 \
--packages="./..." \
--junitfile TEST-$*.xml \
--junitfile TEST-unit.xml \
-- \
-coverprofile=coverage.out \
-timeout=30m
Expand Down
27 changes: 21 additions & 6 deletions modulegen/_template/ci.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ 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 @@ -52,7 +51,6 @@ 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 @@ -74,7 +72,6 @@ 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 @@ -92,7 +89,6 @@ 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 @@ -112,7 +108,6 @@ 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 @@ -130,7 +125,6 @@ jobs:
matrix:
module: [{{ .Examples }}]
uses: ./.github/workflows/ci-test-go.yml
secrets: inherit
with:
go-version: "1.20.x"
fail-fast: true
Expand All @@ -139,3 +133,24 @@ jobs:
rootless-docker: false
run-tests: true
ryuk-disabled: false

sonarcloud:
if: {{ "${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' }}" }}
needs: test-examples
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0

- uses: actions/download-artifact@v3
with:
name: sonarcloud

- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}
SONAR_TOKEN: {{ "${{ secrets.SONAR_TOKEN }}" }}
4 changes: 2 additions & 2 deletions modulegen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,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[112])
assert.Equal(t, " module: ["+strings.Join(modulesList, ", ")+"]", data[108])

examplesList, err := ctx.GetExamples()
assert.Nil(t, err)
assert.Equal(t, " module: ["+strings.Join(examplesList, ", ")+"]", data[130])
assert.Equal(t, " module: ["+strings.Join(examplesList, ", ")+"]", data[125])
}

// assert content go.mod
Expand Down
7 changes: 3 additions & 4 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ sonar.projectVersion=v0.23.0

sonar.sources=.

sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/*
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.golangci-lint.reportPaths=golangci-lint.report.xml
sonar.go.tests.reportPaths=TEST-unit.xml
sonar.go.coverage.reportPaths=**/coverage.out
sonar.go.tests.reportPaths=**/TEST-unit.xml

0 comments on commit eb91328

Please sign in to comment.