Skip to content

Commit e4aef37

Browse files
authored
#SBCOSS-519 feat: adding github actions to run testcases and codequality checks for data-pipeline flink jobs
1 parent 0b2a325 commit e4aef37

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed

.github/workflows/pr-actions.yml

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,43 @@
11
name: PR Code Coverage and SonarQube Analysis
22

3+
# Trigger workflow on pull requests to any branch
4+
# This workflow runs comprehensive testing and code quality analysis
35
on:
46
push:
57
branches: ['**']
68

79
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
814
root-pom-build-and-coverage-job-core:
915
runs-on: ubuntu-latest
1016
outputs:
17+
# Output the Maven cache key for potential use by other jobs
1118
maven-cache-key: ${{ steps.cache-maven.outputs.cache-primary-key }}
1219
env:
20+
# Environment variables for schema and blob paths
21+
# These are used by the application during testing
1322
SCHEMA_BASE_PATH: ${{ vars.SCHEMA_BASE_PATH }}
1423
BLOB_IMAGE_CONTENT_PATH: ${{ vars.BLOB_IMAGE_CONTENT_PATH }}
1524
BLOB_VIDEO_CONTENT_PATH: ${{ vars.BLOB_VIDEO_CONTENT_PATH }}
1625
steps:
26+
# Step 1: Checkout the source code from the PR
1727
- uses: actions/checkout@v3
1828

29+
# Step 2: Set up Java 11 environment for building and testing
30+
# Uses Temurin distribution for better performance and reliability
1931
- name: Set up JDK11
2032
uses: actions/setup-java@v3
2133
with:
2234
java-version: '11'
2335
distribution: 'temurin'
24-
cache: 'maven'
36+
cache: 'maven' # Additional Maven caching provided by setup-java
2537

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
2641
- name: Cache Maven packages
2742
id: cache-maven
2843
uses: actions/cache@v3
@@ -32,51 +47,76 @@ jobs:
3247
restore-keys: |
3348
${{ runner.os }}-maven-
3449
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
3553
- name: Build root POM and job-core
3654
run: |
55+
# First, build only the root POM (parent project) without building modules
56+
# -N flag means "non-recursive" - only build the current project
3757
mvn clean install -N -DskipTests
58+
59+
# Then build and test the jobs-core module with code coverage
3860
cd jobs-core
3961
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
4570
- name: Test Summary
4671
uses: dorny/test-reporter@v2.1.0
47-
if: always()
72+
if: always() # Run even if tests fail
4873
with:
4974
name: Test Results
50-
path: 'jobs-core/target/surefire-reports/*.xml'
75+
path: 'jobs-core/target/surefire-reports/*.xml' # Path to test results
5176
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
5580

81+
# Step 6: Set up Java 17 for SonarQube analysis
82+
# SonarQube analysis requires Java 17 for better analysis capabilities
5683
- name: Set up JDK17
5784
uses: actions/setup-java@v3
5885
with:
5986
java-version: '17'
6087
distribution: 'temurin'
6188

89+
# Step 7: Run SonarQube code quality analysis
90+
# This analyzes code quality, security, and maintainability
91+
# Results are sent to SonarCloud for review
6292
- name: Run SonarQube Analysis for jobs-core
6393
env:
64-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
94+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Authentication token for SonarCloud
6595
working-directory: jobs-core
6696
run: |
6797
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
73106
- name: Upload Maven local repository
74107
uses: actions/upload-artifact@v4.6.2
75108
with:
76109
name: maven-repo
77110
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
80120
coverage-notification:
81121
needs: root-pom-build-and-coverage-job-core
82122
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)