From 91245f18d99c35c7d090408cbc5171550ba82722 Mon Sep 17 00:00:00 2001 From: Ramona Hartinger Date: Wed, 9 Oct 2024 10:15:27 +0200 Subject: [PATCH] ci: adding sonar to action --- .github/workflows/lint.yml | 21 ------------- .github/workflows/nodejs.yml | 61 +++++++++++++++++++++++++++++++++--- .vscode-test.mjs | 2 +- 3 files changed, 57 insertions(+), 27 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 76b465a..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: ESLint - -on: - pull_request: - -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 diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 45d41fc..1917404 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: @@ -16,12 +21,14 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - name: Check Node.js version - run: node -v - - - name: Check npm versions - run: npm -v + - name: Cache node_modules + uses: actions/cache@v3 + with: + path: node_modules + key: node_modules-${{ matrix.os }}-node-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }} + restore-keys: | + node_modules-${{ matrix.os }}-node-${{ matrix.node-version }} - name: Run clean install run: npm ci @@ -29,3 +36,47 @@ jobs: if: runner.os == 'Linux' - run: npm test if: runner.os != 'Linux' + + sonar: + name: Run eslint and sonar scanning + runs-on: ubuntu-latest + needs: build + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 22.x + + - name: Restore cached node_modules + uses: actions/cache@v3 + with: + path: node_modules + key: node_modules-ubuntu-latest-node-22.x-${{ hashFiles('package-lock.json') }} + restore-keys: | + node_modules-ubuntu-latest-node-22.x + - name: Run ESLint + run: npm run lint -- --format json --output-file eslint-results.json || true + + - 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: xvfb-run -a npm test -- --coverage --coverage-output ./coverage --coverage-reporter lcovonly --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_vscode-logging + -Dsonar.organization=aditosoftware + -Dsonar.eslint.reportPaths=eslint-results.json + -Dsonar.testExecutionReportPaths=xunit.xml + -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info diff --git a/.vscode-test.mjs b/.vscode-test.mjs index 5af0e70..a348b7c 100644 --- a/.vscode-test.mjs +++ b/.vscode-test.mjs @@ -4,7 +4,7 @@ export default defineConfig({ files: "out/test/**/*.test.js", version: "insiders", mocha: { - retries: 3, + retries: 5, parallel: false, }, });