This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (108 loc) · 3.74 KB
/
ci.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Grant execute permission for Gradlew
run: chmod +x ./gradlew
- name: Install xmllint
run: |
sudo apt-get update
sudo apt-get install -y libxml2-utils
- name: Run Spotless Apply
run: ./gradlew spotlessApply
- name: Run Spotless Check
run: ./gradlew spotlessCheck
- name: Run tests and generate JaCoCo report
run: |
./gradlew clean test jacocoTestReport
echo "Generated JaCoCo reports:"
ls -R build/reports/jacoco || echo "No JaCoCo reports found."
- name: Extract and display coverage percentage
run: |
# Find the JaCoCo XML report
REPORT_PATH=build/reports/jacoco/test/jacocoTestReport.xml
if [ ! -f "$REPORT_PATH" ]; then
echo "JaCoCo coverage report not found!"
exit 1
fi
echo "Found JaCoCo XML report at: $REPORT_PATH"
# Display the content of the XML report
echo "Content of $REPORT_PATH:"
cat "$REPORT_PATH"
# Extract coverage percentage using xmllint
COVERED=$(xmllint --xpath 'string(//counter[@type="LINE"]/@covered)' "$REPORT_PATH")
MISSED=$(xmllint --xpath 'string(//counter[@type="LINE"]/@missed)' "$REPORT_PATH")
if [ -z "$COVERED" ] || [ -z "$MISSED" ]; then
echo "No coverage data found in the report."
exit 1
fi
# Calculate the percentage
TOTAL=$((COVERED + MISSED))
PERCENTAGE=$(echo "scale=2; ($COVERED / $TOTAL) * 100" | bc)
echo "Coverage: $PERCENTAGE%"
# Validate coverage percentage
MINIMUM=50.0
if (( $(echo "$PERCENTAGE < $MINIMUM" | bc -l) )); then
echo "Coverage is below the minimum required: $MINIMUM%!"
exit 1
fi
echo "Coverage validation passed with $PERCENTAGE%."
- name: Upload JaCoCo HTML Report
uses: actions/upload-artifact@v3
with:
name: jacoco-html-report
path: build/reports/jacoco/test/html
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup JDK
uses: actions/setup-java@v3
with:
java-version: 21
distribution: 'zulu'
- name: Setup Docker Compose
run: |
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('build.gradle', 'gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Raise infra
run: make infrastructure/up
- name: Grant execute permission for Gradlew
run: chmod +x gradlew
- name: Run Spotless Apply
run: ./gradlew spotlessApply
- name: Code linting
run: ./gradlew spotlessCheck
- name: Static analysis
run: |
./gradlew pmdMain
./gradlew pmdTest
- name: Run tests
run: ./gradlew test
- name: Build
run: ./gradlew clean assemble