I have set up a React.js
sample project to try out sonarqube
with Github actions
. I have tried multiple ways to get the coverage % but everytime it is showing No data about Coverage
.
The Icov file path is set explicitly where it is the default path only. If I run the command npm run coverage
the a coverage directory gets created in the local and Icov.info
file also gets generated.
Repo :- https://github.com/shanbiswas/github-actions-cicd-react-app
PR :- https://github.com/shanbiswas/github-actions-cicd-react-app/pull/13
build.yml
name: Build
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install dependencies
run: npm install
- name: Test and coverage
run: npm run coverage
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
with:
args: >
-Dsonar.organization=github-actions-react-cicd
-Dsonar.projectKey=shanbiswas_github-actions-cicd-react-app
-Dsonar.sources=src
-Dsonar.tests=src
-Dsonar.test.inclusions=**/*.test.js
-Dsonar.exclusions=**/*.test.js
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
sonar-project.properties
sonar.projectKey=shanbiswas_github-actions-cicd-react-app
sonar.organization=github-actions-react-cicd
# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=github-actions-cicd-react-app
#sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "" by "/" on Windows.
sonar.sources=src
sonar.tests=src
sonar.exclusions=**/*.test.js
sonar.test.inclusions=**/*.test.js
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
package.json
{
"name": "github-actions-cicd-react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"test:ci": "jest",
"eject": "react-scripts eject",
"coverage": "jest --coverage"
},
"jest": {
"testEnvironment": "jsdom"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}