From 2798e0247b8d1622a1d780592c4689a542dd92d9 Mon Sep 17 00:00:00 2001 From: David Sondermann Date: Sun, 9 Mar 2025 16:12:40 +0000 Subject: [PATCH 1/2] Add merging of JUnit reports to integration test --- .github/workflows/integration-test.yml | 107 +++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 0357b69..b0d1c53 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -108,3 +108,110 @@ jobs: 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 "" > $FILE + echo "" >> $FILE + echo " " >> $FILE + echo " " >> $FILE + echo " > $FILE + echo "00:00:00.001 [Test] INFO Done" >> $FILE + echo "]]>" >> $FILE + echo " " >> $FILE + echo " " >> $FILE + echo "" >> $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 diff --git a/README.md b/README.md index 9c34c91..d33850c 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ jobs: debug: true - name: Run integration tests - run: ./gradlew :integrationTest ${{ steps.split-tests.outputs.test-suite }} + run: ./gradlew :integrationTest ${{ steps.split-tests.outputs.test-suite }} - name: Upload JUnit report artifact uses: actions/upload-artifact@v4 From 5057ed38db3a048e26d8d0aea4f1facec2e0fb8f Mon Sep 17 00:00:00 2001 From: David Sondermann Date: Sun, 9 Mar 2025 16:37:50 +0000 Subject: [PATCH 2/2] Create empty JUnit report branch if it doesn't exist --- merge-junit-reports/action.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/merge-junit-reports/action.yml b/merge-junit-reports/action.yml index 3665de3..50abdfc 100644 --- a/merge-junit-reports/action.yml +++ b/merge-junit-reports/action.yml @@ -31,14 +31,30 @@ runs: steps: - name: Set up xmlstarlet shell: bash - run: sudo apt update && sudo apt install -y xmlstarlet + run: | + sudo apt update + sudo apt install -y xmlstarlet - - name: Checkout JUnit reports + - name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 with: path: junit-reports - ref: ${{ inputs.git-branch }} - continue-on-error: true + + - name: Create orphaned branch if checkout failed + shell: bash + working-directory: junit-reports + run: | + if git show-ref --verify --quiet refs/remotes/origin/${{ inputs.git-branch }}; then + echo "Switching to branch ${{ inputs.git-branch }}" + git switch ${{ inputs.git-branch }} + else + echo "Creating branch ${{ inputs.git-branch }}" + git switch --orphan ${{ inputs.git-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 ${{ inputs.git-branch }} + fi - name: Merge JUnit report artifacts uses: actions/upload-artifact/merge@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4