Skip to content

Commit 6fa09bb

Browse files
committed
Add download-junit-reports sub-action
1 parent 823e963 commit 6fa09bb

File tree

4 files changed

+214
-6
lines changed

4 files changed

+214
-6
lines changed

.github/workflows/integration-test.yml

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Integration tests
22

33
on:
44
push:
5-
branches: ["**"]
5+
branches: [ "**" ]
66

77
concurrency:
88
group: integration-test-${{ github.ref }}
@@ -12,9 +12,126 @@ env:
1212
split-total: 4
1313

1414
jobs:
15+
download-junit-reports-test:
16+
name: Download JUnit reports
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout split-tests-java-action
20+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
21+
22+
- name: Create JUnit reports branch
23+
run: |
24+
BRANCH=junit-reports-it-${{ github.sha }}-download
25+
echo "Creating branch $BRANCH"
26+
git switch --orphan $BRANCH
27+
git config user.name "${{ github.actor }}"
28+
git config user.email "${{ github.actor }}@users.noreply.github.com"
29+
touch first.xml
30+
git add *.xml
31+
git commit -m "Initial commit for JUnit reports branch"
32+
SHA=$(git rev-parse HEAD)
33+
git push origin --set-upstream $BRANCH
34+
git switch ${{ github.ref_name }}
35+
echo "Saving expexted JUnit reports SHA $SHA"
36+
echo "expected-junit-reports-sha=${SHA}" >> "$GITHUB_ENV"
37+
38+
- name: Download JUnit reports
39+
uses: ./download-junit-reports
40+
with:
41+
git-branch: junit-reports-it-${{ github.sha }}-download
42+
path: junit-reports-first
43+
44+
- name: Assert JUnit reports
45+
working-directory: junit-reports-first
46+
run: |
47+
REPORT_FILE="first.xml"
48+
if [[ ! -f "$REPORT_FILE" ]]; then
49+
echo "Error: JUnit report $REPORT_FILE not found!"
50+
ls -l
51+
exit 1
52+
fi
53+
FILE_COUNT=$(ls -1 | wc -l)
54+
if [[ "$FILE_COUNT" -ne 1 ]]; then
55+
echo "Error: Expected 1 JUnit reports, but found $FILE_COUNT files!"
56+
ls -l
57+
exit 1
58+
fi
59+
60+
- name: Update JUnit reports
61+
working-directory: junit-reports-first
62+
run: |
63+
touch second.xml
64+
git add *.xml
65+
git config user.name "${{ github.actor }}"
66+
git config user.email "${{ github.actor }}@users.noreply.github.com"
67+
git commit -m "Second commit for JUnit reports branch"
68+
git push
69+
70+
- name: Download JUnit reports
71+
uses: ./download-junit-reports
72+
with:
73+
git-branch: junit-reports-it-${{ github.sha }}-download
74+
path: junit-reports-second
75+
76+
- name: Assert JUnit reports
77+
working-directory: junit-reports-second
78+
run: |
79+
REPORT_FILE="first.xml"
80+
if [[ ! -f "$REPORT_FILE" ]]; then
81+
echo "Error: JUnit report $REPORT_FILE not found!"
82+
ls -l
83+
exit 1
84+
fi
85+
FILE_COUNT=$(ls -1 | wc -l)
86+
if [[ "$FILE_COUNT" -ne 1 ]]; then
87+
echo "Error: Expected 1 JUnit reports, but found $FILE_COUNT files!"
88+
ls -l
89+
exit 1
90+
fi
91+
92+
- name: Download JUnit reports SHA artifact
93+
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4
94+
with:
95+
name: junit-xml-reports-sha
96+
path: junit-xml-reports-sha-artifact-assertion
97+
98+
- name: Assert JUnit reports SHA artifact
99+
working-directory: junit-xml-reports-sha-artifact-assertion
100+
run: |
101+
SHA_FILE="junit-reports-sha.txt"
102+
if [[ ! -f "$SHA_FILE" ]]; then
103+
echo "Error: JUnit reports SHA file $SHA_FILE not found!"
104+
ls -l
105+
exit 1
106+
fi
107+
FILE_COUNT=$(ls -1 | wc -l)
108+
if [[ "$FILE_COUNT" -ne 1 ]]; then
109+
echo "Error: Expected 1 JUnit reports SHA file, but found $FILE_COUNT files!"
110+
ls -l
111+
exit 1
112+
fi
113+
ARTIFACT_SHA=$(cat $SHA_FILE)
114+
if [ "$ARTIFACT_SHA" != "${{ env.expected-junit-reports-sha }}" ]; then
115+
echo "Error: JUnit reports SHA $ARTIFACT_SHA in artifact does not match expected SHA ${{ env.expected-junit-reports-sha }}"
116+
exit 1
117+
fi
118+
119+
- name: Clean up JUnit reports branch
120+
if: always()
121+
run: |
122+
git push origin --delete junit-reports-it-${{ github.sha }}-download || true
123+
124+
- name: Clean up JUnit reports artifact
125+
uses: geekyeggo/delete-artifact@f275313e70c08f6120db482d7a6b98377786765b #v5
126+
with:
127+
name: junit-xml-reports-sha
128+
failOnError: false
129+
15130
generate-split-index-json:
16131
name: Generate split indexes
17132
runs-on: ubuntu-latest
133+
needs:
134+
download-junit-reports-test
18135
outputs:
19136
json: ${{ steps.generate.outputs.split-index-json }}
20137
steps:
@@ -192,7 +309,7 @@ jobs:
192309
exit 1
193310
fi
194311
195-
- name: Cleanup JUnit reports branch
312+
- name: Clean up JUnit reports branch
196313
if: always()
197314
run: |
198315
git push origin --delete junit-reports-it-${{ github.sha }}-existing || true
@@ -277,7 +394,7 @@ jobs:
277394
exit 1
278395
fi
279396
280-
- name: Cleanup JUnit reports branch
397+
- name: Clean up JUnit reports branch
281398
if: always()
282399
run: |
283400
git push origin --delete junit-reports-it-${{ github.sha }}-new || true

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@ jobs:
5050
path: project
5151

