From 001a88cc905cb54a44fbfa4a3765bc4d7638dbc5 Mon Sep 17 00:00:00 2001 From: Ramona Hartinger Date: Wed, 9 Oct 2024 06:58:07 +0200 Subject: [PATCH] ci: added sonar to action --- .github/workflows/lint.yml | 44 +++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 76b465a..9e71213 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,8 +1,13 @@ name: ESLint on: + push: + branches: [ "main" ] pull_request: +permissions: + pull-requests: read # allows SonarCloud to decorate PRs with analysis results + jobs: eslint: name: Run eslint scanning @@ -18,4 +23,41 @@ jobs: run: npm ci - name: Run ESLint - run: npm run lint + run: npm run lint --format json --output-file eslint-results.json || true + + - name: Install Coverage Reporters + run: npm install -g nyc + npm install -d mocha-multi-reporters + npm install -d mocha-junit-reporter + npm install -d mocha-sonarqube-reporter + - run: | + echo '{ + "reporterEnabled": "spec, mocha-junit-reporter, mocha-sonarqube-reporter" + }' > config.json + + - name: Run tests with coverage + run: nyc --reporter lcovonly npm run test -- --reporter mocha-multi-reporters --reporter-options configFile=config.json + + + - name: Analyze with SonarCloud + uses: SonarSource/sonarcloud-github-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + # Additional arguments for the SonarScanner CLI + args: + # Unique keys of your project and organization. You can find them in SonarCloud > Information (bottom-left menu) + # mandatory + -Dsonar.projectKey=aditosoftware_driver-dependencies + -Dsonar.organization=aditosoftware + -Dsonar.eslint.reportPaths=eslint-results.json + -Dsonar.testExecutionReportPaths=xunit.xml + -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info + # Comma-separated paths to directories containing main source files. + #-Dsonar.sources= # optional, default is project base directory + # Comma-separated paths to directories containing test source files. + #-Dsonar.tests= # optional. For more info about Code Coverage, please refer to https://docs.sonarcloud.io/enriching/test-coverage/overview/ + # Adds more detail to both client and server-side analysis logs, activating DEBUG mode for the scanner, and adding client-side environment variables and system properties to the server-side log of analysis report processing. + #-Dsonar.verbose= # optional, default is false + # When you need the analysis to take place in a directory other than the one from which it was launched, default is . + projectBaseDir: . \ No newline at end of file