From e6b590ff88da75cf75faa802cd57b55636f89e71 Mon Sep 17 00:00:00 2001 From: Alberto Baroso <35893959+AlbertoBaroso@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:53:21 +0100 Subject: [PATCH] SonarCloud Analysis (#18) * 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 --- .github/workflows/fullstack.yml | 35 ++++++++++++++++++++++----------- api/package.json | 17 +++++++++++++--- package.json | 2 +- shared/package.json | 3 ++- sonar-project.properties | 7 +++++++ 5 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 sonar-project.properties diff --git a/.github/workflows/fullstack.yml b/.github/workflows/fullstack.yml index 0c49192..48e3293 100644 --- a/.github/workflows/fullstack.yml +++ b/.github/workflows/fullstack.yml @@ -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: @@ -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 }} @@ -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 @@ -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 }} \ No newline at end of file diff --git a/api/package.json b/api/package.json index 4bb5e3c..b4a347b 100644 --- a/api/package.json +++ b/api/package.json @@ -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" }, @@ -98,10 +99,20 @@ "collectCoverageFrom": [ "**/*.(t|j)s" ], + "coveragePathIgnorePatterns": [ + "node_modules/", + "coverage*/", + "test/", + "dist/", + ".module.", + "google/", + "main.ts", + ".eslintrc.js" + ], "moduleNameMapper": { "^@mocks/(.*)$": "/src/mocks/$1" }, - "coverageDirectory": "../coverage", + "coverageDirectory": "../coverage/api", "testEnvironment": "node" } } \ No newline at end of file diff --git a/package.json b/package.json index 21fa9c6..4fbe562 100644 --- a/package.json +++ b/package.json @@ -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": "", diff --git a/shared/package.json b/shared/package.json index 9688ff6..6d82609 100644 --- a/shared/package.json +++ b/shared/package.json @@ -31,6 +31,7 @@ ], "transform": { "^.+\\.tsx?$": "@swc/jest" - } + }, + "coverageDirectory": "../coverage/shared" } } diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..895f2fc --- /dev/null +++ b/sonar-project.properties @@ -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