Skip to content

Commit

Permalink
ci: adding sonar to action
Browse files Browse the repository at this point in the history
  • Loading branch information
rH4rtinger committed Oct 9, 2024
1 parent 9e28ab1 commit 91245f1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 27 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/lint.yml

This file was deleted.

61 changes: 56 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -16,16 +21,62 @@ 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

- run: xvfb-run -a npm test
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
2 changes: 1 addition & 1 deletion .vscode-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default defineConfig({
files: "out/test/**/*.test.js",
version: "insiders",
mocha: {
retries: 3,
retries: 5,
parallel: false,
},
});

0 comments on commit 91245f1

Please sign in to comment.