Skip to content

Commit 3119865

Browse files
Merge pull request #1264 from Sunbird-Lern/gh-actions
SBCOSS-465: Userorg-service - add the GitHub actions to run test cases and code quality checks when a PR raised
2 parents c653232 + 41dcf9b commit 3119865

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

.github/COVERAGE.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# PR Code Coverage
2+
3+
This document outlines the steps for the Pull Request Code Coverage process.
4+
5+
## Triggering the Workflow
6+
This GitHub Actions workflow is triggered automatically whenever a pull request (PR) is raised against any branch in the repository. It ensures that every proposed change is checked for code quality and coverage before being merged into the main codebase.
7+
8+
## Steps
9+
10+
1. **Checkout the Repository**
11+
- The first step is to checkout the repository to ensure you have the latest code.
12+
13+
2. **Set Up JDK 11**
14+
- JDK 11 is used for building the project. Ensure to use the `temurin` distribution and cache Maven dependencies.
15+
16+
3. **Build the Project and Generate Coverage Report**
17+
- Execute the following commands to build and generate coverage report:
18+
```bash
19+
mvn clean verify jacoco:report
20+
```
21+
22+
4. **Set Up JDK 17**
23+
- After generating the coverage report, set up JDK 17 for SonarQube analysis.
24+
25+
5. **Run SonarQube Analysis**
26+
- Execute the SonarQube analysis to check code quality and coverage:
27+
```bash
28+
mvn sonar:sonar \
29+
-Dsonar.projectKey=sunbird-lern \
30+
-Dsonar.organization=sunbird-lern \
31+
-Dsonar.host.url=https://sonarcloud.io \
32+
-Dsonar.coverage.jacoco.xmlReportPaths=service/target/site/jacoco/jacoco.xml
33+
```
34+
35+
## Notes
36+
- Ensure that the `SONAR_TOKEN` secret is set in your GitHub repository for the SonarQube analysis to work.
37+
- The coverage report can be found at `controller/target/site/jacoco/jacoco.xml`.
38+
- The workflow uses Ubuntu latest runner.
39+
- Maven dependencies are cached to improve build performance.

.github/workflows/pr-actions.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: PR Code Coverage and SonarQube Analysis
2+
3+
on:
4+
pull_request:
5+
# Trigger this workflow on pull requests to any branch
6+
branches: ['**']
7+
8+
jobs:
9+
pr-coverage:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
# Checkout the code from the pull request
14+
- uses: actions/checkout@v3
15+
16+
# Set up JDK 11 for running tests and generating code coverage
17+
- name: Set up JDK11
18+
uses: actions/setup-java@v3
19+
with:
20+
java-version: '11'
21+
distribution: 'temurin'
22+
cache: 'maven'
23+
24+
# Cache Maven dependencies to speed up builds
25+
- name: Cache Maven packages
26+
uses: actions/cache@v3
27+
with:
28+
path: ~/.m2/repository
29+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
30+
restore-keys: |
31+
${{ runner.os }}-maven-
32+
33+
# Build the project and generate the JaCoCo coverage report
34+
- name: Build and Generate Coverage Report
35+
run: |
36+
mvn clean verify jacoco:report
37+
38+
# Set up JDK 17 for running SonarQube analysis (if required by plugins)
39+
- name: Set up JDK 17
40+
uses: actions/setup-java@v3
41+
with:
42+
java-version: '17'
43+
distribution: 'temurin'
44+
45+
# Run SonarQube analysis using the generated JaCoCo coverage report
46+
- name: Run SonarQube Analysis
47+
env:
48+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
49+
run: |
50+
mvn sonar:sonar \
51+
-Dsonar.projectKey=sunbird-lern \
52+
-Dsonar.organization=sunbird-lern \
53+
-Dsonar.host.url=https://sonarcloud.io \
54+
-Dsonar.coverage.jacoco.xmlReportPaths=controller/target/site/jacoco/jacoco.xml

0 commit comments

Comments
 (0)