-
Notifications
You must be signed in to change notification settings - Fork 5k
293 lines (262 loc) · 9.85 KB
/
unit-test.yml
File metadata and controls
293 lines (262 loc) · 9.85 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Test
on:
pull_request:
push:
paths-ignore:
- '**/*.md'
- 'dolphinscheduler-ui'
branches:
- '[0-9]+.[0-9]+.[0-9]+-prepare'
- '[0-9]+.[0-9]+.[0-9]+-release'
- 'dev'
concurrency:
group: unit-test-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
paths-filter:
name: Unit-Test-Path-Filter
runs-on: ubuntu-latest
outputs:
not-ignore: ${{ steps.filter.outputs.not-ignore }}
steps:
- uses: actions/checkout@v6
with:
submodules: true
- uses: ./.github/actions/paths-filter
id: filter
with:
filters: |
not-ignore:
- '!(docs/**)'
sanity-check:
name: Sanity Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Sanity Check
uses: ./.github/actions/sanity-check
with:
token: ${{ secrets.GITHUB_TOKEN }}
generate-matrix:
name: Generate Module Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v6
- name: Parse modules from pom.xml
id: set-matrix
run: |
MODULES=$(python3 - <<'EOF'
import xml.etree.ElementTree as ET, json, re
tree = ET.parse('pom.xml')
ns = {'m': 'http://maven.apache.org/POM/4.0.0'}
root = tree.getroot()
# Support both namespaced and non-namespaced pom.xml
modules = root.findall('.//m:modules/m:module', ns)
if not modules:
modules = root.findall('.//modules/module')
# Exclude aggregator-only or non-testable modules
exclude = re.compile(r'dolphinscheduler-bom|dolphinscheduler-dist|dolphinscheduler-microbench|dolphinscheduler-ui')
result = [m.text.strip() for m in modules if m.text and not exclude.search(m.text)]
print(json.dumps(result))
EOF
)
echo "matrix={\"module\":$MODULES}" >> "$GITHUB_OUTPUT"
echo "Discovered modules: $MODULES"
unit-test:
name: Unit-Test (${{ matrix.module }} | Java ${{ matrix.java }})
needs: [ paths-filter, generate-matrix, sanity-check ]
if: ${{ (needs.paths-filter.outputs.not-ignore == 'true') || (github.event_name == 'push') }}
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '11' ]
module: ${{ fromJSON(needs.generate-matrix.outputs.matrix).module }}
timeout-minutes: 60
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Collect Workflow Metrics
uses: ./.github/actions/actions-workflow-metrics
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v5
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
- uses: actions/cache@v5
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-backend
restore-keys: ${{ runner.os }}-maven-
# Use -am (--also-make) so Maven automatically builds all upstream
# dependency modules before running tests in the target module.
# -DskipTests=true skips tests in dependency modules; only the
# target module (-pl) runs its unit tests via verify.
- name: Run Unit Tests (${{ matrix.module }})
run: |
export MAVEN_OPTS="-Xmx8g -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=1024m"
./mvnw verify -B \
-pl "${{ matrix.module }}" \
-am \
-DskipTests=true \
-Dmaven.test.skip=false \
-pl "${{ matrix.module }}" \
-Dspotless.skip=true \
-DskipUT=false \
-Danalyze.skip=true
- name: Collect jacoco exec files
if: always()
run: |
mkdir -p /tmp/jacoco-exec
find . -name "jacoco.exec" -exec cp --backup=numbered {} /tmp/jacoco-exec/ \;
- name: Upload jacoco exec
uses: actions/upload-artifact@v6
if: always()
with:
name: jacoco-exec-java${{ matrix.java }}-${{ matrix.module }}
path: /tmp/jacoco-exec/
retention-days: 1
- name: Upload surefire reports
uses: actions/upload-artifact@v6
if: always()
with:
name: surefire-java${{ matrix.java }}-${{ matrix.module }}
path: '**/target/surefire-reports/'
retention-days: 7
- name: Upload coverage to Codecov
if: matrix.java == '11'
run: CODECOV_TOKEN="09c2663f-b091-4258-8a47-c981827eb29a" bash <(curl -s https://codecov.io/bash)
sonar:
name: SonarCloud Analysis
runs-on: ubuntu-latest
needs: [ paths-filter, unit-test ]
if: ${{ needs.unit-test.result == 'success' }}
timeout-minutes: 30
steps:
- uses: actions/checkout@v6
with:
submodules: true
fetch-depth: 0
- name: Download all jacoco exec files (Java 11)
uses: actions/download-artifact@v8
with:
pattern: jacoco-exec-java11-*
path: all-jacoco-exec/
merge-multiple: true
- name: Set up JDK 17 for SonarCloud
uses: actions/setup-java@v5
with:
java-version: 17
distribution: 'adopt'
- uses: actions/cache@v5
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-backend
restore-keys: ${{ runner.os }}-maven-
# Use jacococli.jar instead of jacoco:merge Maven goal.
# The 'fileSets' parameter of jacoco:merge cannot be passed via -D on
# the command line; it must be declared in pom.xml <configuration>.
# jacococli.jar merge accepts file paths directly, no XML config needed.
- name: Download jacococli.jar
run: |
JACOCO_VERSION=$(./mvnw help:evaluate -Dexpression=jacoco.version -q -DforceStdout 2>/dev/null || echo "0.8.14")
echo "Using JaCoCo version: $JACOCO_VERSION"
mvn dependency:get \
-Dartifact=org.jacoco:org.jacoco.cli:${JACOCO_VERSION}:jar:nodeps \
-Ddest=/tmp/jacococli.jar \
-q
# Fallback: copy from local .m2 cache if dependency:get did not place it at -Ddest
find ~/.m2 -name "org.jacoco.cli-*-nodeps.jar" | head -1 | xargs -I{} cp {} /tmp/jacococli.jar || true
- name: Merge JaCoCo exec files via jacococli
run: |
# Collect all .exec files under the downloaded artifact directory
EXEC_FILES=$(find all-jacoco-exec/ -name "*.exec" | tr '\n' ' ')
echo "Merging exec files: $EXEC_FILES"
mkdir -p target
java -jar /tmp/jacococli.jar merge $EXEC_FILES \
--destfile target/merged.exec
- name: Generate merged JaCoCo XML report
run: |
./mvnw jacoco:report \
-Djacoco.dataFile=target/merged.exec \
-Dspotless.skip=true \
-Dmaven.test.skip=true
- name: Run SonarCloud Analysis
run: >
./mvnw --batch-mode verify sonar:sonar
-Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
-Dmaven.test.skip=true
-Dspotless.skip=true
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.organization=apache
-Dsonar.core.codeCoveragePlugin=jacoco
-Dsonar.projectKey=apache-dolphinscheduler
-Dsonar.token=e4058004bc6be89decf558ac819aa1ecbee57682
-Dsonar.exclusions=dolphinscheduler-ui/src/**/i18n/locale/*.js,dolphinscheduler-microbench/src/**/*
-Dhttp.keepAlive=false
-Dmaven.wagon.http.pool=false
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
-DskipUT=true
-Danalyze.skip=true
publish-test-results:
name: Publish Test Results
runs-on: ubuntu-latest
needs: [ paths-filter, unit-test ]
if: ${{ needs.unit-test.result == 'success' }}
steps:
- name: Download all surefire reports
uses: actions/download-artifact@v8
with:
pattern: surefire-java11-*
path: all-surefire/
merge-multiple: true
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: all-surefire/**/*.xml
comment_mode: off
result:
name: Unit Test
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [ unit-test, paths-filter, sonar, sanity-check ]
if: always()
steps:
- name: Status
run: |
if [[ ${{ needs.paths-filter.outputs.not-ignore }} == 'false' && ${{ github.event_name }} == 'pull_request' ]]; then
echo "Skip Unit Test!"
exit 0
fi
if [[ ${{ needs.sanity-check.result }} != 'success' ]]; then
echo "Sanity Check Failed!"
exit -1
fi
if [[ ${{ needs.unit-test.result }} != 'success' ]]; then
echo "Unit Test Failed!"
exit -1
fi
if [[ ${{ needs.sonar.result }} != 'success' ]]; then
echo "SonarCloud Analysis Failed!"
exit -1
fi