Skip to content

Commit

Permalink
Integrate repo with Sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
chudilka1 committed Oct 12, 2023
1 parent 02ab182 commit 32a5472
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 45 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/prettier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ jobs:
- name: Install dependencies
run: npm install # npm install instead of npm ci is used to prevent unsupported platform errors due to the fsevents sub-dependency --no-optional

- name: Run Prettier check
run: npm run prettier:check

- name: Run lint check
run: npm run lint:check
run: npm run lint:ci

- name: Upload ESLint report
if: always()
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: eslint-report
path: ./eslint-report.json

- name: Run Prettier
run: npm run prettier:check
78 changes: 78 additions & 0 deletions .github/workflows/sonar-scan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: SonarQube Scan

on:
push:
branches:
- main
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
uses: smartcontractkit/chainlink-github-actions/utils/wait-for-workflows@main
with:
max-timeout: '900'
polling-interval: '30'
exclude-workflow-names: 'Package Artifact Tests'
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 ESLint report
uses: dawidd6/[email protected]
with:
workflow: lint.yaml
workflow_conclusion: ''
name: eslint-report
if_no_artifact_found: warn

- name: Download unit-tests report
uses: dawidd6/[email protected]
with:
workflow: unit-test.yaml
workflow_conclusion: ''
name: unit-tests-coverage
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 'lcov.info' -printf "%p,")" >> $GITHUB_OUTPUT
echo "sonarqube_eslint_report_paths=$(find -type f -name 'eslint-report.json' -printf "%p")" >> $GITHUB_OUTPUT
- name: Update ESLint report symlinks
continue-on-error: true
run: sed -i 's+/home/runner/work/functions-toolkit/functions-toolkit/+/github/workspace/+g' ${{ steps.sonarqube_report_paths.outputs.sonarqube_eslint_report_paths }}

- name: SonarQube Scan
if: always()
uses: sonarsource/[email protected]
with:
args: >
-Dsonar.javascript.lcov.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_coverage_report_paths }}
-Dsonar.eslint.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_eslint_report_paths }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
30 changes: 0 additions & 30 deletions .github/workflows/test-converage.yaml

This file was deleted.

22 changes: 16 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Jest Tests
name: Unit Tests

on:
pull_request:
push:
branches:
- main

jobs:
tests:
Expand All @@ -11,20 +14,27 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: npm install # npm install instead of npm ci is used to prevent unsupported platform errors due to the fsevents sub-dependency

- name: Setup Deno
uses: denolib/setup-deno@v2
with:
deno-version: '1.36.2'

- name: Run Jest tests
run: npm test
# 'integration' are the Jest tests that cover code in unit-testing way, so both are included
- name: Run unit tests
run: npm run test:ci

- name: Upload unit-test coverage report
if: always()
uses: actions/[email protected]
with:
name: unit-tests-coverage
path: ./coverage/lcov.info
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ node_modules
/test/hardhat/node_modules
/test/hardhat/build
/test/hardhat/.openzeppelin
.DS_Store
dist

# Reports
/coverage
coverage.json
.DS_Store
dist
*report.json
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
node_modules
*report.json
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
testMatch: ['**/test/**/*.test.ts'],
testTimeout: 2 * 60 * 1000,

coverageReporters: ['html'],
coverageReporters: ['html', 'lcov'],
collectCoverageFrom: ['src/**/*.ts', '!src/test/*.ts', '!src/simulateScript/deno-sandbox/*.ts'],
coverageThreshold: {
global: {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"build": "rimraf dist && tsc -P tsconfig.build.json && cpy src/simulateScript/deno-sandbox/**/* dist/simulateScript/deno-sandbox",
"build:browser": "webpack && browserify dist/simulateScript.bundle.js -o dist/simulateScript.browser.js -p esmify --standalone simulateScript && rm dist/simulateScript.bundle.js",
"test": "jest",
"test:unit": "jest --testPathPattern=unit",
"test:integration": "jest --testPathPattern=integration",
"test:ci": "jest --coverage",
"test:package": "jest --config jest.config.package.js",
"lint:check": "eslint 'src/**/*.{ts,tsx}'",
"lint:ci": "eslint 'src/**/*.{ts,tsx}' -f json -o eslint-report.json",
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix",
"prettier:check": "prettier --check . && tsc --noEmit",
"prettier:fix": "npx prettier -w ."
Expand Down
11 changes: 11 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sonar.projectKey=smartcontractkit_functions-toolkit
sonar.sources=.

# Full exclusions from the static analysis
sonar.exclusions=**/node_modules/**/*, **/mocks/**/*, **/testdata/**/*, **/demo/**/*, **/contracts/**/*, **/generated/**/*, **/fixtures/**/*, **/docs/**/*, **/tools/**/*, **/*.fixtures.ts, **/apiFixture.ts, **/*report.xml, **/*.config.ts, **/*.txt, **/*.abi, **/*.bin
# Coverage exclusions
sonar.coverage.exclusions=**/*.test.ts, **/test/**/*, **/contracts/**/*, **/testutils/**/*, **/test/integration/**/*, **/*.config.js, **/*.config.ts,

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

0 comments on commit 32a5472

Please sign in to comment.