Skip to content

Fix JUnit reports SHA lookup with many artifacts and merging of inval… #222

Fix JUnit reports SHA lookup with many artifacts and merging of inval…

Fix JUnit reports SHA lookup with many artifacts and merging of inval… #222

name: Integration tests
on:
push:
branches: [ "**" ]
concurrency:
group: integration-test-${{ github.ref }}
cancel-in-progress: true
env:
split-total: 4
jobs:
checkout-junit-reports:
name: Checkout JUnit reports
runs-on: ubuntu-latest
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Create JUnit reports branch
run: |
BRANCH=junit-reports-it-${{ github.sha }}-download
echo "Creating branch $BRANCH"
git switch --orphan $BRANCH
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
touch first.xml
git add *.xml
git commit -m "Initial commit for JUnit reports branch"
SHA=$(git rev-parse HEAD)
git push origin --set-upstream $BRANCH
git switch ${{ github.ref_name }}
echo "Saving expexted JUnit reports SHA $SHA"
echo "expected-junit-reports-sha=${SHA}" >> "$GITHUB_ENV"
- name: Checkout JUnit reports (split-index 1)
uses: ./checkout-junit-reports
with:
split-index: 1
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-first-index-1
- name: Checkout JUnit reports (split-index 0a)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-first-index-0
- name: Checkout JUnit reports (split-index 2)
uses: ./checkout-junit-reports
with:
split-index: 2
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-first-index-2
- name: Checkout JUnit reports (split-index 0b)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-first-index-3
- name: Checkout JUnit reports (split-index 0c)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-first-index-4
upload-artifact: false
- name: Assert JUnit reports
run: |
for SPLIT_INDEX in {0..3}; do
echo "Checking JUnit reports for split-index $SPLIT_INDEX"
if [[ ! -d "junit-reports-first-index-$SPLIT_INDEX" ]]; then
echo "Error: JUnit report directory not found!"
ls -l
exit 1
fi
cd junit-reports-first-index-$SPLIT_INDEX
REPORT_FILE="first.xml"
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 1 ]]; then
echo "Error: Expected 1 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
cd ..
done
- name: Update JUnit reports
working-directory: junit-reports-first-index-0
run: |
touch second.xml
git add *.xml
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git commit -m "Second commit for JUnit reports branch"
git push origin HEAD:junit-reports-it-${{ github.sha }}-download
- name: Download JUnit reports
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-second
- name: Assert JUnit reports
working-directory: junit-reports-second
run: |
REPORT_FILE="first.xml"
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 1 ]]; then
echo "Error: Expected 1 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
- name: Download JUnit reports SHA artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: junit-reports-sha
path: junit-xml-reports-sha-artifact-assertion
- name: Assert JUnit reports SHA artifact
working-directory: junit-xml-reports-sha-artifact-assertion
run: |
SHA_FILE="junit-reports-sha.txt"
if [[ ! -f "$SHA_FILE" ]]; then
echo "Error: JUnit reports SHA file $SHA_FILE not found!"
ls -l
exit 1
fi
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 1 ]]; then
echo "Error: Expected 1 JUnit reports SHA file, but found $FILE_COUNT files!"
ls -l
exit 1
fi
ARTIFACT_SHA=$(cat $SHA_FILE)
if [ "$ARTIFACT_SHA" != "${{ env.expected-junit-reports-sha }}" ]; then
echo "Error: JUnit reports SHA $ARTIFACT_SHA in artifact does not match expected SHA ${{ env.expected-junit-reports-sha }}"
exit 1
fi
- name: Clean up JUnit reports branch
if: always()
run: |
git push origin --delete junit-reports-it-${{ github.sha }}-download || true
- name: Clean up JUnit reports artifact
uses: geekyeggo/delete-artifact@176a747ab7e287e3ff4787bf8a148716375ca118 # v6
with:
name: junit-reports-sha
failOnError: false
checkout-junit-reports-with-nonexistent-branch:
name: Checkout JUnit reports with non-existent branch
runs-on: ubuntu-latest
needs:
- checkout-junit-reports
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Checkout JUnit reports (split-index 1)
uses: ./checkout-junit-reports
with:
split-index: 1
git-branch: junit-reports-it-nonexistent
path: junit-reports-first-index-1
- name: Checkout JUnit reports (split-index 0a)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-nonexistent
path: junit-reports-first-index-0
- name: Checkout JUnit reports (split-index 2)
uses: ./checkout-junit-reports
with:
split-index: 2
git-branch: junit-reports-it-nonexistent
path: junit-reports-first-index-2
- name: Checkout JUnit reports (split-index 0b)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-nonexistent
path: junit-reports-first-index-3
- name: Checkout JUnit reports (split-index 0c)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-nonexistent
path: junit-reports-first-index-4
upload-artifact: false
- name: Assert JUnit reports
run: |
for SPLIT_INDEX in {0..3}; do
echo "Checking JUnit reports for split-index $SPLIT_INDEX"
if [[ ! -d "junit-reports-first-index-$SPLIT_INDEX" ]]; then
echo "Error: JUnit report directory not found!"
ls -l
exit 1
fi
cd junit-reports-first-index-$SPLIT_INDEX || exit 1
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 0 ]]; then
echo "Error: Expected empty directory, but found $FILE_COUNT files!"
ls -l
exit 1
fi
cd ..
done
checkout-junit-reports-pagination-setup:
name: Checkout JUnit reports with paginated artifacts (setup)
runs-on: ubuntu-latest
outputs:
expected-junit-reports-sha: ${{ steps.create-branch.outputs.sha }}
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Create JUnit reports branch
id: create-branch
run: |
BRANCH=junit-reports-it-${{ github.sha }}-pagination
echo "Creating branch $BRANCH"
git switch --orphan $BRANCH
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
touch first.xml
git add *.xml
git commit -m "Initial commit for JUnit reports branch"
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
git push origin --set-upstream $BRANCH
git switch ${{ github.ref_name }}
- name: Checkout JUnit reports
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-${{ github.sha }}-pagination
path: junit-reports
artifact-name: junit-reports-sha-pagination
checkout-junit-reports-pagination-filler:
name: Checkout JUnit reports with paginated artifacts (filler ${{ matrix.index }})
runs-on: ubuntu-latest
needs:
- checkout-junit-reports-pagination-setup
strategy:
matrix:
index: [ 0, 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 ]
steps:
- name: Create filler file
run: echo "${{ matrix.index }}" > filler.txt
- name: Upload filler artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: pagination-filler-${{ matrix.index }}
path: filler.txt
checkout-junit-reports-pagination:
name: Checkout JUnit reports with paginated artifacts
runs-on: ubuntu-latest
needs:
- checkout-junit-reports-pagination-setup
- checkout-junit-reports-pagination-filler
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Assert JUnit reports SHA artifact is not on the first page
env:
GH_TOKEN: ${{ github.token }}
run: |
INDEX=$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts" \
--jq '[.artifacts[].name] | index("junit-reports-sha-pagination")')
if [[ "$INDEX" != "null" ]]; then
echo "Error: The JUnit reports SHA artifact is on the first page of the artifact list (index $INDEX)!"
exit 1
fi
- name: Update JUnit reports branch
run: |
git fetch --quiet origin junit-reports-it-${{ github.sha }}-pagination
git switch --quiet --detach FETCH_HEAD
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
touch second.xml
git add *.xml
git commit -m "Second commit for JUnit reports branch"
git push origin HEAD:junit-reports-it-${{ github.sha }}-pagination
git switch --quiet ${{ github.ref_name }}
- name: Checkout JUnit reports
uses: ./checkout-junit-reports
with:
split-index: 1
git-branch: junit-reports-it-${{ github.sha }}-pagination
path: junit-reports
artifact-name: junit-reports-sha-pagination
- name: Assert JUnit reports
working-directory: junit-reports
run: |
SHA=$(git rev-parse HEAD)
if [[ "$SHA" != "${{ needs.checkout-junit-reports-pagination-setup.outputs.expected-junit-reports-sha }}" ]]; then
echo "Error: Checked out $SHA instead of the saved JUnit reports SHA ${{ needs.checkout-junit-reports-pagination-setup.outputs.expected-junit-reports-sha }}!"
ls -l
exit 1
fi
- name: Clean up JUnit reports branch
if: always()
run: |
git push origin --delete junit-reports-it-${{ github.sha }}-pagination || true
- name: Clean up artifacts
if: always()
uses: geekyeggo/delete-artifact@176a747ab7e287e3ff4787bf8a148716375ca118 # v6
with:
name: |
junit-reports-sha-pagination
pagination-filler-*
failOnError: false
generate-split-index-json:
name: Generate split indexes
runs-on: ubuntu-latest
needs:
- checkout-junit-reports-with-nonexistent-branch
outputs:
json: ${{ steps.generate.outputs.split-index-json }}
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Generate split index list
id: generate
uses: ./generate-split-index-json
with:
split-total: ${{ env.split-total }}
integration-test:
name: "Test #${{ matrix.split-index }}"
runs-on: ubuntu-latest
needs:
- generate-split-index-json
permissions:
contents: read
checks: write
strategy:
fail-fast: false
matrix:
split-index: ${{ fromjson(needs.generate-split-index-json.outputs.json) }}
env:
DOWNLOAD_JAR: false
JAR_PATH: split-tests-java/build/libs/split-tests-java.jar
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Checkout split-tests-java
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: Donnerbart/split-tests-java
path: split-tests-java
- name: Set up JDK 21
uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6
with:
distribution: temurin
java-version: 25
- name: Set up Gradle
uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6
- name: Compile split-tests-java
working-directory: split-tests-java
run: ./gradlew shadowJar
- name: Split tests
id: split-tests
uses: ./
with:
split-index: ${{ matrix.split-index }}
split-total: ${{ env.split-total }}
glob: '**/integration-test/tests/*Test.java'
exclude-glob: '**/NoClassNameTest.java'
junit-glob: '**/integration-test/reports/*.xml'
format: 'list'
new-test-time: 'average'
calculate-optimal-total-split: true
debug: true
- name: Assert split tests
env:
SPLIT_INDEX: ${{ matrix.split-index }}
ACTUAL: ${{ steps.split-tests.outputs.test-suite }}
run: |
case "$SPLIT_INDEX" in
"0")
EXPECTED="de.donnerbart.example.SlowestTest"
;;
"1")
EXPECTED="NoPackageTest de.donnerbart.example.ThirdPartyLibraryTest"
;;
"2")
EXPECTED="de.donnerbart.example.NoTimingOneTest de.donnerbart.example.WhitespaceClassDefinitionTest"
;;
"3")
EXPECTED="de.donnerbart.example.NoTimingTwoTest de.donnerbart.example.SlowTest de.donnerbart.example.FastTest"
;;
*)
echo "Unexpected split index"
exit 1
;;
esac
echo "Expected: $EXPECTED"
echo "Actual: $ACTUAL"
if [ "$ACTUAL" != "$EXPECTED" ]; then
echo "The split tests are not matching"
exit 1
fi
- name: Create simulated JUnit report
run: |
mkdir -p build/reports/test-results
CLASS="de.donnerbart.example.ActionSplit${{ matrix.split-index }}Test"
FILE="build/reports/test-results/TEST-$CLASS.xml"
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $FILE
echo "<testsuite name=\"$CLASS\" tests=\"1\" skipped=\"0\" failures=\"0\" errors=\"0\" timestamp=\"1970-01-01T00:00:00\" hostname=\"foobar\" time=\"23.42\">" >> $FILE
echo " <properties/>" >> $FILE
echo " <testcase name=\"testMethod()\" classname=\"$CLASS\" time=\"23.42\">" >> $FILE
echo " <system-out><![CDATA[00:00:00.000 [Test] INFO Test log for split ${{ matrix.split-index }}" >> $FILE
echo "00:00:00.001 [Test] INFO Done" >> $FILE
echo "]]></system-out>" >> $FILE
echo " <system-err><![CDATA[]]></system-err>" >> $FILE
echo " </testcase>" >> $FILE
echo "</testsuite>" >> $FILE
- name: Upload JUnit report artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: junit-xml-reports-${{ matrix.split-index }}
path: build/reports/test-results/*.xml
merge-junit-reports-with-existing-branch:
name: Merge JUnit reports with existing branch
runs-on: ubuntu-latest
needs:
- integration-test
permissions:
contents: write
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Create JUnit reports branch
run: |
BRANCH=junit-reports-it-${{ github.sha }}-existing
echo "Creating branch $BRANCH"
git switch --orphan $BRANCH
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git commit --allow-empty -m "Initial commit for JUnit reports branch"
git push origin --set-upstream $BRANCH
git switch ${{ github.ref_name }}
- name: Merge JUnit reports
uses: ./merge-junit-reports
with:
git-branch: junit-reports-it-${{ github.sha }}-existing
artifact-name: junit-xml-report-existing
split-artifact-pattern: junit-xml-reports-*
split-artifact-delete-merged: false
- name: Checkout JUnit reports
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: junit-reports-assertion
ref: junit-reports-it-${{ github.sha }}-existing
- name: Assert JUnit reports
working-directory: junit-reports-assertion
run: |
for SPLIT_INDEX in {0..3}; do
REPORT_FILE="TEST-de.donnerbart.example.ActionSplit${SPLIT_INDEX}Test.xml"
SEARCH_STRING='name="de.donnerbart.example.ActionSplit'${SPLIT_INDEX}'Test"'
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
if ! grep -q "$SEARCH_STRING" "$REPORT_FILE"; then
echo "Error: JUnit report $REPORT_FILE does not contain the required string '$SEARCH_STRING'!"
cat $REPORT_FILE
exit 1
fi
echo "JUnit report $REPORT_FILE is valid"
done
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 4 ]]; then
echo "Error: Expected 4 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
- name: Clean up JUnit reports branch
if: always()
run: |
git push origin --delete junit-reports-it-${{ github.sha }}-existing || true
merge-junit-reports-with-concurrent-push:
name: Merge JUnit reports with concurrent push
runs-on: ubuntu-latest
needs:
- integration-test
permissions:
contents: write
env:
BRANCH: junit-reports-it-${{ github.sha }}-concurrent
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Create JUnit reports branch
run: |
echo "Creating branch $BRANCH"
git switch --orphan $BRANCH
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git commit --allow-empty -m "Initial commit for JUnit reports branch"
git push origin --set-upstream $BRANCH
git switch ${{ github.ref_name }}
- name: Checkout JUnit reports for concurrent push
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: junit-reports-concurrent
ref: ${{ env.BRANCH }}
- name: Prepare concurrent commit
working-directory: junit-reports-concurrent
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
echo '<testsuite name="de.donnerbart.example.ConcurrentTest"/>' > TEST-de.donnerbart.example.ConcurrentTest.xml
git add TEST-de.donnerbart.example.ConcurrentTest.xml
git commit -m "Concurrent JUnit reports update"
echo "concurrent-sha=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
- name: Install pre-push hook that pushes the concurrent commit first
run: |
HOOKS_DIR="$RUNNER_TEMP/git-hooks"
mkdir -p "$HOOKS_DIR"
cat > "$HOOKS_DIR/pre-push" <<'HOOK'
#!/usr/bin/env bash
MARKER="$RUNNER_TEMP/concurrent-push-done"
if [[ -f "$MARKER" ]]; then
exit 0
fi
touch "$MARKER"
env -u GIT_DIR -u GIT_WORK_TREE -u GIT_INDEX_FILE \
git -C "$GITHUB_WORKSPACE/junit-reports-concurrent" push --quiet origin HEAD:$BRANCH
HOOK
chmod +x "$HOOKS_DIR/pre-push"
git config --global core.hooksPath "$HOOKS_DIR"
- name: Merge JUnit reports
uses: ./merge-junit-reports
with:
git-branch: ${{ env.BRANCH }}
artifact-name: junit-xml-report-concurrent
split-artifact-pattern: junit-xml-reports-*
split-artifact-delete-merged: false
- name: Remove pre-push hook
if: always()
run: git config --global --unset core.hooksPath || true
- name: Checkout JUnit reports
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: junit-reports-assertion
ref: ${{ env.BRANCH }}
fetch-depth: 0
- name: Assert JUnit reports
working-directory: junit-reports-assertion
run: |
if [[ ! -f "$RUNNER_TEMP/concurrent-push-done" ]]; then
echo "Error: The pre-push hook did not push the concurrent commit!"
exit 1
fi
if ! git merge-base --is-ancestor ${{ env.concurrent-sha }} HEAD; then
echo "Error: The concurrent commit ${{ env.concurrent-sha }} is not part of $BRANCH!"
git log --oneline
exit 1
fi
for SPLIT_INDEX in {0..3}; do
REPORT_FILE="TEST-de.donnerbart.example.ActionSplit${SPLIT_INDEX}Test.xml"
SEARCH_STRING='name="de.donnerbart.example.ActionSplit'${SPLIT_INDEX}'Test"'
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
if ! grep -q "$SEARCH_STRING" "$REPORT_FILE"; then
echo "Error: JUnit report $REPORT_FILE does not contain the required string '$SEARCH_STRING'!"
cat $REPORT_FILE
exit 1
fi
echo "JUnit report $REPORT_FILE is valid"
done
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 4 ]]; then
echo "Error: Expected 4 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
- name: Clean up JUnit reports branch
if: always()
run: |
git push origin --delete $BRANCH || true
merge-junit-reports-with-invalid-reports:
name: Merge JUnit reports with invalid reports
runs-on: ubuntu-latest
permissions:
contents: write
env:
BRANCH: junit-reports-it-${{ github.sha }}-invalid
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Create JUnit reports branch
run: |
echo "Creating branch $BRANCH"
git switch --orphan $BRANCH
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
echo '<testsuite name="de.donnerbart.example.MalformedTest" time="1.0"/>' > TEST-de.donnerbart.example.MalformedTest.xml
git add *.xml
git commit -m "Initial commit for JUnit reports branch"
git push origin --set-upstream $BRANCH
git switch ${{ github.ref_name }}
- name: Create JUnit reports
run: |
mkdir -p split-0 split-1
echo '<testsuite name="de.donnerbart.example.DuplicateTest" time="2.0"/>' > split-0/TEST-de.donnerbart.example.DuplicateTest.xml
echo '<testsuite name="de.donnerbart.example.MalformedTest" time="3.0"><testcase name="test"></testsuite>' > split-0/TEST-de.donnerbart.example.MalformedTest.xml
echo '<testsuite name="de.donnerbart.example.DuplicateTest" time="2.0"/>' > split-1/TEST-de.donnerbart.example.DuplicateTest.xml
- name: Upload JUnit report artifact (split 0)
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: junit-xml-invalid-0
path: split-0/*.xml
- name: Upload JUnit report artifact (split 1)
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: junit-xml-invalid-1
path: split-1/*.xml
- name: Merge JUnit reports
uses: ./merge-junit-reports
with:
git-branch: ${{ env.BRANCH }}
artifact-name: junit-xml-report-invalid
split-artifact-pattern: junit-xml-invalid-*
- name: Checkout JUnit reports
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: junit-reports-assertion
ref: ${{ env.BRANCH }}
- name: Assert JUnit reports
working-directory: junit-reports-assertion
run: |
if ! grep -q 'name="de.donnerbart.example.DuplicateTest"' TEST-de.donnerbart.example.DuplicateTest.xml; then
echo "Error: JUnit report TEST-de.donnerbart.example.DuplicateTest.xml is missing or invalid!"
ls -l
exit 1
fi
if ! grep -q 'time="1.0"' TEST-de.donnerbart.example.MalformedTest.xml; then
echo "Error: The previous version of JUnit report TEST-de.donnerbart.example.MalformedTest.xml was not kept!"
cat TEST-de.donnerbart.example.MalformedTest.xml
exit 1
fi
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 2 ]]; then
echo "Error: Expected 2 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
- name: Clean up JUnit reports branch
if: always()
run: |
git push origin --delete $BRANCH || true
merge-junit-reports-with-new-branch:
name: Merge JUnit reports with new branch
runs-on: ubuntu-latest
needs:
- merge-junit-reports-with-existing-branch
- merge-junit-reports-with-concurrent-push
permissions:
contents: write
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Merge JUnit reports
uses: ./merge-junit-reports
with:
git-branch: junit-reports-it-${{ github.sha }}-new
artifact-name: junit-xml-report-new
split-artifact-pattern: junit-xml-reports-*
- name: Checkout JUnit reports
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: junit-reports-assertion
ref: junit-reports-it-${{ github.sha }}-new
- name: Assert JUnit reports
working-directory: junit-reports-assertion
run: |
for SPLIT_INDEX in {0..3}; do
REPORT_FILE="TEST-de.donnerbart.example.ActionSplit${SPLIT_INDEX}Test.xml"
SEARCH_STRING='name="de.donnerbart.example.ActionSplit'${SPLIT_INDEX}'Test"'
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
if ! grep -q "$SEARCH_STRING" "$REPORT_FILE"; then
echo "Error: JUnit report $REPORT_FILE does not contain the required string '$SEARCH_STRING'!"
cat $REPORT_FILE
exit 1
fi
echo "JUnit report $REPORT_FILE is valid"
done
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 4 ]]; then
echo "Error: Expected 4 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
- name: Download JUnit reports artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: junit-xml-report-new
path: junit-reports-artifact-assertion
- name: Assert JUnit reports artifact
working-directory: junit-reports-artifact-assertion
run: |
for SPLIT_INDEX in {0..3}; do
REPORT_FILE="TEST-de.donnerbart.example.ActionSplit${SPLIT_INDEX}Test.xml"
SEARCH_STRING='name="de.donnerbart.example.ActionSplit'${SPLIT_INDEX}'Test"'
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
if ! grep -q "$SEARCH_STRING" "$REPORT_FILE"; then
echo "Error: JUnit report $REPORT_FILE does not contain the required string '$SEARCH_STRING'!"
cat $REPORT_FILE
exit 1
fi
echo "JUnit report $REPORT_FILE is valid"
done
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 4 ]]; then
echo "Error: Expected 4 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
- name: Clean up JUnit reports branch
if: always()
run: |
git push origin --delete junit-reports-it-${{ github.sha }}-new || true