From 43ce84d53b9c95eee608a1848b5516cd88c4f4fa Mon Sep 17 00:00:00 2001 From: Ramona Hartinger Date: Wed, 9 Oct 2024 07:12:02 +0200 Subject: [PATCH] ci: moved sonar action into nodejs action file --- .github/workflows/lint.yml | 62 ------------------------------------ .github/workflows/nodejs.yml | 43 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 62 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index df48589..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,62 +0,0 @@ -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 - runs-on: ubuntu-latest - permissions: - contents: read - security-events: write - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install dependencies - run: npm ci - - - name: Run ESLint - run: npm run lint --format json --output-file eslint-results.json || true - - - name: Install Coverage Reporters - run: npm install -g nyc - - name: Install Mocha reporters - run: npm install -d mocha-multi-reporters mocha-junit-reporter mocha-sonarqube-reporter - - name: create mocha config - 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: . diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index c5c72f7..8c91671 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -1,8 +1,13 @@ name: Build Project on: + push: + branches: ["main"] pull_request: +permissions: + pull-requests: read # allows SonarCloud to decorate PRs with analysis results + jobs: build: strategy: @@ -27,3 +32,41 @@ jobs: - name: Run tests run: npm test + + sonar: + name: Run eslint and sonar scanning + runs-on: ubuntu-latest + needs: build + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install dependencies + run: npm ci + + - name: Run ESLint + run: npm run lint --format json --output-file eslint-results.json || true + + - name: Install Coverage Reporters + run: npm install -g nyc + - name: Install Mocha reporters + run: npm install -d mocha-multi-reporters mocha-junit-reporter mocha-sonarqube-reporter + - name: create mocha config + 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: + args: -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