Skip to content

Commit 44fd1ca

Browse files
committed
added sonar scan files pt 2
1 parent 5ee604d commit 44fd1ca

4 files changed

Lines changed: 73 additions & 0 deletions

File tree

.github/workflows/sonar.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Sonar Analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
branches:
10+
- main
11+
12+
jobs:
13+
sonarcloud_scan:
14+
name: Build, Test and Analyze
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout Code
19+
uses: actions/checkout@v4
20+
with:
21+
# Fetch depth 0 is crucial for SonarCloud to analyze all code history
22+
# and correctly compute 'New Code' metrics, especially for PRs.
23+
fetch-depth: 0
24+
25+
- name: Set up Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '20'
29+
cache: 'npm'
30+
31+
- name: Install dependencies
32+
run: npm install
33+
34+
- name: Run tests and generate coverage
35+
run: npm test
36+
37+
- name: Run SonarCloud Analysis
38+
# This command runs the sonar-scanner executable from the sonarqube-scanner package.
39+
# The configuration is taken from sonar-project.js
40+
run: npm exec sonar-scanner
41+
env:
42+
# The SONAR_TOKEN is needed for authentication with SonarCloud.
43+
# It should be stored as a secret in your GitHub repository.
44+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
45+
# The SONAR_HOST_URL is required by the scanner.
46+
SONAR_HOST_URL: https://sonarcloud.io

sonar-project.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const sonarqubeScanner = require('sonarqube-scanner');
2+
3+
sonarqubeScanner({
4+
serverUrl: 'https://sonarcloud.io',
5+
options: {
6+
'sonar.organization': 'rohithandique',
7+
'sonar.projectKey': 'rohithandique_generic-server-spring-boot',
8+
'sonar.sources': 'src',
9+
'sonar.tests': 'src',
10+
'sonar.inclusions': '**/*.ts,**/*.tsx',
11+
'sonar.test.inclusions': 'src/**/*.test.tsx,src/**/*.test.ts',
12+
'javascript.lcov.reportPaths': 'coverage/lcov.info',
13+
'sonar.token': process.env.SONAR_TOKEN,
14+
},
15+
}, () => process.exit());

src/App.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { describe, it, expect } from 'vitest';
3+
import App from './App';
4+
5+
describe('App', () => {
6+
it('renders headline', () => {
7+
render(<App />);
8+
const headline = screen.getByText(/Vite \+ React/i);
9+
expect(headline).toBeInTheDocument();
10+
});
11+
});

src/test/setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

0 commit comments

Comments
 (0)