|
| 1 | +name: Merge JUnit reports |
| 2 | + |
| 3 | +description: Merges the JUnit reports from the test split jobs and saves them in a Git branch |
| 4 | +inputs: |
| 5 | + git-branch: |
| 6 | + description: The Git branch in this repository to store the JUnit reports in (string) |
| 7 | + required: true |
| 8 | + artifact-name: |
| 9 | + description: The artifact name for the merged JUnit reports of all test split jobs |
| 10 | + required: true |
| 11 | + split-artifact-pattern: |
| 12 | + description: The artifact name pattern used by the test split jobs, e.g. junit-xml-reports-* (string) |
| 13 | + required: true |
| 14 | + split-artifact-delete-merged: |
| 15 | + description: Configures if the artifacts of the test split jobs should be deleted after the merge (boolean) |
| 16 | + required: false |
| 17 | + default: true |
| 18 | + cleanup-junit-reports: |
| 19 | + description: Configures if the test output should be removed from the merged JUnit reports (boolean) |
| 20 | + required: false |
| 21 | + default: true |
| 22 | + delete-old-junit-reports: |
| 23 | + description: Configures if the old JUnit reports in the Git branch should be deleted (boolean) |
| 24 | + required: false |
| 25 | + default: true |
| 26 | +runs: |
| 27 | + using: composite |
| 28 | + steps: |
| 29 | + - name: Set up xmlstarlet |
| 30 | + run: sudo apt update && sudo apt install -y xmlstarlet |
| 31 | + |
| 32 | + - name: Checkout JUnit reports |
| 33 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 34 | + with: |
| 35 | + path: junit-reports |
| 36 | + ref: ${{ inputs.git-branch }} |
| 37 | + continue-on-error: true |
| 38 | + |
| 39 | + - name: Merge JUnit report artifacts |
| 40 | + uses: actions/upload-artifact/merge@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4 |
| 41 | + with: |
| 42 | + name: ${{ inputs.artifact-name }} |
| 43 | + pattern: ${{ inputs.split-artifact-pattern }} |
| 44 | + delete-merged: ${{ split-artifact-delete-merged }} |
| 45 | + |
| 46 | + - name: Download JUnit reports artifact |
| 47 | + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 |
| 48 | + with: |
| 49 | + name: ${{ inputs.artifact-name }} |
| 50 | + path: junit-reports-artifact |
| 51 | + |
| 52 | + - name: Clean up JUnit reports |
| 53 | + if: ${{ inputs.cleanup-junit-reports }} |
| 54 | + working-directory: junit-reports-artifact |
| 55 | + run: | |
| 56 | + echo -n "JUnit report size before cleanup: " |
| 57 | + du -sch *.xml | tail -n 1 | cut -f1 |
| 58 | + for REPORT in *.xml; do |
| 59 | + xmlstarlet ed -d '//system-out' -d '//system-err' "$REPORT" > tmp-report.xml && mv tmp-report.xml "$REPORT" |
| 60 | + done |
| 61 | + echo -n "JUnit report size after cleanup: " |
| 62 | + du -sch *.xml | tail -n 1 | cut -f1 |
| 63 | +
|
| 64 | + - name: Delete old JUnit reports |
| 65 | + if: ${{ inputs.delete-old-junit-reports }} |
| 66 | + working-directory: junit-reports |
| 67 | + run: git rm *.xml || true |
| 68 | + |
| 69 | + - name: Copy new JUnit reports |
| 70 | + run: cp junit-reports-artifact/*.xml junit-reports/ |
| 71 | + |
| 72 | + - name: Update JUnit reports |
| 73 | + uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9 |
| 74 | + with: |
| 75 | + message: 'Update JUnit reports' |
| 76 | + add: '*.xml' |
| 77 | + cwd: junit-reports |
| 78 | +branding: |
| 79 | + icon: archive |
| 80 | + color: blue |
0 commit comments