Skip to content

Commit

Permalink
Exclude tests and mocks from capabilities SonarQube coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
chudilka1 committed Oct 14, 2024
1 parent cdeea8f commit 4b79517
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 63 deletions.
31 changes: 13 additions & 18 deletions .github/workflows/golangci_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@ on: [pull_request]
jobs:
golangci-lint:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
actions: read
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
- name: ci-lint
uses: smartcontractkit/.github/actions/ci-lint-go@7a4d99cb349ea8f25195d2390d157942031f8a57 # [email protected]
with:
go-version-file: "go.mod"
- name: Build binary
shell: bash
run: go build ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
version: v1.60.1
# only-new-issues is only applicable to PRs, otherwise it is always set to false
only-new-issues: true
args: --out-format colored-line-number,checkstyle:golangci-lint-report.xml
- name: Print lint report artifact
if: failure()
shell: bash
run: cat ./golangci-lint-report.xml
# grafana inputs
metrics-job-name: golangci-lint
gc-basic-auth: ${{ secrets.GRAFANA_INTERNAL_BASIC_AUTH }}
gc-host: ${{ secrets.GRAFANA_INTERNAL_HOST }}
gc-org-id: ${{ secrets.GRAFANA_INTERNAL_TENANT_ID }}
go-version-file: go.mod

46 changes: 5 additions & 41 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,10 @@ jobs:
runs-on: ubuntu-latest
if: always()
steps:
- name: Checkout the repo
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0 # fetches all history for all tags and branches to provide more metadata for sonar reports

- name: Download Golangci-lint report
if: always()
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
with:
workflow: golangci_lint.yml
workflow_conclusion: ""
name_is_regexp: true
name: golangci-lint-report
if_no_artifact_found: warn

- name: Download Go PKG test reports
if: always()
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
with:
workflow: pkg.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@53c3e3207fe4b8d52e2f1ac9d6eb1d2506f626c0 # v2.0.2
uses: smartcontractkit/.github/actions/ci-sonarqube-go@dca9ab89d734e82738b8aa52bd25d09b205ec6ee # v0.1.1
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 }}
# sonarqube inputs
include-lint: "true"
sonar-token: ${{ secrets.SONAR_TOKEN }}
sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
**/testdata/fuzz/*

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# IntelliJ IDE
.idea

vendor/
# Visual Studio Code
.vscode

# Generated files
*.wasm
40 changes: 40 additions & 0 deletions fail_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"errors"
"os"
"sync"
"testing"
)

func TestFail(t *testing.T) {
if testing.Short() {
t.Skip()
}
t.Fatal("fake failure")
}

func TestRace(t *testing.T) {
var v int
var wg sync.WaitGroup
wg.Add(100)
for i := 0; i < 100; i++ {
go func() {
defer wg.Done()
v++
v--
}()
}
wg.Wait()
t.Log(v)
}

func TestLint(t *testing.T) {
const UnusedVar = 1 // lint should complain for unused variable
const ALL_CAPS = 10 // should be AllCaps
err := os.ErrNotExist
if err == os.ErrNotExist { // should use errors.Is
err := errors.New("fake error") // shadowed variable
t.Log(err)
}
}
11 changes: 9 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ sonar.exclusions=\
**/*report.xml,\
**/*.txt,\
**/*.abi,\
**/*.bin
**/*.bin,\
**/generated_*,\
**/*_generated.go,\
**/mock_*.go

# Coverage exclusions
sonar.coverage.exclusions=\
**/test/**/*,\
**/*_test.go,\
observability-lib/**,\
**/fuzz/**/*
**/fuzz/**/*,\
**/capabilities/consensus/ocr3/ocr3cap/ocr3captest/**/*,\
**/capabilities/targets/chainwriter/chainwritertest/**/*,\
**/capabilities/triggers/streams/streamstest/**/*


# Tests' root folder, inclusions (tests to check and count) and exclusions
sonar.tests=.
Expand Down

0 comments on commit 4b79517

Please sign in to comment.