Skip to content

Commit b999ab1

Browse files
committed
Integrate repo with Sonar
1 parent 02ab182 commit b999ab1

12 files changed

Lines changed: 140 additions & 52 deletions

.eslintignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**/node_modules/**
2+
**/generated/**
3+
**/dist/**
4+
**/artifacts/**
5+
**/public/**
6+
**/build/**
7+
**/fixtures/**
8+
**/lib/**
9+
**/schema/**
10+
11+
*.config.js
12+
*.config.ts

.github/workflows/prettier.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ jobs:
1919
- name: Install dependencies
2020
run: npm install # npm install instead of npm ci is used to prevent unsupported platform errors due to the fsevents sub-dependency --no-optional
2121

22-
- name: Run Prettier check
23-
run: npm run prettier:check
24-
2522
- name: Run lint check
26-
run: npm run lint:check
23+
run: npm run lint:ci
24+
25+
- name: Upload ESLint report
26+
if: always()
27+
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
28+
with:
29+
name: eslint-report
30+
path: ./eslint-report.json
31+
32+
- name: Run Prettier
33+
run: npm run prettier:check

.github/workflows/sonar-scan.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: SonarQube Scan
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
wait_for_workflows:
11+
name: Wait for workflows
12+
runs-on: ubuntu-latest
13+
if: always()
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@v3
17+
with:
18+
ref: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha }}
19+
20+
- name: Wait for workflows
21+
uses: smartcontractkit/chainlink-github-actions/utils/wait-for-workflows@main
22+
with:
23+
max-timeout: '900'
24+
polling-interval: '30'
25+
exclude-workflow-names: 'Package Artifact Tests'
26+
exclude-workflow-ids: ''
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
env:
29+
DEBUG: 'true'
30+
31+
sonarqube:
32+
name: SonarQube Scan
33+
needs: [wait_for_workflows]
34+
runs-on: ubuntu-latest
35+
if: always()
36+
steps:
37+
- name: Checkout the repo
38+
uses: actions/checkout@v3
39+
with:
40+
fetch-depth: 0 # fetches all history for all tags and branches to provide more metadata for sonar reports
41+
42+
- name: Download ESLint report
43+
uses: dawidd6/action-download-artifact@v2.28.0
44+
with:
45+
workflow: lint.yaml
46+
workflow_conclusion: ''
47+
name: eslint-report
48+
if_no_artifact_found: warn
49+
50+
- name: Download unit-tests report
51+
uses: dawidd6/action-download-artifact@v2.28.0
52+
with:
53+
workflow: unit-test.yaml
54+
workflow_conclusion: ''
55+
name: unit-tests-coverage
56+
if_no_artifact_found: warn
57+
58+
- name: Set SonarQube Report Paths
59+
if: always()
60+
id: sonarqube_report_paths
61+
shell: bash
62+
run: |
63+
echo "sonarqube_coverage_report_paths=$(find -type f -name 'lcov.info' -printf "%p,")" >> $GITHUB_OUTPUT
64+
echo "sonarqube_eslint_report_paths=$(find -type f -name 'eslint-report.json' -printf "%p")" >> $GITHUB_OUTPUT
65+
- name: Update ESLint report symlinks
66+
continue-on-error: true
67+
run: sed -i 's+/home/runner/work/functions-toolkit/functions-toolkit/+/github/workspace/+g' ${{ steps.sonarqube_report_paths.outputs.sonarqube_eslint_report_paths }}
68+
69+
- name: SonarQube Scan
70+
if: always()
71+
uses: sonarsource/sonarqube-scan-action@v2.0.1
72+
with:
73+
args: >
74+
-Dsonar.javascript.lcov.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_coverage_report_paths }}
75+
-Dsonar.eslint.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_eslint_report_paths }}
76+
env:
77+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
78+
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

.github/workflows/test-converage.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/test.yaml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
name: Jest Tests
1+
name: Unit Tests
22

33
on:
44
pull_request:
5+
push:
6+
branches:
7+
- main
58

69
jobs:
710
tests:
@@ -11,20 +14,27 @@ jobs:
1114

1215
steps:
1316
- name: Checkout repository
14-
uses: actions/checkout@v2
17+
uses: actions/checkout@v3
1518

1619
- name: Set up Node.js
17-
uses: actions/setup-node@v2
20+
uses: actions/setup-node@v3
1821
with:
1922
node-version: 18
2023

2124
- name: Install dependencies
2225
run: npm install # npm install instead of npm ci is used to prevent unsupported platform errors due to the fsevents sub-dependency
23-
2426
- name: Setup Deno
2527
uses: denolib/setup-deno@v2
2628
with:
2729
deno-version: '1.36.2'
2830

29-
- name: Run Jest tests
30-
run: npm test
31+
# 'integration' are the Jest tests that cover code in unit-testing way, so both are included
32+
- name: Run unit tests
33+
run: npm run test:ci
34+
35+
- name: Upload unit-test coverage report
36+
if: always()
37+
uses: actions/upload-artifact@v3.1.3
38+
with:
39+
name: unit-tests-coverage
40+
path: ./coverage/lcov.info

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
node_modules
2-
/test/hardhat/node_modules
3-
/test/hardhat/build
4-
/test/hardhat/.openzeppelin
2+
.DS_Store
3+
dist
4+
5+
# Reports
56
/coverage
67
coverage.json
7-
.DS_Store
8-
dist
8+
*report.json

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
dist
22
node_modules
3+
*report.json

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
testMatch: ['**/test/**/*.test.ts'],
66
testTimeout: 2 * 60 * 1000,
77

