|
16 | 16 | permissions: |
17 | 17 | contents: read |
18 | 18 | pull-requests: write |
| 19 | + actions: read |
19 | 20 |
|
20 | 21 | jobs: |
21 | 22 | comment: |
@@ -60,43 +61,87 @@ jobs: |
60 | 61 | - name: Compose comment body |
61 | 62 | if: steps.pr.outputs.pr-number != '' && (steps.download-editmode.outcome == 'success' || steps.download-playmode.outcome == 'success') |
62 | 63 | id: body |
| 64 | + env: |
| 65 | + GITHUB_TOKEN: ${{ github.token }} |
| 66 | + REPO: ${{ github.repository }} |
| 67 | + WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }} |
| 68 | + WORKFLOW_RUN_URL: ${{ github.event.workflow_run.html_url }} |
63 | 69 | run: | |
| 70 | + set -euo pipefail |
| 71 | +
|
| 72 | + # Job list of the originating "Unity Test" run, used to deep-link a |
| 73 | + # crashed/timed-out suite straight to its job page in the warning line. |
| 74 | + JOBS_JSON=$(gh api "/repos/$REPO/actions/runs/$WORKFLOW_RUN_ID/jobs" 2>/dev/null || echo '{"jobs":[]}') |
| 75 | +
|
| 76 | + declare -A DISPLAY=( [editmode]=EditMode [playmode]=PlayMode ) |
| 77 | +
|
| 78 | + status=passed # passed | failed | incomplete |
| 79 | + rows="" |
| 80 | + warnings="" |
| 81 | + failed_list="" |
| 82 | + total_failed=0 |
| 83 | +
|
| 84 | + for mode in editmode playmode; do |
| 85 | + file="failed-tests/$mode/failed-tests-$mode.json" |
| 86 | + [ -f "$file" ] || continue |
| 87 | + disp=${DISPLAY[$mode]} |
| 88 | +
|
| 89 | + # A suite that produced no result XML crashed or timed out before finishing. |
| 90 | + # Surface it as its own state instead of silently contributing 0 to a green total. |
| 91 | + if [ "$(jq -r '.hasResults' "$file")" != "true" ]; then |
| 92 | + status=incomplete |
| 93 | + job_url=$(jq -r --arg n "Test ($mode)" '.jobs[]? | select(.name==$n) | .html_url' <<< "$JOBS_JSON" | head -1) |
| 94 | + [ -n "$job_url" ] || job_url="$WORKFLOW_RUN_URL" |
| 95 | + rows="$rows| $disp | ⚠️ No results | — | — | — |"$'\n' |
| 96 | + warnings="$warnings⚠️ **$disp** produced no results — the run likely crashed or timed out before finishing. Check the [\`Unity Test / Test ($mode)\`]($job_url) job."$'\n\n' |
| 97 | + continue |
| 98 | + fi |
| 99 | +
|
| 100 | + # The artifact comes from the untrusted pull_request job - never let a |
| 101 | + # non-numeric value reach the arithmetic context. |
| 102 | + p=$(jq -r '.passed' "$file"); [[ "$p" =~ ^[0-9]+$ ]] || p=0 |
| 103 | + t=$(jq -r '.total' "$file"); [[ "$t" =~ ^[0-9]+$ ]] || t=0 |
| 104 | + f=$(jq -r '.failed | length' "$file") |
| 105 | + s=$((t - p - f)); if [ "$s" -lt 0 ]; then s=0; fi |
| 106 | +
|
| 107 | + if [ "$f" -gt 0 ]; then |
| 108 | + if [ "$status" = "passed" ]; then status=failed; fi |
| 109 | + total_failed=$((total_failed + f)) |
| 110 | + rows="$rows| $disp | ❌ $f failed | $p | $f | $s |"$'\n' |
| 111 | + names=$(jq -r --arg mode "$mode" '.failed[] | "- [\($mode)] \(. | gsub("[\r\n]"; " "))"' "$file") |
| 112 | + failed_list="$failed_list$names"$'\n' |
| 113 | + else |
| 114 | + rows="$rows| $disp | ✅ Passed | $p | 0 | $s |"$'\n' |
| 115 | + fi |
| 116 | + done |
| 117 | +
|
| 118 | + case "$status" in |
| 119 | + incomplete) badge="https://img.shields.io/badge/Tests-Incomplete-d29922?logo=codecov&logoColor=white&style=for-the-badge"; headline="$warnings" ;; |
| 120 | + failed) badge="https://img.shields.io/badge/Tests-Failed!-ff0000?logo=codecov&logoColor=white&style=for-the-badge"; headline="Some Unity tests failed ❌" ;; |
| 121 | + *) badge="https://img.shields.io/badge/Tests-Passed!-3fb950?logo=codecov&logoColor=white&style=for-the-badge"; headline="All Unity tests passed ✅" ;; |
| 122 | + esac |
| 123 | +
|
64 | 124 | DELIM="EOF_$(uuidgen)" |
65 | 125 | { |
66 | 126 | echo "body<<$DELIM" |
67 | 127 | echo "<!-- test-failures -->" |
68 | | -
|
69 | | - passed=0 |
70 | | - failed=0 |
71 | | - any_results=false |
72 | | - for mode in editmode playmode; do |
73 | | - file="failed-tests/$mode/failed-tests-$mode.json" |
74 | | - [ -f "$file" ] || continue |
75 | | - [ "$(jq -r '.hasResults' "$file")" = "true" ] && any_results=true |
76 | | - # The artifact comes from the untrusted pull_request job - never let a |
77 | | - # non-numeric value reach the arithmetic context. |
78 | | - p=$(jq -r '.passed' "$file"); [[ "$p" =~ ^[0-9]+$ ]] || p=0 |
79 | | - passed=$((passed + p)) |
80 | | - failed=$((failed + $(jq -r '.failed | length' "$file"))) |
81 | | - done |
82 | | -
|
83 | | - if [ "$any_results" = "false" ]; then |
84 | | - echo "**Test results not found** — the test run likely crashed or timed out before producing results; check the \`Unity Tests\` checks." |
85 | | - elif [ "$failed" -eq 0 ]; then |
86 | | - echo "**Tests: $passed passed, 0 failed** ✅" |
87 | | - else |
88 | | - echo "**Tests: $passed passed, $failed failed**" |
| 128 | + echo "![badge]" |
| 129 | + echo "" |
| 130 | + printf '%s\n' "$headline" |
| 131 | + echo "" |
| 132 | + echo "| TESTS SUITE | Result | Passed | Failed | Skipped |" |
| 133 | + echo "| ----------- | ------ | -----: | -----: | ------: |" |
| 134 | + printf '%s' "$rows" |
| 135 | + if [ "$total_failed" -gt 0 ]; then |
89 | 136 | echo "" |
90 | | - echo "<details><summary>Failed tests ($failed)</summary>" |
| 137 | + echo "<details><summary>Failed tests ($total_failed)</summary>" |
91 | 138 | echo "" |
92 | | - for mode in editmode playmode; do |
93 | | - file="failed-tests/$mode/failed-tests-$mode.json" |
94 | | - [ -f "$file" ] || continue |
95 | | - jq -r --arg mode "$mode" '.failed[] | "- [\($mode)] \(. | gsub("[\r\n]"; " "))"' "$file" |
96 | | - done |
| 139 | + printf '%s' "$failed_list" |
97 | 140 | echo "" |
98 | 141 | echo "</details>" |
99 | 142 | fi |
| 143 | + echo "" |
| 144 | + echo "[badge]: $badge" |
100 | 145 | echo "$DELIM" |
101 | 146 | } >> "$GITHUB_OUTPUT" |
102 | 147 |
|
|
0 commit comments