Repository navigation
163 lines (154 loc) · 6.66 KB
/
Copy pathjunit-report.yml
File metadata and controls
163 lines (154 loc) · 6.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: junit report
on:
workflow_run:
workflows: [master pull request ci]
types: [completed]
concurrency:
group: junit-report-${{ github.event.workflow_run.pull_requests[0].number || github.event.workflow_run.head_sha }}
cancel-in-progress: true
permissions:
actions: read
checks: write
contents: read
issues: write
pull-requests: write
jobs:
checks:
if: >
github.event.workflow_run.event == 'pull_request' &&
(github.event.workflow_run.conclusion == 'success' ||
github.event.workflow_run.conclusion == 'failure')
runs-on: ubuntu-24.04
steps:
- name: Set up JDK 17
uses: actions/setup-java@v6
with:
java-version: '17'
distribution: 'temurin'
- name: Download Test Report (Ubuntu JDK 17)
uses: dawidd6/action-download-artifact@v27
with:
name: junit-test-results-linux-jdk17
workflow: master-build.yml
run_id: ${{ github.event.workflow_run.id }}
path: ./junit-ubuntu-jdk17
if_no_artifact_found: ignore
- name: Verify JUnit XML layout
id: xml
run: |
set -euo pipefail
shopt -s globstar nullglob
root="./junit-ubuntu-jdk17"
if [ ! -d "$root" ]; then
echo "::notice::No JUnit artifact directory (tests may have been path-filtered). Skipping PR comment."
echo "has_xml=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# upload-artifact strips the common 'build/' prefix from the uploaded
# paths, so reports land as $root/test/... and $root/<plugin>/test/...
files=("$root"/**/TEST-*.xml)
if [ ${#files[@]} -eq 0 ] || [ ! -e "${files[0]}" ]; then
echo "::notice::No TEST-*.xml under $root/ (artifact missing, wrong layout, or download failed). Skipping PR comment."
find "$root" -maxdepth 5 -type d -print 2>/dev/null | head -80 || true
echo "has_xml=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Found ${#files[@]} JUnit report file(s) under $root/."
echo "has_xml=true" >> "$GITHUB_OUTPUT"
- name: Resolve PR number
if: steps.xml.outputs.has_xml == 'true'
id: pr
run: |
set -euo pipefail
REPO="${{ github.repository }}"
HEAD_SHA="${{ github.event.workflow_run.head_sha }}"
EVENT_PR="${{ github.event.workflow_run.pull_requests[0].number }}"
EVENT_PR_URL="${{ github.event.workflow_run.pull_requests[0].url }}"
PR_NUMBER=""
PR_SOURCE=""
# The producer records this during pull_request. It is required for
# fork PRs, where the workflow_run event and base-repo commit lookup
# do not contain the PR number.
if [ -f ./junit-ubuntu-jdk17/junit-pr-number ]; then
CANDIDATE=$(tr -d '[:space:]' < ./junit-ubuntu-jdk17/junit-pr-number)
if [[ "$CANDIDATE" =~ ^[0-9]+$ ]]; then
PR_NUMBER="$CANDIDATE"
PR_SOURCE="artifact"
else
echo "::notice::Ignoring non-numeric PR metadata from artifact: ${CANDIDATE}"
fi
fi
if [ -z "$PR_NUMBER" ] && [ -n "$EVENT_PR" ] && [ -n "$EVENT_PR_URL" ] && [[ "$EVENT_PR_URL" == *"/repos/${REPO}/pulls/"* ]]; then
PR_NUMBER="$EVENT_PR"
PR_SOURCE="workflow_run"
fi
if [ -z "$PR_NUMBER" ]; then
PR_NUMBER=$(gh api \
"repos/${REPO}/commits/${HEAD_SHA}/pulls" \
--jq "[.[] | select(.base.repo.full_name == \"${REPO}\")] | first | .number // empty")
if [ -n "$PR_NUMBER" ]; then
PR_SOURCE="commit"
fi
fi
if [ -z "$PR_NUMBER" ]; then
echo "::notice::No PR number found in artifact, workflow_run payload, or commit association. Publishing the check without a PR comment."
echo "number=" >> "$GITHUB_OUTPUT"
echo "has_pr=false" >> "$GITHUB_OUTPUT"
exit 0
fi
PR_JSON=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}")
PR_BASE=$(jq -r '.base.repo.full_name // empty' <<< "$PR_JSON")
PR_HEAD=$(jq -r '.head.sha // empty' <<< "$PR_JSON")
if [ "$PR_BASE" != "$REPO" ] || [ "$PR_HEAD" != "$HEAD_SHA" ]; then
echo "::notice::PR ${PR_NUMBER} from ${PR_SOURCE} failed validation (base='${PR_BASE}' head='${PR_HEAD}'). Publishing the check without a PR comment."
echo "number=" >> "$GITHUB_OUTPUT"
echo "has_pr=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "number=${PR_NUMBER}" >> "$GITHUB_OUTPUT"
echo "has_pr=true" >> "$GITHUB_OUTPUT"
echo "Resolved PR number='${PR_NUMBER}' source='${PR_SOURCE}' has_pr='true' repo='${REPO}' sha='${HEAD_SHA}'"
env:
GH_TOKEN: ${{ github.token }}
- name: Publish Test Report
if: steps.xml.outputs.has_xml == 'true'
uses: mikepenz/action-junit-report@v6
with:
report_paths: ./junit-ubuntu-jdk17/**/TEST-*.xml
check_name: JUnit Test Report
commit: ${{ github.event.workflow_run.head_sha }}
fail_on_failure: false
fail_on_parse_error: true
require_tests: true
require_passed_tests: true
include_passed: false
include_skipped: true
check_annotations: true
annotate_notice: true
job_summary: true
detailed_summary: true
flaky_summary: true
skip_success_summary: false
include_time_in_summary: true
group_suite: true
comment: ${{ steps.pr.outputs.has_pr == 'true' }}
updateComment: ${{ steps.pr.outputs.has_pr == 'true' }}
skip_comment_without_tests: true
job_name: tests
truncate_stack_traces: false
annotations_limit: 50
pr_id: ${{ steps.pr.outputs.number }}