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 #339

Merged
merged 25 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"ignorePatterns": ["**/node_modules/**"],
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
36 changes: 35 additions & 1 deletion .github/workflows/gauntlet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ jobs:
- run: nix develop -c yarn install --frozen-lockfile
- run: nix develop -c yarn lint:format

gauntlet_eslint:
name: Gauntlet ESLint
env:
CI: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Install Nix
uses: cachix/install-nix-action@29bd9290ef037a3ecbdafe83cbd2185e9dd0fa0a # v20
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: "sandbox = false"
- name: Cache Nix
uses: cachix/cachix-action@v12
with:
name: chainlink-cosmos
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix develop -c yarn install --frozen-lockfile
- run: nix develop -c yarn eslint
- name: Upload eslint report
if: always()
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: gauntlet-eslint-report
path: ./eslint-report.json

gauntlet_run_tests:
name: Gauntlet Run Tests
env:
Expand Down Expand Up @@ -75,4 +101,12 @@ jobs:
run: make contracts_compile

- run: nix develop -c yarn install --frozen-lockfile
- run: nix develop -c yarn test:ci
- run: nix develop -c yarn test:ci --coverage

- name: Upload test coverage report
smickovskid marked this conversation as resolved.
Show resolved Hide resolved
if: always()
cfal marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: typescript-test-coverage
path: ./coverage/lcov.info

25 changes: 10 additions & 15 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ jobs:
- 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: v${{ steps.tool-versions.outputs.golangci-lint_version }}

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

# Optional: golangci-lint command line arguments.
args: --timeout=5m0s --tests=false

# Optional: show only new issues if it's a pull request. The default value is `false`.
args: --timeout=5m0s --tests=false --out-format checkstyle:golangci-lint-report.xml
smickovskid marked this conversation as resolved.
Show resolved Hide resolved
only-new-issues: 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: Store lint report artifact
if: always()
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: golangci-lint-report
path: golangci-lint-report.xml
13 changes: 11 additions & 2 deletions .github/workflows/relay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ jobs:
run: nix develop -c go build -v ./pkg/cosmos/...

- name: Run unit tests
run: nix develop -c go test -v ./pkg/cosmos/...
run: nix develop -c make test_relay_unit

- name: Run tests with the race detector enabled
run: nix develop -c go test -v ./pkg/cosmos/... -race -count=10
run: nix develop -c make test_relay_unit_race

- name: Upload Go test results
if: always()
uses: actions/upload-artifact@v3
with:
name: go-test-results
path: |
./unit_coverage.txt
./race_coverage.txt
102 changes: 102 additions & 0 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: SonarQube Scan

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: "CodeQL,release_contracts,contracts,Integration Tests Publish,e2e_tests_custom_cl,Integration Test (Docker)"
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 report
uses: dawidd6/action-download-artifact@v2.27.0
with:
workflow: golangci-lint.yml
workflow_conclusion: ""
name: golangci-lint-report
if_no_artifact_found: warn

- name: Download relay test reports
uses: dawidd6/action-download-artifact@v2.27.0
with:
workflow: relay.yml
workflow_conclusion: ""
name: go-test-results
smickovskid marked this conversation as resolved.
Show resolved Hide resolved
if_no_artifact_found: warn

- name: Download gauntlet test reports
smickovskid marked this conversation as resolved.
Show resolved Hide resolved
uses: dawidd6/action-download-artifact@v2.27.0
with:
workflow: gauntlet.yml
workflow_conclusion: ""
name_is_regexp: true
name: typescript-test-coverage
if_no_artifact_found: warn

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

- name: Set SonarQube Report Paths
id: sonarqube_report_paths
shell: bash
run: |
echo "sonarqube_go_tests_report_paths=$(find . -type f -name 'output.txt' -printf "%p,")" >> $GITHUB_OUTPUT
echo "sonarqube_go_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
echo "sonarqube_eslint_report_paths=$(find -type f -name 'eslint-report.json' -printf "%p")" >> $GITHUB_OUTPUT
echo "sonarqube_ts_js_coverage_report_paths=$(find . -type f -name 'lcov.info' -printf "%p,")" >> $GITHUB_OUTPUT

- name: Update ESLint report symlinks
continue-on-error: true
run: sed -i 's+/home/runner/work/feeds-manager/feeds-manager/+/github/workspace/+g' ${{ steps.sonarqube_report_paths.outputs.sonarqube_eslint_report_paths }}

- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@a6ba0aafc293e03de5437af7edbc97f7d3ebc91a # v1.2.0
with:
args: >
-Dsonar.go.tests.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_go_tests_report_paths }}
-Dsonar.go.coverage.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_go_coverage_report_paths }}
-Dsonar.go.golangci-lint.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_golangci_report_paths }}
-Dsonar.eslint.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_eslint_report_paths }}
-Dsonar.javascript.lcov.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_ts_js_coverage_report_paths }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ report.json
.envrc
bin

# test
# test & linter reports
packages-ts/gauntlet-cosmos-contracts/codeIds/test*
packages-ts/gauntlet-cosmos-contracts/networks/.env.test*
tests/e2e/logs
Expand All @@ -28,4 +28,8 @@ tmp-manifest-*
.local-mock-server
codegen
devAccounts.json

*report.xml
*report.json
*.out
*coverage*
eslint-report.json
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,17 @@ artifacts_clean_wasmd:

build: build_js build_contracts

test_relay_unit:
# Common build step
build_relay:
go build -v ./pkg/cosmos/...
go test -v ./pkg/cosmos/...

# Unit test without race detection
test_relay_unit: build_relay
go test -v -covermode=atomic ./pkg/cosmos/... -coverpkg=./... -coverprofile=unit_coverage.txt

# Unit test with race detection
test_relay_unit_race: build_relay
go test -v -covermode=atomic ./pkg/cosmos/... -race -count=10 -coverpkg=./... -coverprofile=race_coverage.txt


# copied over from starknet, replace as needed
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"scripts": {
"preinstall": "node scripts/require-yarn.js",
"gauntlet": "yarn build && node ./packages-ts/gauntlet-cosmos-contracts/dist/index.js",
"eslint": "eslint -f json -o eslint-report.json ./packages-ts || true",
"lint": "tsc -b ./tsconfig.json",
"test": "yarn build && yarn workspaces run test",
"test:coverage": "yarn build && yarn test --collectCoverage",
Expand Down Expand Up @@ -52,6 +53,9 @@
"prettier": "2.1.1",
"ts-jest": "^26.4.3",
"ts-node": "^8.3.0",
"typescript": "4.3.5"
"typescript": "4.3.5",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"eslint": "^8.49.0"
}
}
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-cosmos
sonar.sources=.

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

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