Skip to content

Commit 355d134

Browse files
committed
Add existing branch check to integration test
1 parent d19c084 commit 355d134

File tree

2 files changed

+75
-9
lines changed

2 files changed

+75
-9
lines changed

.github/workflows/integration-test.yml

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ jobs:
131131
name: junit-xml-reports-${{ matrix.split-index }}
132132
path: build/reports/test-results/*.xml
133133

134-
merge-junit-reports:
135-
name: Merge JUnit reports
134+
merge-junit-reports-with-existing-branch:
135+
name: Merge JUnit reports with existing branch
136136
runs-on: ubuntu-latest
137137
needs:
138138
- integration-test
@@ -142,18 +142,84 @@ jobs:
142142
- name: Checkout split-tests-java-action
143143
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
144144

145+
- name: Create JUnit reports branch
146+
run: |
147+
BRANCH=junit-reports-it-${{ github.sha }}-existing
148+
echo "Creating branch $BRANCH"
149+
git switch --orphan $BRANCH
150+
git config user.name "${{ github.actor }}"
151+
git config user.email "${{ github.actor }}@users.noreply.github.com"
152+
git commit --allow-empty -m "Initial commit for JUnit reports branch"
153+
git push origin --set-upstream $BRANCH
154+
git switch ${{ github.ref_name }}
155+
156+
- name: Merge JUnit reports
157+
uses: ./merge-junit-reports
158+
with:
159+
git-branch: junit-reports-it-${{ github.sha }}-existing
160+
artifact-name: junit-xml-report-existing
161+
split-artifact-pattern: junit-xml-reports-*
162+
split-artifact-delete-merged: false
163+
164+
- name: Checkout JUnit reports
165+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
166+
with:
167+
path: junit-reports-assertion
168+
ref: junit-reports-it-${{ github.sha }}-existing
169+
170+
- name: Assert JUnit reports
171+
working-directory: junit-reports-assertion
172+
run: |
173+
for SPLIT_INDEX in {0..3}; do
174+
REPORT_FILE="TEST-de.donnerbart.example.ActionSplit${SPLIT_INDEX}Test.xml"
175+
SEARCH_STRING='name="de.donnerbart.example.ActionSplit'${SPLIT_INDEX}'Test"'
176+
if [[ ! -f "$REPORT_FILE" ]]; then
177+
echo "Error: JUnit report $REPORT_FILE not found!"
178+
ls -l
179+
exit 1
180+
fi
181+
if ! grep -q "$SEARCH_STRING" "$REPORT_FILE"; then
182+
echo "Error: JUnit report $REPORT_FILE does not contain the required string '$SEARCH_STRING'!"
183+
cat $REPORT_FILE
184+
exit 1
185+
fi
186+
echo "JUnit report $REPORT_FILE is valid"
187+
done
188+
FILE_COUNT=$(ls -1 | wc -l)
189+
if [[ "$FILE_COUNT" -ne 4 ]]; then
190+
echo "Error: Expected 4 JUnit reports, but found $FILE_COUNT files!"
191+
ls -l
192+
exit 1
193+
fi
194+
195+
- name: Cleanup JUnit reports branch
196+
if: always()
197+
run: |
198+
git push origin --delete junit-reports-it-${{ github.sha }}-existing || true
199+
200+
merge-junit-reports-with-new-branch:
201+
name: Merge JUnit reports with new branch
202+
runs-on: ubuntu-latest
203+
needs:
204+
- merge-junit-reports-with-existing-branch
205+
permissions:
206+
contents: write
207+
steps:
208+
- name: Checkout split-tests-java-action
209+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
210+
145211
- name: Merge JUnit reports
146212
uses: ./merge-junit-reports
147213
with:
148-
git-branch: junit-reports-it-${{ github.sha }}
149-
artifact-name: junit-xml-reports
214+
git-branch: junit-reports-it-${{ github.sha }}-new
215+
artifact-name: junit-xml-report-new
150216
split-artifact-pattern: junit-xml-reports-*
151217

152218
- name: Checkout JUnit reports
153219
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
154220
with:
155221
path: junit-reports-assertion
156-
ref: junit-reports-it-${{ github.sha }}
222+
ref: junit-reports-it-${{ github.sha }}-new
157223

158224
- name: Assert JUnit reports
159225
working-directory: junit-reports-assertion
@@ -183,7 +249,7 @@ jobs:
183249
- name: Download JUnit reports artifact
184250
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4
185251
with:
186-
name: junit-xml-reports
252+
name: junit-xml-report-new
187253
path: junit-reports-artifact-assertion
188254

189255
- name: Assert JUnit reports artifact
@@ -214,4 +280,4 @@ jobs:
214280
- name: Cleanup JUnit reports branch
215281
if: always()
216282
run: |
217-
git push origin --delete junit-reports-it-${{ github.sha }} || true
283+
git push origin --delete junit-reports-it-${{ github.sha }}-new || true

merge-junit-reports/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ runs:
4545
working-directory: junit-reports
4646
run: |
4747
if git ls-remote --exit-code --heads origin ${{ inputs.git-branch }}; then
48-
echo "Switching to branch ${{ inputs.git-branch }}"
48+
echo "Switching to existing branch ${{ inputs.git-branch }}"
4949
git fetch --quiet
5050
git switch ${{ inputs.git-branch }}
5151
else
52-
echo "Creating branch ${{ inputs.git-branch }}"
52+
echo "Creating new branch ${{ inputs.git-branch }}"
5353
git switch --orphan ${{ inputs.git-branch }}
5454
git config user.name "${{ github.actor }}"
5555
git config user.email "${{ github.actor }}@users.noreply.github.com"

0 commit comments

Comments
 (0)