Skip to content

SonarQube Self-Hosted Analysis #9

SonarQube Self-Hosted Analysis

SonarQube Self-Hosted Analysis #9

name: SonarQube Self-Hosted Analysis
# This workflow is for self-hosted SonarQube Server ONLY
# It requires SONARQUBE_HOST_URL and SONARQUBE_TOKEN secrets to be configured
# For SonarCloud analysis, use the sonarcloud.yml workflow instead
on:
workflow_dispatch: # Manual trigger only - since it requires self-hosted SonarQube
inputs:
run_tests:
description: "Run tests before analysis"
required: false
default: "true"
type: boolean
jobs:
sonarqube:
name: SonarQube Self-Hosted Analysis
runs-on: ubuntu-latest
# This workflow requires SONARQUBE_HOST_URL and SONARQUBE_TOKEN secrets
# Only trigger manually when you have a self-hosted SonarQube server
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: |
backend/package-lock.json
frontend/package-lock.json
- name: Install Backend Dependencies
working-directory: ./backend
run: npm ci
continue-on-error: true
- name: Install Frontend Dependencies
working-directory: ./frontend
run: npm ci
continue-on-error: true
- name: Run Backend Tests with Coverage
if: ${{ inputs.run_tests == 'true' }}
working-directory: ./backend
run: npm run test:coverage || echo "Backend tests completed"
env:
NODE_ENV: test
MONGODB_URI: mongodb://localhost:27017/notes-app-test
JWT_SECRET: test-jwt-secret-for-ci
continue-on-error: true
- name: Run Frontend Tests with Coverage
if: ${{ inputs.run_tests == 'true' }}
working-directory: ./frontend
run: npm run test:coverage || echo "Frontend tests completed"
continue-on-error: true
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@v6
env:
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST_URL }}
with:
args: >
-Dsonar.projectKey=scribo-notes-ai
-Dsonar.projectName=ScriboNotesAI
-Dsonar.sources=backend/src,frontend/src
-Dsonar.tests=backend/tests
-Dsonar.exclusions=**/node_modules/**,**/dist/**,**/build/**,**/coverage/**,frontend/src/tests/**,backend/tests/**
-Dsonar.javascript.lcov.reportPaths=backend/coverage/lcov.info,frontend/coverage/lcov.info