5252
- name: Checkout JUnit reports
53-
uses: actions/checkout@v4
53+
uses: donnerbart/split-tests-java-action/download-junit-reports@v1
5454
with:
55+
git-branch: junit-reports/${{ github.base_ref }}
5556
path: junit-reports
56-
ref: junit-reports/${{ github.base_ref }}
57-
continue-on-error: true
5857

5958
- name: Set up JDK 21
6059
uses: actions/setup-java@v4

download-junit-reports/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# @donnerbart/split-tests-java-action/download-junit-reports
2+
3+
Downloads the JUnit reports from a Git branch and stores the SHA values in a GitHub artifact.
4+
On a job re-run this SHA will be used to check out the same test results to ensure a consistent test distribution.

download-junit-reports/action.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Merge JUnit reports
2+
3+
description: Downloads the JUnit reports a Git branch
4+
branding:
5+
icon: download
6+
color: blue
7+
inputs:
8+
git-branch:
9+
description: The Git branch in this repository to download the JUnit reports from (string)
10+
required: true
11+
type: string
12+
path:
13+
description: Relative path under the GitHub workspace to download the JUnit reports (string)
14+
required: false
15+
type: string
16+
default: ${{ github.workspace }}
17+
artifact-name:
18+
description: The artifact name for the SHA of the JUnit reports (string)
19+
required: false
20+
type: string
21+
default: junit-xml-reports-sha
22+
artifact-path:
23+
description: Path to save the SHA of the JUnit reports in the GitHub workspace (string)
24+
required: false
25+
type: string
26+
default: junit-xml-reports-sha
27+
runs:
28+
using: composite
29+
steps:
30+
- name: Download JUnit reports SHA artifact
31+
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4
32+
with:
33+
name: ${{ inputs.artifact-name }}
34+
path: ${{ inputs.artifact-path }}
35+
continue-on-error: true
36+
37+
- name: Check JUnit reports SHA
38+
id: junit-reports-sha
39+
shell: bash
40+
run: |
41+
echo "Checking JUnit reports SHA"
42+
UPLOAD_SHA_ARTIFACT=true
43+
CHECKOUT_REF=${{ inputs.git-branch }}
44+
if [ -d ${{ inputs.artifact-path }} ]; then
45+
cd ${{ inputs.artifact-path }}
46+
if [ -f junit-reports-sha.txt ]; then
47+
UPLOAD_SHA_ARTIFACT=false
48+
CHECKOUT_REF=$(cat junit-reports-sha.txt)
49+
fi
50+
else
51+
mkdir ${{ inputs.artifact-path }} || true
52+
fi
53+
if [ "$UPLOAD_SHA_ARTIFACT" == "true" ]; then
54+
echo "Checking out JUnit reports from branch $CHECKOUT_REF"
55+
else
56+
echo "Checking out JUnit reports from previously used SHA $CHECKOUT_REF"
57+
fi
58+
echo "upload-artifact=${UPLOAD_SHA_ARTIFACT}" >> "$GITHUB_OUTPUT"
59+
echo "ref=${CHECKOUT_REF}" >> "$GITHUB_OUTPUT"
60+
61+
- name: Checkout repository
62+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
63+
with:
64+
path: ${{ inputs.path }}
65+
ref: ${{ steps.junit-reports-sha.outputs.ref }}
66+
67+
- name: Save JUnit reports SHA
68+
if: ${{ steps.junit-reports-sha.outputs.upload-artifact == 'true' }}
69+
shell: bash
70+
working-directory: ${{ inputs.path }}
71+
run: |
72+
SHA=$(git rev-parse HEAD)
73+
echo "Saving JUnit reports SHA $SHA"
74+
cd ../${{ inputs.artifact-path }}
75+
echo -n "$SHA" > junit-reports-sha.txt
76+
77+
- name: Upload JUnit report SHA
78+
if: ${{ steps.junit-reports-sha.outputs.upload-artifact == 'true' }}
79+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
80+
with:
81+
name: ${{ inputs.artifact-name }}
82+
path: ${{ inputs.artifact-path }}
83+
84+
- name: Clean up JUnit reports SHA
85+
if: always()
86+
shell: bash
87+
run: |
88+
rm -rf ${{ inputs.artifact-path }} || true

0 commit comments

Comments
 (0)