Skip to content

Commit

Permalink
SonarCloud Analysis (#18)
Browse files Browse the repository at this point in the history
* feat: setup coverageDirectory and coveragePathIgnorePatterns

* ci: added SonarCloud Analysis job in GitHub actions

* ci: sonar-project.properties configuration

* Simplified workflow, single task, maximum gain

---------

Co-authored-by: Vincenzo Pellegrini <[email protected]>
  • Loading branch information
AlbertoBaroso and friedbyalice committed Apr 9, 2024
1 parent c44c5bd commit e6b590f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
35 changes: 24 additions & 11 deletions .github/workflows/fullstack.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
name: Fullstack
name: Test

on:
- push
- pull_request
push:
branches:
- '*'
pull_request:
branches:
- '*'

jobs:
test:
tests:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v3
name: Install pnpm
id: pnpm-install
with:
Expand All @@ -30,7 +34,7 @@ jobs:
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
Expand All @@ -46,10 +50,13 @@ jobs:

- name: Test building
run: pnpm run build && pnpm run clean

- name: Run shared unit tests
run: pnpm --filter shared test
run: pnpm --filter shared test:cov

- name: Run api unit tests
run: pnpm --filter api test
run: pnpm --filter api test:cov

- name: Run api e2e tests
env:
DATABASE_TYPE: sqlite
Expand All @@ -59,4 +66,10 @@ jobs:
AUTH0_AUDIENCE: ${{ secrets.TEST_AUTH0_AUDIENCE }}
AUTH0_CLIENT_ID: ${{ secrets.TEST_AUTH0_CLIENT_ID }}
AUTH0_CLIENT_SECRET: ${{ secrets.TEST_AUTH0_CLIENT_SECRET }}
run: pnpm --filter api test:e2e
run: pnpm --filter api test-e2e:cov

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
17 changes: 14 additions & 3 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest -i --verbose",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:cov": "jest -i --verbose --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --verbose --config ./test/jest-e2e.json",
"test-e2e": "jest --verbose --config ./test/jest-e2e.json",
"test-e2e:cov": "jest --verbose --config ./test/jest-e2e.json --coverage --coverageDirectory=../coverage/api-e2e",
"typeorm": "typeorm-ts-node-commonjs",
"clean": "rimraf dist"
},
Expand Down Expand Up @@ -98,10 +99,20 @@
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coveragePathIgnorePatterns": [
"node_modules/",
"coverage*/",
"test/",
"dist/",
".module.",
"google/",
"main.ts",
".eslintrc.js"
],
"moduleNameMapper": {
"^@mocks/(.*)$": "<rootDir>/src/mocks/$1"
},
"coverageDirectory": "../coverage",
"coverageDirectory": "../coverage/api",
"testEnvironment": "node"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"clean": "pnpm --filter frontend clean && pnpm --filter api clean",
"format": "pnpm --filter shared format & pnpm --filter frontend format & pnpm --filter api format",
"format-check": "pnpm --filter shared format-check && pnpm --filter frontend format-check && pnpm --filter api format-check",
"test": "pnpm --filter api test && pnpm --filter shared test"
"test": "pnpm --filter api test && pnpm --filter shared test && pnpm --filter api test-e2e"
},
"keywords": [],
"author": "",
Expand Down
3 changes: 2 additions & 1 deletion shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
],
"transform": {
"^.+\\.tsx?$": "@swc/jest"
}
},
"coverageDirectory": "../coverage/shared"
}
}
7 changes: 7 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sonar.projectKey=MuNuChapterHKN_HKrecruitment
sonar.organization=munuchapterhkn
sonar.projectName=HKrecruitment

sonar.javascript.lcov.reportPaths=./coverage/shared/lcov.info, ./coverage/api/lcov.info, ./coverage/api-e2e/lcov.info
sonar.sources=api/, frontend/, shared/
sonar.coverage.exclusions=**/node_modules/**/*, **/*.spec.*, **/test/**/*, **/tests/**/*, **/*.json, **/*.yaml, **/*.yml, **/*.md

0 comments on commit e6b590f

Please sign in to comment.