forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github action to run tests and get coverage
- Loading branch information
1 parent
fc53905
commit c2fafb4
Showing
3 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Maven tests | ||
|
||
on: | ||
pull_request: | ||
push: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'zulu' | ||
cache: maven | ||
|
||
- name: Run Maven tests | ||
run: | | ||
mvn clean install -DskipTests | ||
modules=("dubbo-common" | ||
"dubbo-serialization/dubbo-serialization-hessian2" | ||
"dubbo-serialization/dubbo-serialization-fastjson2" | ||
"dubbo-remoting/dubbo-remoting-api" | ||
"dubbo-metrics/dubbo-metrics-api" | ||
"dubbo-config/dubbo-config-api") | ||
for module in "${modules[@]}"; do | ||
echo "Running tests for $module" | ||
mvn -B verify -Pjacoco -f $module/pom.xml | ||
done | ||
- name: Get JaCoCo Coverage | ||
id: COVERAGE | ||
run: | | ||
coverage1=$(python3 config/coverage.py dubbo-common/target/site/jacoco/jacoco.csv) | ||
echo "COVERAGE1=$coverage1" >> $GITHUB_ENV | ||
coverage2=$(python3 config/coverage.py dubbo-serialization/dubbo-serialization-hessian2/target/site/jacoco/jacoco.csv) | ||
echo "COVERAGE2=$coverage2" >> $GITHUB_ENV | ||
coverage3=$(python3 config/coverage.py dubbo-serialization/dubbo-serialization-fastjson2/target/site/jacoco/jacoco.csv) | ||
echo "COVERAGE3=$coverage3" >> $GITHUB_ENV | ||
coverage4=$(python3 config/coverage.py dubbo-remoting/dubbo-remoting-api/target/site/jacoco/jacoco.csv) | ||
echo "COVERAGE4=$coverage4" >> $GITHUB_ENV | ||
coverage5=$(python3 config/coverage.py dubbo-metrics/dubbo-metrics-api/target/site/jacoco/jacoco.csv) | ||
echo "COVERAGE5=$coverage5" >> $GITHUB_ENV | ||
coverage6=$(python3 config/coverage.py dubbo-config/dubbo-config-api/target/site/jacoco/jacoco.csv) | ||
echo "COVERAGE6=$coverage6" >> $GITHUB_ENV | ||
- name: Fail if coverage has not improved. | ||
run: | | ||
threshold1=65.38 | ||
threshold2=56.79 | ||
threshold3=68.38 | ||
threshold4=53.44 | ||
threshold5=34.24 | ||
threshold6=74.58 | ||
if (( $(echo "$COVERAGE1 > $threshold1" | bc -l) )); then | ||
echo "New coverage for the module dubbo-common - $COVERAGE1%. Coverage is improved!" | ||
elif (( $(echo "$COVERAGE2 > $threshold2" | bc -l) )); then | ||
echo "New coverage for the module dubbo-serialization-hessian2 - $COVERAGE2%. Coverage is improved!" | ||
elif (( $(echo "$COVERAGE3 > $threshold3" | bc -l) )); then | ||
echo "New coverage for the module dubbo-serialization-fastjson2 - $COVERAGE3%. Coverage is improved!" | ||
elif (( $(echo "$COVERAGE4 > $threshold4" | bc -l) )); then | ||
echo "New coverage for the module dubbo-remoting-api - $COVERAGE4%. Coverage is improved!" | ||
elif (( $(echo "$COVERAGE5 > $threshold5" | bc -l) )); then | ||
echo "New coverage for the module dubbo-metrics-api - $COVERAGE5%. Coverage is improved!" | ||
elif (( $(echo "$COVERAGE6 > $threshold6" | bc -l) )); then | ||
echo "New coverage for the module dubbo-config-api - $COVERAGE6%. Coverage is improved!" | ||
else | ||
echo "Coverage is not improved." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import csv | ||
|
||
def computeCoverage(fileList): | ||
"""Parses one or more jacoco.csv files and computes code coverage percentages.""" | ||
missed = 0 | ||
covered = 0 | ||
missedBranches = 0 | ||
coveredBranches = 0 | ||
|
||
for filename in fileList: | ||
try: | ||
with open(filename, newline='') as csvfile: | ||
jacocoReader = csv.reader(csvfile) | ||
for i, row in enumerate(jacocoReader): | ||
if i > 0: # Skip header | ||
missed += int(row[3]) | ||
covered += int(row[4]) | ||
missedBranches += int(row[5]) | ||
coveredBranches += int(row[6]) | ||
except FileNotFoundError: | ||
print(f"File not found: {filename}") | ||
return (0, 0) | ||
except Exception as e: | ||
print(f"Error processing file {filename}: {str(e)}") | ||
return (0, 0) | ||
|
||
return ( | ||
calculatePercentage(covered, missed), | ||
calculatePercentage(coveredBranches, missedBranches) | ||
) | ||
|
||
def calculatePercentage(covered, missed): | ||
"""Calculates the coverage percentage.""" | ||
if missed == 0 and covered == 0: | ||
return 1 | ||
return covered / (covered + missed) | ||
|
||
def main(jacocoCsvFile): | ||
coverage, branchCoverage = computeCoverage([jacocoCsvFile]) | ||
"""Return coverage percentage to check against the previous coverage.""" | ||
return round(coverage * 100, 2) | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
jacocoCsvFile = sys.argv[1] | ||
result = main(jacocoCsvFile) | ||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters