Skip to content

Commit 2798e02

Browse files
committed
Add merging of JUnit reports to integration test
1 parent f4b126f commit 2798e02

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

.github/workflows/integration-test.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,110 @@ jobs:
108108
echo "The split tests are not matching"
109109
exit 1
110110
fi
111+
112+
- name: Create simulated JUnit report
113+
run: |
114+
mkdir -p build/reports/test-results
115+
CLASS="de.donnerbart.example.ActionSplit${{ matrix.split-index }}Test"
116+
FILE="build/reports/test-results/TEST-$CLASS.xml"
117+
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $FILE
118+
echo "<testsuite name=\"$CLASS\" tests=\"1\" skipped=\"0\" failures=\"0\" errors=\"0\" timestamp=\"1970-01-01T00:00:00\" hostname=\"foobar\" time=\"23.42\">" >> $FILE
119+
echo " <properties/>" >> $FILE
120+
echo " <testcase name=\"testMethod()\" classname=\"$CLASS\" time=\"23.42\">" >> $FILE
121+
echo " <system-out><![CDATA[00:00:00.000 [Test] INFO Test log for split ${{ matrix.split-index }}" >> $FILE
122+
echo "00:00:00.001 [Test] INFO Done" >> $FILE
123+
echo "]]></system-out>" >> $FILE
124+
echo " <system-err><![CDATA[]]></system-err>" >> $FILE
125+
echo " </testcase>" >> $FILE
126+
echo "</testsuite>" >> $FILE
127+
128+
- name: Upload JUnit report artifact
129+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
130+
with:
131+
name: junit-xml-reports-${{ matrix.split-index }}
132+
path: build/reports/test-results/*.xml
133+
134+
merge-junit-reports:
135+
name: Merge JUnit reports
136+
runs-on: ubuntu-latest
137+
needs:
138+
- integration-test
139+
permissions:
140+
contents: write
141+
steps:
142+
- name: Checkout split-tests-java-action
143+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
144+
145+
- name: Merge JUnit reports
146+
uses: ./merge-junit-reports
147+
with:
148+
git-branch: junit-reports-it-${{ github.sha }}
149+
artifact-name: junit-xml-reports
150+
split-artifact-pattern: junit-xml-reports-*
151+
152+
- name: Checkout JUnit reports
153+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
154+
with:
155+
path: junit-reports-assertion
156+
ref: junit-reports-it-${{ github.sha }}
157+
158+
- name: Assert JUnit reports
159+
working-directory: junit-reports-assertion
160+
run: |
161+
for SPLIT_INDEX in {0..3}; do
162+
REPORT_FILE="TEST-de.donnerbart.example.ActionSplit${SPLIT_INDEX}Test.xml"
163+
SEARCH_STRING='name="de.donnerbart.example.ActionSplit'${SPLIT_INDEX}'Test"'
164+
if [[ ! -f "$REPORT_FILE" ]]; then
165+
echo "Error: JUnit report $REPORT_FILE not found!"
166+
ls -l
167+
exit 1
168+
fi
169+
if ! grep -q "$SEARCH_STRING" "$REPORT_FILE"; then
170+
echo "Error: JUnit report $REPORT_FILE does not contain the required string '$SEARCH_STRING'!"
171+
cat $REPORT_FILE
172+
exit 1
173+
fi
174+
echo "JUnit report $REPORT_FILE is valid"
175+
done
176+
FILE_COUNT=$(ls -1 | wc -l)
177+
if [[ "$FILE_COUNT" -ne 4 ]]; then
178+
echo "Error: Expected 4 JUnit reports, but found $FILE_COUNT files!"
179+
ls -l
180+
exit 1
181+
fi
182+
183+
- name: Download JUnit reports artifact
184+
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4
185+
with:
186+
name: junit-xml-reports
187+
path: junit-reports-artifact-assertion
188+
189+
- name: Assert JUnit reports artifact
190+
working-directory: junit-reports-artifact-assertion
191+
run: |
192+
for SPLIT_INDEX in {0..3}; do
193+
REPORT_FILE="TEST-de.donnerbart.example.ActionSplit${SPLIT_INDEX}Test.xml"
194+
SEARCH_STRING='name="de.donnerbart.example.ActionSplit'${SPLIT_INDEX}'Test"'
195+
if [[ ! -f "$REPORT_FILE" ]]; then
196+
echo "Error: JUnit report $REPORT_FILE not found!"
197+
ls -l
198+
exit 1
199+
fi
200+
if ! grep -q "$SEARCH_STRING" "$REPORT_FILE"; then
201+
echo "Error: JUnit report $REPORT_FILE does not contain the required string '$SEARCH_STRING'!"
202+
cat $REPORT_FILE
203+
exit 1
204+
fi
205+
echo "JUnit report $REPORT_FILE is valid"
206+
done
207+
FILE_COUNT=$(ls -1 | wc -l)
208+
if [[ "$FILE_COUNT" -ne 4 ]]; then
209+
echo "Error: Expected 4 JUnit reports, but found $FILE_COUNT files!"
210+
ls -l
211+
exit 1
212+
fi
213+
214+
- name: Cleanup JUnit reports branch
215+
if: always()
216+
run: |
217+
git push origin --delete junit-reports-it-${{ github.sha }} || true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
debug: true
7979

8080
- name: Run integration tests
81-
run: ./gradlew :integrationTest ${{ steps.split-tests.outputs.test-suite }}
81+
run: ./gradlew :integrationTest ${{ steps.split-tests.outputs.test-suite }}
8282

8383
- name: Upload JUnit report artifact
8484
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)