1
1
name : PR Code Coverage and SonarQube Analysis
2
2
3
+ # Trigger workflow on pull requests to any branch
4
+ # This workflow runs comprehensive testing and code quality analysis
3
5
on :
4
6
push :
5
7
branches : ['**']
6
8
7
9
jobs :
10
+ # First job: Build root POM and test jobs-core module
11
+ # This job serves as the foundation for all other parallel jobs
12
+ # It builds the root POM, tests jobs-core, and uploads Maven repository
13
+ # All other jobs depend on this job and download the Maven repository from it
8
14
root-pom-build-and-coverage-job-core :
9
15
runs-on : ubuntu-latest
10
16
outputs :
17
+ # Output the Maven cache key for potential use by other jobs
11
18
maven-cache-key : ${{ steps.cache-maven.outputs.cache-primary-key }}
12
19
env :
20
+ # Environment variables for schema and blob paths
21
+ # These are used by the application during testing
13
22
SCHEMA_BASE_PATH : ${{ vars.SCHEMA_BASE_PATH }}
14
23
BLOB_IMAGE_CONTENT_PATH : ${{ vars.BLOB_IMAGE_CONTENT_PATH }}
15
24
BLOB_VIDEO_CONTENT_PATH : ${{ vars.BLOB_VIDEO_CONTENT_PATH }}
16
25
steps :
26
+ # Step 1: Checkout the source code from the PR
17
27
- uses : actions/checkout@v3
18
28
29
+ # Step 2: Set up Java 11 environment for building and testing
30
+ # Uses Temurin distribution for better performance and reliability
19
31
- name : Set up JDK11
20
32
uses : actions/setup-java@v3
21
33
with :
22
34
java-version : ' 11'
23
35
distribution : ' temurin'
24
- cache : ' maven'
36
+ cache : ' maven' # Additional Maven caching provided by setup-java
25
37
38
+ # Step 3: Cache Maven dependencies to speed up builds
39
+ # This caches the ~/.m2/repository directory between workflow runs
40
+ # The cache key is based on the hash of all pom.xml files
26
41
- name : Cache Maven packages
27
42
id : cache-maven
28
43
uses : actions/cache@v3
@@ -32,51 +47,76 @@ jobs:
32
47
restore-keys : |
33
48
${{ runner.os }}-maven-
34
49
50
+ # Step 4: Build root POM and test jobs-core module
51
+ # This step performs a comprehensive build and test of the jobs-core module
52
+ # including code coverage analysis with JaCoCo
35
53
- name : Build root POM and job-core
36
54
run : |
55
+ # First, build only the root POM (parent project) without building modules
56
+ # -N flag means "non-recursive" - only build the current project
37
57
mvn clean install -N -DskipTests
58
+
59
+ # Then build and test the jobs-core module with code coverage
38
60
cd jobs-core
39
61
mvn clean install \
40
- org.jacoco:jacoco-maven-plugin:0.8.8:prepare-agent \
41
- test \
42
- org.jacoco:jacoco-maven-plugin:0.8.8:report \
43
- surefire-report:report
44
-
62
+ org.jacoco:jacoco-maven-plugin:0.8.8:prepare-agent \ # Prepare JaCoCo agent for coverage
63
+ test \ # Run unit tests
64
+ org.jacoco:jacoco-maven-plugin:0.8.8:report \ # Generate coverage report
65
+ surefire-report:report # Generate test report
66
+
67
+ # Step 5: Generate test summary report
68
+ # This creates a nice test summary in the GitHub UI
69
+ # Shows which tests passed/failed and their details
45
70
- name : Test Summary
46
71
uses : dorny/test-reporter@v2.1.0
47
- if : always()
72
+ if : always() # Run even if tests fail
48
73
with :
49
74
name : Test Results
50
- path : ' jobs-core/target/surefire-reports/*.xml'
75
+ path : ' jobs-core/target/surefire-reports/*.xml' # Path to test results
51
76
reporter : java-junit
52
- fail-on-error : false
53
- only-summary : false
54
- list-tests : ' all'
77
+ fail-on-error : false # Don't fail the workflow if test reporting fails
78
+ only-summary : false # Show detailed test information
79
+ list-tests : ' all' # List all tests in the summary
55
80
81
+ # Step 6: Set up Java 17 for SonarQube analysis
82
+ # SonarQube analysis requires Java 17 for better analysis capabilities
56
83
- name : Set up JDK17
57
84
uses : actions/setup-java@v3
58
85
with :
59
86
java-version : ' 17'
60
87
distribution : ' temurin'
61
88
89
+ # Step 7: Run SonarQube code quality analysis
90
+ # This analyzes code quality, security, and maintainability
91
+ # Results are sent to SonarCloud for review
62
92
- name : Run SonarQube Analysis for jobs-core
63
93
env :
64
- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
94
+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }} # Authentication token for SonarCloud
65
95
working-directory : jobs-core
66
96
run : |
67
97
mvn sonar:sonar \
68
- -Dsonar.projectKey=sunbird-lern \
69
- -Dsonar.organization=sunbird-lern \
70
- -Dsonar.host.url=https://sonarcloud.io \
71
- -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
72
-
98
+ -Dsonar.projectKey=sunbird-lern \ # SonarCloud project key
99
+ -Dsonar.organization=sunbird-lern \ # SonarCloud organization
100
+ -Dsonar.host.url=https://sonarcloud.io \ # SonarCloud URL
101
+ -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml # Coverage report path
102
+
103
+ # Step 8: Upload Maven repository as artifact
104
+ # This makes the built dependencies available to parallel jobs
105
+ # All other jobs will download this to avoid rebuilding dependencies
73
106
- name : Upload Maven local repository
74
107
uses : actions/upload-artifact@v4.6.2
75
108
with :
76
109
name : maven-repo
77
110
path : ~/.m2/repository
78
- retention-days : 1
79
-
111
+ retention-days : 1 # Keep for 1 day to allow for debugging
112
+
113
+ # Parallel jobs: The following jobs run in parallel after the first job completes
114
+ # Each job follows the same pattern:
115
+ # 1. Download Maven repository from the first job
116
+ # 2. Set up Java environment
117
+ # 3. Build and test the specific module with coverage
118
+ # 4. Generate test summary
119
+ # 5. Run SonarQube analysis
80
120
coverage-notification :
81
121
needs : root-pom-build-and-coverage-job-core
82
122
runs-on : ubuntu-latest
0 commit comments