Skip to content

Commit

Permalink
Update Sonar configs in git workflows to fit repo's modular structure
Browse files Browse the repository at this point in the history
  • Loading branch information
chudilka1 committed Jul 28, 2023
1 parent b7a4e2a commit c57f446
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 122 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/golangci_lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Golangci-lint

on: [push]

jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Install golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3

# go.work makes it necessary to run linter manually
- name: Run golangci-lint
run: find . -name "go.mod" -execdir $(go env GOPATH)/bin/golangci-lint run --enable=gofmt --tests=false --exclude-use-default --timeout=5m0s --out-format checkstyle:golangci-lint-report.xml \;

- name: Check golangci-lint report for errors
run: find . -name "golangci-lint-report.xml" -exec grep "error" {} + && exit 1 || true

- name: Upload golangci-lint report
if: always()
uses: actions/upload-artifact@v3
with:
name: golangci-lint-report
path: |
./ops/golangci-lint-report.xml
./golangci-lint-report.xml
49 changes: 15 additions & 34 deletions .github/workflows/ops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,23 @@ jobs:
relay-ops:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- name: Build
run: cd ops && go build -v
- name: Test
run: cd ops && go test -v ./...
- name: Checkout
uses: actions/checkout@v3

golangci-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.51.1

# Optional: working directory, useful for monorepos
working-directory: ops

# Optional: golangci-lint command line arguments.
args: --enable=gofmt --tests=false --exclude-use-default --timeout=5m0s

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true
- name: Build ops
run: cd ops && go build -v

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
- name: Unit test ops
run: cd ops && go test ./... -coverpkg=./... -coverprofile=ops_coverage.out

- name: Upload Go ops test results
if: always()
uses: actions/upload-artifact@v3
with:
name: go-test-results
path: ./ops/ops_coverage.out
91 changes: 3 additions & 88 deletions .github/workflows/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,6 @@ on:
push:

jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'

##
# XXX: change this to the official action once multiple --out-format args are supported.
# See: https://github.com/golangci/golangci-lint-action/issues/612
##
- name: golangci-lint
uses: smartcontractkit/golangci-lint-action@54ab6c5f11d66a92d14c3f7cc41ea13f676644bd # feature/multiple-output-formats-backup
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.52.1

# Optional: working directory, useful for monorepos
# working-directory:

# Optional: golangci-lint command line arguments.
allow-extra-out-format-args: true
args: --enable=gofmt --tests=false --exclude-use-default --timeout=5m0s --out-format checkstyle:golangci-lint-report.xml

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true

- name: Print lint report artifact
if: always()
run: test -f golangci-lint-report.xml && cat golangci-lint-report.xml || true

- name: Upload lint report artifact
if: always()
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: golangci-lint-report
path: golangci-lint-report.xml

build-test:
runs-on: ubuntu-latest
steps:
Expand All @@ -66,48 +15,14 @@ jobs:
go-version-file: 'go.mod'

- name: Build
run: go build -v ./...
run: cd pkg go build -v ./...

- name: Unit Tests
run: go test -race ./... -coverpkg=./... -coverprofile=coverage.txt
run: go test -race ./... -coverpkg=./... -coverprofile=pkg_coverage.out

- name: Upload Go test results
if: always()
uses: actions/upload-artifact@v3
with:
name: go-test-results
path: |
./output.txt
./coverage.txt
sonar-scan:
name: SonarQube
needs: [golangci-lint, build-test]
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
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' -printf "%p,")" >> $GITHUB_OUTPUT
echo "sonarqube_coverage_report_paths=$(find -type f -name 'coverage.txt' -printf "%p,")" >> $GITHUB_OUTPUT
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 }}
path: ./pkg_coverage.out
73 changes: 73 additions & 0 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: SonarQube Scan

on: [push]

jobs:
wait_for_workflows:
name: Wait for workflows
runs-on: ubuntu-latest
if: always()
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha }}

- name: Wait for workflows
uses: smartcontractkit/chainlink-github-actions/utils/wait-for-workflows@main
with:
max-timeout: "900"
polling-interval: "30"
exclude-workflow-names: ""
exclude-workflow-ids: ""
github-token: ${{ secrets.GITHUB_TOKEN }}
env:
DEBUG: "true"

sonarqube:
name: SonarQube Scan
needs: [wait_for_workflows]
runs-on: ubuntu-latest
if: always()
steps:
- name: Checkout the repo
uses: actions/checkout@v3
with:
fetch-depth: 0 # fetches all history for all tags and branches to provide more metadata for sonar reports

- name: Download Golangci-lint report
uses: dawidd6/action-download-artifact@v2.27.0
with:
workflow: golangci-lint.yml
workflow_conclusion: ""
name_is_regexp: true
name: golangci-lint-report
if_no_artifact_found: warn

- name: Download Go test reports
uses: dawidd6/action-download-artifact@v2.27.0
with:
workflow: feeds-manager.yml
workflow_conclusion: ""
name_is_regexp: true
name: go-test-results
if_no_artifact_found: warn

- name: Set SonarQube Report Paths
if: always()
id: sonarqube_report_paths
shell: bash
run: |
echo "sonarqube_coverage_report_paths=$(find -type f -name '*coverage.out' -printf "%p,")" >> $GITHUB_OUTPUT
echo "sonarqube_golangci_report_paths=$(find -type f -name 'golangci-lint-report.xml' -printf "%p,")" >> $GITHUB_OUTPUT
- name: SonarQube Scan
if: always()
uses: sonarsource/sonarqube-scan-action@a6ba0aafc293e03de5437af7edbc97f7d3ebc91a # v1.2.0
with:
args: >
-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 }}

0 comments on commit c57f446

Please sign in to comment.