From 5fa615fb7f8ede4b59c8a0de8649ecdb9f4d5fb1 Mon Sep 17 00:00:00 2001 From: Vahn Gomes Date: Wed, 3 Jan 2024 15:09:44 -0500 Subject: [PATCH] Update build and test workflows, add SonarQube integration --- .github/workflows/build.yml | 27 --------------------------- .github/workflows/test.yml | 21 ++++++++++++++++++++- jest.config.js | 3 +++ package-lock.json | 19 +++++++++++++++++++ package.json | 1 + sonar-project.properties | 5 ++++- 6 files changed, 47 insertions(+), 29 deletions(-) delete mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 1ecaebc..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Build - -on: - push: - branches: - - main - - -jobs: - build: - name: Build - runs-on: ubuntu-latest - permissions: read-all - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - uses: sonarsource/sonarqube-scan-action@master - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - # If you wish to fail your job when the Quality Gate is red, uncomment the - # following lines. This would typically be used to fail a deployment. - # - uses: sonarsource/sonarqube-quality-gate-action@master - # timeout-minutes: 5 - # env: - # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aedd790..fc8a37b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,4 +26,23 @@ jobs: run: | export CI=TRUE npm run lint:ci - npm test -- --coverage --json --outputFile=testResults.json + npm test --coverage + sonar: + name: Sonar + runs-on: ubuntu-latest + permissions: read-all + if: github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - uses: sonarsource/sonarqube-scan-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + # If you wish to fail your job when the Quality Gate is red, uncomment the + # following lines. This would typically be used to fail a deployment. + # - uses: sonarsource/sonarqube-quality-gate-action@master + # timeout-minutes: 5 + # env: + # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/jest.config.js b/jest.config.js index a93551f..eafb7cc 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,7 @@ module.exports = { preset: "ts-jest", testEnvironment: "node", + // SonarQube + collectCoverage: true, + coverageDirectory: "coverage", }; diff --git a/package-lock.json b/package-lock.json index 7d38bb5..0f3aa5f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "eslint": "^8.54.0", "fix-tsup-cjs": "^1.2.0", "jest": "^29.7.0", + "jest-sonar-reporter": "^2.0.0", "semantic-release": "^22.0.12", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", @@ -6171,6 +6172,18 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "node_modules/jest-sonar-reporter": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/jest-sonar-reporter/-/jest-sonar-reporter-2.0.0.tgz", + "integrity": "sha512-ZervDCgEX5gdUbdtWsjdipLN3bKJwpxbvhkYNXTAYvAckCihobSLr9OT/IuyNIRT1EZMDDwR6DroWtrq+IL64w==", + "dev": true, + "dependencies": { + "xml": "^1.0.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/jest-util": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", @@ -12152,6 +12165,12 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==", + "dev": true + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/package.json b/package.json index 5b27a4e..4b76ec6 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "conventional-changelog-conventionalcommits": "^7.0.2", "eslint": "^8.54.0", "jest": "^29.7.0", + "jest-sonar-reporter": "^2.0.0", "semantic-release": "^22.0.12", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", diff --git a/sonar-project.properties b/sonar-project.properties index 3df96c0..f8a5618 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1 +1,4 @@ -sonar.projectKey=VMGWARE_js-validator_AYzNAnwTPR--spDn0sJy \ No newline at end of file +sonar.projectKey=VMGWARE_js-validator_AYzNAnwTPR--spDn0sJy +sonar.tests=. +sonar.test.inclusions=**/*.test.js +sonar.javascript.lcov.reportPaths=./coverage/lcov.info \ No newline at end of file