Chore/qa 1202 sonarqube integration #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Unit testing and static analysis | |
on: | |
push: | |
branches: | |
- develop | |
pull_request: | |
jobs: | |
tools: | |
name: Get tool-versions | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out Code | |
uses: actions/checkout@v3 | |
- name: Parse tool-versions file | |
uses: smartcontractkit/[email protected] | |
id: tool-versions | |
outputs: | |
go-version: ${{ steps.tool-versions.outputs.golang_version }} | |
golangci-lint-version: ${{ steps.tool-versions.outputs.golangci-lint_version }} | |
golangci: | |
name: Golang Lint | |
runs-on: ubuntu-latest | |
needs: [tools] | |
steps: | |
- name: Check out Code | |
uses: actions/checkout@v3 | |
- name: Install Go ${{ needs.tools.outputs.go-version }} | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ needs.tools.outputs.go-version }} | |
- name: golangci-lint ${{ needs.tools.outputs.golangci-lint-version }} | |
## | |
# XXX: change this to the official action once multiple --out-format args are supported. | |
# See: https://github.com/golangci/golangci-lint-action/issues/612 | |
## | |
uses: smartcontractkit/golangci-lint-action@54ab6c5f11d66a92d14c3f7cc41ea13f676644bd # feature/multiple-output-formats-backup | |
with: | |
version: v${{ needs.tools.outputs.golangci-lint-version }} # keep golangci-lint 1.51.1 for multiple --out-format | |
allow-extra-out-format-args: true | |
args: --out-format checkstyle:golangci-lint-report.xml --enable=gofmt --tests=false --exclude-use-default --timeout=5m0s | |
only-new-issues: true | |
- name: Print lint report artifact | |
if: always() | |
run: test -f golangci-lint-report.xml || true | |
- name: Store lint report artifact | |
if: always() | |
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0 | |
with: | |
name: golangci-lint-report | |
path: golangci-lint-report.xml | |
relay_run_unit_tests: | |
name: Relay Run Unit Tests | |
runs-on: ubuntu-latest | |
needs: [tools] | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | |
- name: Setup go ${{ needs.tools.outputs.go-version }} | |
uses: actions/setup-go@v4 | |
with: | |
# go-version-file: "go.mod" | |
check-latest: true | |
go-version: ${{ needs.tools.outputs.go-version }} | |
- name: Check go mod tidy | |
run: | | |
go mod tidy | |
echo "if this fails run 'go mod tidy' to fix" | |
git diff --stat --exit-code | |
- name: Install Solana CLI | |
run: ./scripts/install-solana-ci.sh | |
- name: Build | |
run: go build -v ./pkg/... | |
- name: Test | |
run: go test ./pkg/... -v -tags integration -covermode=atomic -coverpkg=./... -coverprofile=coverage.txt | |
- name: Test with the race detector enabled | |
run: go test ./pkg/... -v -race -count=10 -timeout=15m -coverpkg=./... -coverprofile=race_coverage.txt | |
- name: Upload Go test results | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: go-test-results | |
path: | | |
./output.txt | |
./coverage.txt | |
./race_coverage.txt | |
sonarqube: | |
name: SonarQube Scan | |
needs: [golangci, relay_run_unit_tests] | |
runs-on: ubuntu-latest | |
if: ${{ always() }} | |
steps: | |
- name: Fetch blame information | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
with: | |
fetch-depth: 0 # fetches all history for all tags and branches to provide more metadata for sonar reports | |
- name: Download all workflow run artifacts | |
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3.0.1 | |
- name: Set SonarQube Report Paths | |
id: sonarqube_report_paths | |
shell: bash | |
run: | | |
{ | |
echo "sonarqube_tests_report_paths=$(find . -type f -name output.txt | paste -sd "," -)" | |
echo "sonarqube_coverage_report_paths=$(find . -type f -name '*coverage.txt' | paste -sd "," -)" | |
echo "sonarqube_golangci_report_paths=$(find . -type f -name 'golangci-lint-report.xml' -printf "%p,")" | |
} >> "$GITHUB_OUTPUT" | |
- name: SonarQube Scan | |
uses: sonarsource/sonarqube-scan-action@a6ba0aafc293e03de5437af7edbc97f7d3ebc91a # v1.2.0 | |
with: | |
args: > | |
-Dsonar.go.tests.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_tests_report_paths }} | |
-Dsonar.go.coverage.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_coverage_report_paths }} | |
-Dsonar.go.golangci-lint.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_golangci_report_paths }} | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} | |