ci: added sonar to action #16
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Project | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
permissions: | |
pull-requests: read # allows SonarCloud to decorate PRs with analysis results | |
jobs: | |
build: | |
strategy: | |
matrix: | |
node-version: [18.x, 20.x, 22.x] | |
os: [macos-latest, ubuntu-latest, windows-latest] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Node.js | |
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: Run clean install | |
run: npm ci | |
- 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 |