Skip to content

Create empty JUnit report branch if it doesn't exist #31

Create empty JUnit report branch if it doesn't exist

Create empty JUnit report branch if it doesn't exist #31

name: Integration tests
on:
push:
branches: ["**"]
concurrency:
group: integration-test-${{ github.ref }}
cancel-in-progress: true
env:
split-total: 4
jobs:
generate-split-index-json:
name: Generate split indexes
runs-on: ubuntu-latest
outputs:
json: ${{ steps.generate.outputs.split-index-json }}
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Checkout split-tests-java
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
repository: Donnerbart/split-tests-java
path: split-tests-java
- name: Set up JDK 21
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4
with:
distribution: temurin
java-version: 21
- name: Set up Gradle
uses: gradle/actions/setup-gradle@94baf225fe0a508e581a564467443d0e2379123b # v4
- 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@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
with:
name: junit-xml-reports-${{ matrix.split-index }}
path: build/reports/test-results/*.xml
merge-junit-reports:
name: Merge JUnit reports
runs-on: ubuntu-latest
needs:
- integration-test
permissions:
contents: write
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Merge JUnit reports
uses: ./merge-junit-reports
with:
git-branch: junit-reports-it-${{ github.sha }}
artifact-name: junit-xml-reports
split-artifact-pattern: junit-xml-reports-*
- name: Checkout JUnit reports
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
path: junit-reports-assertion
ref: junit-reports-it-${{ github.sha }}
- 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@cc203385981b70ca67e1cc392babf9cc229d5806 # v4
with:
name: junit-xml-reports
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: Cleanup JUnit reports branch
if: always()
run: |
git push origin --delete junit-reports-it-${{ github.sha }} || true