Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/COVERAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# PR Code Coverage

This document outlines the steps for the Pull Request Code Coverage process.

## Triggering the Workflow
This GitHub Actions workflow is triggered automatically on every pull request to any branch in the repository. It ensures comprehensive testing and quality checks for all code changes.

## Prerequisites
- Maven
- JDK 11 (for building and testing)
- JDK 17 (for SonarQube analysis)
- SonarCloud account and token

## Steps

1. **Checkout the Repository**
- The first step is to checkout the repository to ensure you have the latest code.

2. **Set Up JDK 11**
- JDK 11 is used for building the project. The workflow uses the `temurin` distribution and caches Maven dependencies for faster builds.

3. **Build the Project and Generate Reports**
- Execute the following commands to build the project and generate test coverage reports:
```bash
mvn clean install -DskipTests
cd service
mvn clean verify jacoco:report surefire-report:report
```

4. **Generate Test Summary**
- The workflow generates an interactive test summary showing all test results, including passed and failed tests, grouped by test class.

5. **Set Up JDK 17**
- After generating the coverage report, set up JDK 17 for SonarQube analysis.

6. **Run SonarQube Analysis**
- Execute the SonarQube analysis to check the quality of the code and coverage. The analysis includes:
- Code quality metrics
- Code coverage analysis
- Security vulnerabilities
```bash
mvn sonar:sonar \
-Dsonar.projectKey=sunbird-lern \
-Dsonar.organization=sunbird-lern \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.coverage.jacoco.xmlReportPaths=service/target/site/jacoco/jacoco.xml
```
## Generated Reports
- **Test Reports**: `service/target/surefire-reports/`
- **Code Coverage**: `service/target/site/jacoco/`

## Notes
- Ensure the `SONAR_TOKEN` secret is configured in your GitHub repository settings for SonarQube analysis to work
- The test summary is available directly in the GitHub Actions UI
- The workflow automatically runs on every pull request to any branch
69 changes: 69 additions & 0 deletions .github/workflows/pr-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: PR Code Coverage and SonarQube Analysis

on:
pull_request:
# Trigger this workflow on pull requests to any branch
branches: ['**']

jobs:
pr-coverage:
runs-on: ubuntu-latest

steps:
# Checkout the code from the pull request
- uses: actions/checkout@v3

# Set up JDK 11 for running tests and generating code coverage
- name: Set up JDK11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: 'maven'

# Cache Maven dependencies to speed up builds
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

# Build the project and generate the JaCoCo coverage report
- name: Build and Generate Jacoco reports and Surefire reports
run: |
mvn clean install -DskipTests
cd service
mvn clean verify jacoco:report surefire-report:report

# Generate and display a detailed test report in the GitHub Actions UI
# This step uses dorny/test-reporter to parse XML reports and create an interactive test summary
- name: Test Summary
uses: dorny/[email protected]
if: always()
with:
name: Test Results
path: '**/surefire-reports/*.xml'
reporter: java-junit
fail-on-error: false
only-summary: false
list-tests: 'all'

# Set up JDK 17 for running SonarQube analysis (required by plugins)
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# Run SonarQube analysis using the generated JaCoCo coverage report
- name: Run SonarQube Analysis
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
mvn sonar:sonar \
-Dsonar.projectKey=sunbird-lern \
-Dsonar.organization=sunbird-lern \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.coverage.jacoco.xmlReportPaths=service/target/site/jacoco/jacoco.xml