Skip to content

Commit 60a7071

Browse files
committed
gh-actions/envoy/ci/report: Add action
Signed-off-by: Ryan Northey <[email protected]>
1 parent 3c877f5 commit 60a7071

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
inputs:
2+
current:
3+
type: string
4+
issue-author:
5+
type: string
6+
default: "app/ci-envoy"
7+
issue-body:
8+
type: string
9+
default: Tracking issue for CI failures.
10+
issue-label:
11+
type: string
12+
default: "ci:failures"
13+
output:
14+
type: string
15+
required: true
16+
print-report:
17+
type: boolean
18+
default: false
19+
previous:
20+
type: string
21+
repo:
22+
type: string
23+
required: true
24+
default: ${{ github.repository }}
25+
report-cmd:
26+
type: string
27+
default: >-
28+
bazel run
29+
--config=ci
30+
//tools/ci:report
31+
--
32+
status:
33+
type: string
34+
template-issue-title:
35+
type: string
36+
default: >-
37+
CI failures \($monday | strflocaltime("%Y.%m.%d"))-\($sunday | strflocaltime("%Y.%m.%d"))
38+
template-request:
39+
type: string
40+
default: |
41+
##### [\($request.event)@\($requestDate)](\($requestURL))
42+
43+
\($workflowList)
44+
template-report:
45+
type: string
46+
default: |
47+
### [\($branch)@\($commit | .[0:7])](\($commitURL))
48+
49+
\($commitMessage)
50+
51+
\($requestList)
52+
53+
template-workflow:
54+
type: string
55+
default: |
56+
- [\($workflow.name) (\($workflow.conclusion))](\($workflowURL))
57+
token:
58+
type: string
59+
required: true
60+
61+
outputs:
62+
id:
63+
value: ${{ steps.issue-id.outputs.value || steps.issue-created.outputs.id }}
64+
65+
66+
runs:
67+
using: composite
68+
steps:
69+
- run: |
70+
# Generate the report
71+
REPORT_ARGS=()
72+
if [[ -n "${{ inputs.current }}" ]]; then
73+
REPORT_ARGS+=("--current", "${{ inputs.current }}")
74+
elif [[ -n "${{ inputs.previous }}" ]]; then
75+
REPORT_ARGS+=("--previous" "${{ inputs.previous }}")
76+
else
77+
echo "::error::Current or previous must be set!" >&2
78+
exit 1
79+
fi
80+
read -ra REPORT_CMD <<< "${{ inputs.report-cmd }}"
81+
REPORT="$( \
82+
"${REPORT_CMD[@]}" \
83+
--repo ${{ github.repository }} \
84+
--status failure "${REPORT_ARGS[@]}")"
85+
echo "report=${REPORT}" >> $GITHUB_OUTPUT
86+
shell: bash
87+
env:
88+
GITHUB_TOKEN: ${{ inputs.token }}
89+
id: report
90+
- uses: envoyproxy/toolshed/gh-actions/[email protected]
91+
if: ${{ inputs.output == 'artifact' || inputs.print-report }}
92+
with:
93+
input: ${{ steps.report.outputs.report }}
94+
options: -C
95+
print-output: true
96+
output-path: ${{ inputs.output == 'artifact' && '/tmp/report.json' || '' }}
97+
- run: |
98+
# Create temp file
99+
FPATH=$(mktemp)
100+
echo "path=${FPATH}" > $GITHUB_OUTPUT
101+
shell: bash
102+
if: ${{ inputs.output == 'envoy-ci' }}
103+
id: output
104+
- uses: envoyproxy/toolshed/gh-actions/[email protected]
105+
id: report-output
106+
name: Generate markdown report
107+
if: ${{ inputs.output == 'envoy-ci' }}
108+
with:
109+
input: ${{ steps.report.outputs.report }}
110+
options: -r
111+
print-output: true
112+
output-path: ${{ steps.output.outputs.path }}
113+
filter: |
114+
[to_entries[]
115+
| .key as $commit
116+
| .value as $info
117+
| $info.head.message as $message
118+
| $info.head.target_branch as $branch
119+
| "https://github.com/${{ inputs.repo }}/commit/\($commit)" as $commitURL
120+
| ($message | split("\n")) as $lines
121+
| $lines[0] as $title
122+
| ($lines[1:] | join("\n") | gfm::blockquote) as $content
123+
| ({$title, $content} | gfm::collapse) as $commitMessage
124+
| [$info.requests
125+
| to_entries[]
126+
| .key as $requestId
127+
| .value as $request
128+
| "https://github.com/${{ inputs.repo }}/actions/runs/\($requestId)" as $requestURL
129+
| ($request.started | floor | todate) as $requestDate
130+
| [$request.workflows
131+
| to_entries[]
132+
| .key as $workflowId
133+
| .value as $workflow
134+
| "https://github.com/${{ inputs.repo }}/actions/runs/\($workflowId)" as $workflowURL
135+
| "${{ inputs.template-workflow }}"]
136+
| join("\n") as $workflowList
137+
| "${{ inputs.template-request }}"]
138+
| join("\n") as $requestList
139+
| "${{ inputs.template-report }}"]
140+
| join("\n")
141+
- uses: envoyproxy/toolshed/gh-actions/[email protected]
142+
id: issue-title
143+
if: ${{ inputs.output == 'envoy-ci' }}
144+
with:
145+
print-output: true
146+
options: -r
147+
filter: |
148+
now
149+
| (now - (strftime("%u") | tonumber - 1) * 86400) as $monday
150+
| ($monday + 6*86400) as $sunday
151+
| "${{ inputs.template-issue-title }}"
152+
- uses: envoyproxy/toolshed/gh-actions/github/issue/get@e8acc44644d9a65d65d27ab68564eb1185f7e92b
153+
id: issue
154+
if: ${{ inputs.output == 'envoy-ci' }}
155+
with:
156+
GITHUB_TOKEN: ${{ inputs.token }}
157+
author: ${{ inputs.issue-author }}
158+
title: ${{ steps.issue-title.outputs.value }}
159+
body: ${{ inputs.issue-body }}
160+
label: ${{ inputs.issue-label }}
161+
create: true
162+
- run: |
163+
# Add comment to issue
164+
gh issue comment ${{ steps.issue.outputs.id }} --body-file ${{ steps.output.outputs.path }}
165+
shell: bash
166+
if: ${{ steps.issue.outputs.id }}
167+
env:
168+
GH_TOKEN: ${{ inputs.token }}
169+
170+
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
171+
if: ${{ inputs.output == 'artifact' }}
172+
with:
173+
path: /tmp/report.json
174+
name: report

0 commit comments

Comments
 (0)