8-
coverageReporters: ['html'],
8+
coverageReporters: ['html', 'lcov'],
99
collectCoverageFrom: ['src/**/*.ts', '!src/test/*.ts', '!src/simulateScript/deno-sandbox/*.ts'],
1010
coverageThreshold: {
1111
global: {

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"build": "rimraf dist && tsc -P tsconfig.build.json && cpy src/simulateScript/deno-sandbox/**/* dist/simulateScript/deno-sandbox",
99
"build:browser": "webpack && browserify dist/simulateScript.bundle.js -o dist/simulateScript.browser.js -p esmify --standalone simulateScript && rm dist/simulateScript.bundle.js",
1010
"test": "jest",
11-
"test:unit": "jest --testPathPattern=unit",
12-
"test:integration": "jest --testPathPattern=integration",
11+
"test:ci": "jest --coverage",
1312
"test:package": "jest --config jest.config.package.js",
14-
"lint:check": "eslint 'src/**/*.{ts,tsx}'",
15-
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix",
13+
"lint:check": "eslint --ext js,jsx,ts,tsx .",
14+
"lint:ci": "eslint --ext js,jsx,ts,tsx . -f json -o eslint-report.json",
15+
"lint:fix": "eslint --ext js,jsx,ts,tsx . --fix",
1616
"prettier:check": "prettier --check . && tsc --noEmit",
1717
"prettier:fix": "npx prettier -w ."
1818
},

sonar-project.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sonar.projectKey=smartcontractkit_functions-toolkit
2+
sonar.sources=.
3+
4+
# Full exclusions from the static analysis
5+
sonar.exclusions=**/node_modules/**/*, **/mocks/**/*, **/testdata/**/*, **/demo/**/*, **/contracts/**/*, **/generated/**/*, **/fixtures/**/*, **/docs/**/*, **/tools/**/*, **/*.fixtures.ts, **/apiFixture.ts, **/*report.xml, **/*.config.ts, **/*.txt, **/*.abi, **/*.bin, **/decodeResult.ts, **/types.ts
6+
# Coverage exclusions
7+
sonar.coverage.exclusions=**/*.test.ts, **/test/**/*, **/contracts/**/*, **/testutils/**/*, **/test/integration/**/*, **/*.config.js, **/*.config.ts,
8+
9+
# Tests' root folder, inclusions (tests to check and count) and exclusions
10+
sonar.tests=.
11+
sonar.test.inclusions=**/*.test.ts

0 commit comments

Comments
 (0)