From 7ff0dda06d67cc61ab17bd1ad2a727fc3485178b Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Mohammed Hofney Date: Tue, 8 Feb 2022 20:08:09 +0200 Subject: [PATCH] Feature/GitHub workflow (#2) * feature: continue setup --- .github/workflows/build.yml | 28 +++------------------------- README.md | 3 ++- jest.config.js | 2 +- package-lock.json | 29 +++++++++++++++++++++++++++++ package.json | 5 +++++ sonarqube.js | 24 ++++++++++++++++++++++++ 6 files changed, 64 insertions(+), 27 deletions(-) create mode 100644 sonarqube.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 97a21b5..d07835d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,33 +16,11 @@ jobs: node-version: '16' - name: Install Dependencies - run: | - npm install - npm test - ls - cat test-report.xml + run: npm install - name: Sonar Scan - uses: sonarsource/sonarqube-scan-action@master - with: - args: > - -Dsonar.projectKey=node-ts-conventions - -Dsonar.projectVersion=1.0.0 - -Dsonar.sourceEncoding=UTF-8 - -Dsonar.links.scm=https://github.com/blink22/node-ts-conventions/ - -Dsonar.sources=src - -Dsonar.tests=tests - -Dsonar.exclusions=**/tests/*.* - -Dsonar.test.inclusions=**/*.test.* - -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info - -Dsonar.testExecutionReportPaths=test-report.xml - -Dsonar.coverage.exclusions=**/*.spec.js,**/*.spec.ts,**/*.mock.js,**/*.mock.ts,node_modules/*,coverage/lcov-report/* - 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. + run: SONAR_URL=${{ secrets.SONAR_HOST_URL }} SONAR_LOGIN=${{ secrets.SONAR_TOKEN }} npm run sonarqube + - name: Sonar Quality Gate uses: sonarsource/sonarqube-quality-gate-action@master timeout-minutes: 5 diff --git a/README.md b/README.md index 096688b..42773fb 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # node-ts-conventions -[![Quality Gate Status](http://198.211.115.56:9000/api/project_badges/measure?project=node-ts-conventions&metric=alert_status&token=6e973d15010512eca45c3740f9114584c9e39e96)](http://198.211.115.56:9000/dashboard?id=node-ts-conventions) \ No newline at end of file +[![Quality Gate Status](http://198.211.115.56:9000/api/project_badges/measure?project=node-ts-conventions&metric=alert_status&token=6e973d15010512eca45c3740f9114584c9e39e96)](http://198.211.115.56:9000/dashboard?id=node-ts-conventions) +[![Coverage](http://198.211.115.56:9000/api/project_badges/measure?project=node-ts-conventions&metric=coverage&token=6e973d15010512eca45c3740f9114584c9e39e96)](http://198.211.115.56:9000/dashboard?id=node-ts-conventions) \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index 24c0033..2604e48 100644 --- a/jest.config.js +++ b/jest.config.js @@ -10,7 +10,7 @@ module.exports = { transform: { "^.+\\.ts$": "/node_modules/ts-jest/preprocessor.js", }, - testMatch: ["/tests/**/*.test.ts"], + testMatch: ["**/tests/**/*.test.ts"], collectCoverage: true, coverageThreshold: { global: { diff --git a/package-lock.json b/package-lock.json index 56b8f4b..b34f923 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,8 +8,12 @@ "name": "node-ts-conventions", "version": "1.0.0", "license": "ISC", + "dependencies": { + "dotenv": "^8.2.0" + }, "devDependencies": { "@types/jest": "^27.4.0", + "@types/node": "^17.0.16", "jest": "^21.2.1", "jest-sonar-reporter": "^2.0.0", "sonarqube-scanner": "^2.8.1", @@ -156,6 +160,12 @@ "node": ">=8" } }, + "node_modules/@types/node": { + "version": "17.0.16", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.16.tgz", + "integrity": "sha512-ydLaGVfQOQ6hI1xK2A5nVh8bl0OGoIfYMxPWHqqYe9bTkWCfqiVvZoh2I/QF2sNSkZzZyROBoTefIEI+PB6iIA==", + "dev": true + }, "node_modules/abab": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/abab/-/abab-1.0.4.tgz", @@ -1936,6 +1946,14 @@ "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" } }, + "node_modules/dotenv": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", + "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", + "engines": { + "node": ">=10" + } + }, "node_modules/download": { "version": "6.2.5", "resolved": "https://registry.npmjs.org/download/-/download-6.2.5.tgz", @@ -7436,6 +7454,12 @@ } } }, + "@types/node": { + "version": "17.0.16", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.16.tgz", + "integrity": "sha512-ydLaGVfQOQ6hI1xK2A5nVh8bl0OGoIfYMxPWHqqYe9bTkWCfqiVvZoh2I/QF2sNSkZzZyROBoTefIEI+PB6iIA==", + "dev": true + }, "abab": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/abab/-/abab-1.0.4.tgz", @@ -8902,6 +8926,11 @@ "integrity": "sha512-k1gCAXAsNgLwEL+Y8Wvl+M6oEFj5bgazfZULpS5CneoPPXRaCCW7dm+q21Ky2VEE5X+VeRDBVg1Pcvvsr4TtNQ==", "dev": true }, + "dotenv": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", + "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==" + }, "download": { "version": "6.2.5", "resolved": "https://registry.npmjs.org/download/-/download-6.2.5.tgz", diff --git a/package.json b/package.json index 6fd0be7..39cad23 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,17 @@ "scripts": { "build": "tsc -p .", "test": "jest --coverage", + "sonarqube": "npm test && node sonarqube.js", "start": "ts-node src/index.ts" }, "author": "", "license": "ISC", + "dependencies": { + "dotenv": "^8.2.0" + }, "devDependencies": { "@types/jest": "^27.4.0", + "@types/node": "^17.0.16", "jest": "^21.2.1", "jest-sonar-reporter": "^2.0.0", "sonarqube-scanner": "^2.8.1", diff --git a/sonarqube.js b/sonarqube.js new file mode 100644 index 0000000..a8a0f6e --- /dev/null +++ b/sonarqube.js @@ -0,0 +1,24 @@ +const scanner = require("sonarqube-scanner"); +const dotenv = require("dotenv"); + +dotenv.config(); + +scanner( + { + // this example uses local instance of SQ + serverUrl: process.env.SONAR_URL, + options: { + "sonar.projectKey": "node-ts-conventions", + "sonar.projectVersion": "1.0.0", + "sonar.login": process.env.SONAR_LOGIN, + "sonar.sources": "src", + "sonar.tests": "tests", + "sonar.test.inclusions": "**/*.test.*", + "sonar.typescript.lcov.reportPaths": "coverage/lcov.info", + "sonar.testExecutionReportPaths": "test-report.xml", + "sonar.coverage.exclusions": + "**/*.test.*,**/*.spec.js,**/*.spec.ts,**/*.mock.js,**/*.mock.ts,node_modules/*,coverage/lcov-report/*", + }, + }, + () => process.exit() +);