diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 0000000..a69a3e3 --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,47 @@ +name: SonarQube PR Check + +on: + pull_request: + branches: + - main + +jobs: + sonarqube: + name: Run SonarQube Analysis + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '22' + + - name: Install dependencies + run: npm ci + + - name: Run tests and generate coverage + run: | + npm test -- --coverage + ls coverage + + - name: Run SonarQube Scanner + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + run: | + npm install -g sonarqube-scanner + sonar-scanner \ + -Dsonar.projectKey=sunbird-nodebb \ + -Dsonar.sources=. \ + -Dsonar.host.url=$SONAR_HOST_URL \ + -Dsonar.login=$SONAR_TOKEN \ + -Dsonar.exclusions="**/node_modules/**, **/*.module.ts, **/*.model.ts, **/*.conf.js, **/*.guard.ts, **/*.constants.ts" \ + -Dsonar.tests=src \ + -Dsonar.test.inclusions=**/*.spec.ts \ + -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info + + - name: Check Quality Gate (Optional workaround) + run: echo "Can't check quality gate in Community Edition"