diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index b0d1c53..ac3bdfa 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -131,8 +131,8 @@ jobs: name: junit-xml-reports-${{ matrix.split-index }} path: build/reports/test-results/*.xml - merge-junit-reports: - name: Merge JUnit reports + merge-junit-reports-with-existing-branch: + name: Merge JUnit reports with existing branch runs-on: ubuntu-latest needs: - integration-test @@ -142,18 +142,84 @@ jobs: - name: Checkout split-tests-java-action uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + 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: Cleanup JUnit reports branch + if: always() + run: | + git push origin --delete junit-reports-it-${{ github.sha }}-existing || 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 + 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 + 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 with: path: junit-reports-assertion - ref: junit-reports-it-${{ github.sha }} + ref: junit-reports-it-${{ github.sha }}-new - name: Assert JUnit reports working-directory: junit-reports-assertion @@ -183,7 +249,7 @@ jobs: - name: Download JUnit reports artifact uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4 with: - name: junit-xml-reports + name: junit-xml-report-new path: junit-reports-artifact-assertion - name: Assert JUnit reports artifact @@ -214,4 +280,4 @@ jobs: - name: Cleanup JUnit reports branch if: always() run: | - git push origin --delete junit-reports-it-${{ github.sha }} || true + git push origin --delete junit-reports-it-${{ github.sha }}-new || true diff --git a/merge-junit-reports/action.yml b/merge-junit-reports/action.yml index 943d6ba..83861c7 100644 --- a/merge-junit-reports/action.yml +++ b/merge-junit-reports/action.yml @@ -45,11 +45,11 @@ runs: working-directory: junit-reports run: | if git ls-remote --exit-code --heads origin ${{ inputs.git-branch }}; then - echo "Switching to branch ${{ inputs.git-branch }}" + echo "Switching to existing branch ${{ inputs.git-branch }}" git fetch --quiet git switch ${{ inputs.git-branch }} else - echo "Creating branch ${{ inputs.git-branch }}" + echo "Creating new 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"