Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonarQube integration #307

Merged
merged 7 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ jobs:
nix_path: nixpkgs=channel:nixos-unstable
- name: Lint relayer
run: nix develop -c make lint-go-relayer
- name: Store Golangci lint relayer report artifact
if: always()
smickovskid marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: golangci-lint-relayer-report
path: ./relayer/golangci-lint-relayer-report.xml

golang_lint_ops:
name: Golang Lint Ops
Expand All @@ -52,6 +58,12 @@ jobs:
nix_path: nixpkgs=channel:nixos-unstable
- name: Lint ops
run: nix develop -c make lint-go-ops
- name: Store Golangci lint ops report artifact
if: always()
smickovskid marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: golangci-lint-ops-report
path: ./ops/golangci-lint-ops-report.xml

golang_lint_integration_tests:
name: Golang Lint Integration Tests
Expand All @@ -66,6 +78,12 @@ jobs:
nix_path: nixpkgs=channel:nixos-unstable
- name: Lint integration-tests
run: nix develop -c make lint-go-test
- name: Store Golangci lint integration tests report artifact
if: always()
smickovskid marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: golangci-lint-integration-tests-report
path: ./integration-tests/golangci-lint-integration-tests-report.xml
# Note: I could not figure out why the golangci-lint-action would not work even though it is technically running the same as above, error message is this:
# Running [/home/runner/golangci-lint-1.50.1-linux-amd64/golangci-lint run --out-format=github-actions --path-prefix=integration-tests --exclude=dot-imports] in [/home/runner/work/chainlink-starknet/chainlink-starknet/integration-tests] ...
# level=warning msg="[runner] Can't run linter goanalysis_metalinter: inspect: failed to load package client: could not load export data: no export data for \"github.com/smartcontractkit/chainlink-testing-framework/client\""
Copy link

@chudilka1 chudilka1 Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The report is generated, take a look here
I believe the version of the linter, should be bumped to v1.51.1 # this version has an --out-format checkstyle necessary for Sonar
Ref: smartcontractkit/golangci-lint-action@54ab6c5

To test, you can try adding the unused variable to a go file analyzed by linter, eventually you should get a code smell in Sonar with label GOLANGCI-LINT. ⚠️ Better to test whether all the separately analyzed parts of the code produce the corresponding results in Sonar

image

Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/relayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ jobs:

- name: Unit Test
run: nix develop -c make test-unit-go

- name: Upload Golangci relayer results
if: always()
smickovskid marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/upload-artifact@v3
with:
name: go-unit-tests-results
path: |
./relayer/output.txt
./relayer/coverage.txt
./relayer/race_coverage.txt

- name: Install starknet-devnet (via venv+pip)
run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt
Expand Down
97 changes: 97 additions & 0 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: SonarQube Scan
smickovskid marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches:
- develop
pull_request:

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
id: wait
uses: smartcontractkit/chainlink-github-actions/utils/wait-for-workflows@main
with:
max-timeout: "1200"
polling-interval: "30"
exclude-workflow-names: "Amarna Analysis,Changesets,Integration Contracts (Vendor, Examples),Integration Gauntlet,Integration Tests Publish,Integration Tests - Smoke,Integration Tests - Soak,Build and push on-chain monitor image to ECR,Contracts,Lint"
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()
smickovskid marked this conversation as resolved.
Show resolved Hide resolved
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 unit tests reports
uses: dawidd6/[email protected]
with:
workflow: relayer.yml
workflow_conclusion: ""
name_is_regexp: true
name: go-unit-tests-results
if_no_artifact_found: warn

- name: Download Golangci Relayer report
uses: dawidd6/[email protected]
with:
workflow: golangci-lint.yml
workflow_conclusion: ""
name_is_regexp: true
name: golangci-lint-relayer-report
if_no_artifact_found: warn

- name: Download Golangci Ops report
uses: dawidd6/[email protected]
with:
workflow: golangci-lint.yml
workflow_conclusion: ""
name_is_regexp: true
name: golangci-lint-ops-report
if_no_artifact_found: warn

- name: Download Go Integration tests report
uses: dawidd6/[email protected]
with:
workflow: golangci-lint.yml
workflow_conclusion: ""
name_is_regexp: true
smickovskid marked this conversation as resolved.
Show resolved Hide resolved
name: golangci-lint-integration-tests-report
if_no_artifact_found: warn

- 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-*-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 }}
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ bin

.DS_Store
.temp/
coverage/
coverage.json

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -60,11 +58,13 @@ pip-delete-this-directory.txt
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
*report.xml
*report.json
*.out
*coverage*
testdata/
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ format-ts-check:

.PHONY: lint-go-ops
lint-go-ops:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use this opportunity to make these Makefile actions and CI workflows consistent across our projects (Solana, Cosmos, Starknet).

cd ./ops && golangci-lint --color=always run
cd ./ops && golangci-lint --color=always --out-format checkstyle:golangci-lint-ops-report.xml run

.PHONY: lint-go-relayer
lint-go-relayer:
cd ./relayer && golangci-lint --color=always run
cd ./relayer && golangci-lint --color=always --out-format checkstyle:golangci-lint-relayer-report.xml run

.PHONY: lint-go-test
lint-go-test:
cd ./integration-tests && golangci-lint --color=always --exclude=dot-imports run
cd ./integration-tests && golangci-lint --color=always --exclude=dot-imports --out-format checkstyle:golangci-lint-integration-tests-report.xml run

.PHONY: test-go
test-go: test-unit-go test-integration-go
Expand All @@ -175,8 +175,8 @@ test-unit: test-unit-go

.PHONY: test-unit-go
test-unit-go:
cd ./relayer && go test -v ./...
cd ./relayer && go test -v ./... -race -count=10
cd ./relayer && go test -v ./... -covermode=atomic -coverpkg=./... -coverprofile=coverage.txt
cd ./relayer && go test -v ./... -race -count=10 -coverpkg=./... -coverprofile=race_coverage.txt

.PHONY: test-integration-go
# only runs tests with TestIntegration_* + //go:build integration
Expand Down
13 changes: 13 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# required (may be found under "Project Information" in SonarQube)
sonar.projectKey=smartcontractkit_chainlink-starknet
sonar.sources=.

# Full exclusions from the static analysis
sonar.exclusions=**/vendor/**/*, **/contracts/**/*, **/mocks/**/*, **/examples/**/*, **/node_modules/**/*, **/docs/**/*, **/scripts/**/*, **/*.config.ts, **/*.config.js, **/*.txt
# Coverage exclusions
sonar.coverage.exclusions=**/*.test.ts, **/*_test.go, **/integration-tests/**/*, **/ops/**/*, **/test/**/*, **/testdata/**/*

# Tests' root folder, inclusions (tests to check and count) and exclusions
sonar.tests=.
sonar.test.inclusions=**/*_test.go, **/*.test.ts, **/test/**/*
sonar.test.exclusions=**/integration-tests/**/*