-
Notifications
You must be signed in to change notification settings - Fork 5
209 lines (195 loc) · 8.03 KB
/
Copy pathpull-request-dashboard.yml
File metadata and controls
209 lines (195 loc) · 8.03 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Pull request dashboard
on:
schedule:
- cron: "0 * * * *" # hourly
workflow_dispatch:
inputs:
repository:
description: Target repository. Empty means all configured repositories.
required: false
type: string
pr_number:
description: Pull request number to refresh. Empty means backfill.
required: false
type: string
trigger_event:
description: Event that requested the refresh.
required: false
type: string
trigger_action:
description: Event action that requested the refresh.
required: false
type: string
trigger_review_id:
description: Pull request review id that requested the refresh.
required: false
type: string
permissions:
contents: read
env:
DASHBOARD_CONFIG: .github/scripts/pull-request-dashboard/repositories.json
jobs:
resolve-targets:
runs-on: ubuntu-latest
permissions:
contents: read
environment: protected
outputs:
matrix: ${{ steps.targets.outputs.matrix }}
pr_number: ${{ steps.trigger.outputs.pr_number }}
trigger_event: ${{ steps.trigger.outputs.event }}
trigger_action: ${{ steps.trigger.outputs.action }}
trigger_review_id: ${{ steps.trigger.outputs.review_id }}
dashboard_precondition_met: ${{ steps.dashboard-precondition.outputs.met }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Resolve trigger inputs
id: trigger
env:
EVENT_NAME: ${{ github.event_name }}
TARGET_REPOSITORY_FROM_INPUT: ${{ inputs.repository }}
PR_FROM_INPUT: ${{ inputs.pr_number }}
TRIGGER_EVENT_FROM_INPUT: ${{ inputs.trigger_event }}
TRIGGER_ACTION_FROM_INPUT: ${{ inputs.trigger_action }}
TRIGGER_REVIEW_ID_FROM_INPUT: ${{ inputs.trigger_review_id }}
run: |
set -euo pipefail
pr_number=""
trigger_event=""
trigger_action=""
trigger_review_id=""
case "$EVENT_NAME" in
schedule)
trigger_event="$EVENT_NAME"
;;
workflow_dispatch)
pr_number="$PR_FROM_INPUT"
trigger_event="${TRIGGER_EVENT_FROM_INPUT:-workflow_dispatch}"
trigger_action="$TRIGGER_ACTION_FROM_INPUT"
trigger_review_id="$TRIGGER_REVIEW_ID_FROM_INPUT"
;;
esac
if [[ -n "$pr_number" ]]; then
[[ "$pr_number" =~ ^[1-9][0-9]{0,6}$ ]] || { echo "bad PR number: $pr_number"; exit 1; }
[[ -n "$TARGET_REPOSITORY_FROM_INPUT" ]] || { echo "repository is required when pr_number is set"; exit 1; }
fi
if [[ -n "$trigger_event" ]]; then
[[ "$trigger_event" =~ ^(schedule|workflow_dispatch|check_suite|pull_request|issue_comment|pull_request_review|pull_request_review_comment|pull_request_review_thread)$ ]] \
|| { echo "bad trigger event: $trigger_event"; exit 1; }
fi
if [[ -n "$trigger_action" ]]; then
[[ "$trigger_action" =~ ^[a-z_]{1,32}$ ]] || { echo "bad trigger action: $trigger_action"; exit 1; }
fi
if [[ -n "$trigger_review_id" ]]; then
[[ "$trigger_review_id" =~ ^[1-9][0-9]{0,19}$ ]] || { echo "bad review id: $trigger_review_id"; exit 1; }
fi
{
echo "pr_number=$pr_number"
echo "event=$trigger_event"
echo "action=$trigger_action"
echo "review_id=$trigger_review_id"
} >> "$GITHUB_OUTPUT"
- name: Resolve target repositories
id: targets
env:
TARGET_REPOSITORY: ${{ inputs.repository }}
run: |
set -euo pipefail
matrix=$(jq -c --arg repo "$TARGET_REPOSITORY" '
if $repo == "" then
.
else
[ .[] | select(.name == $repo or ("open-telemetry/" + .name) == $repo) ]
end
' "$DASHBOARD_CONFIG")
if [[ "$matrix" == "[]" ]]; then
echo "no configured repository matched: ${TARGET_REPOSITORY:-<all>}" >&2
exit 1
fi
echo "matrix={\"include\":${matrix}}" >> "$GITHUB_OUTPUT"
echo "repository=$(jq -r '.[0].name' <<< "$matrix")" >> "$GITHUB_OUTPUT"
echo "$matrix" | jq .
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
if: steps.trigger.outputs.pr_number != ''
id: dashboard-token
with:
client-id: ${{ vars.PR_DASHBOARD_CLIENT_ID }}
private-key: ${{ secrets.PR_DASHBOARD_PRIVATE_KEY }}
owner: open-telemetry
repositories: ${{ steps.targets.outputs.repository }}
permission-issues: read
- name: Check dashboard precondition
id: dashboard-precondition
env:
GH_TOKEN: ${{ steps.dashboard-token.outputs.token }}
TRIGGER_PR_NUMBER: ${{ steps.trigger.outputs.pr_number }}
REPO: open-telemetry/${{ steps.targets.outputs.repository }}
run: |
set -euo pipefail
if [[ -z "$TRIGGER_PR_NUMBER" ]]; then
echo "met=true" >> "$GITHUB_OUTPUT"
exit 0
fi
dashboard_exists=$(python3 .github/scripts/pull-request-dashboard/publish_dashboard.py --repo "$REPO" --check-dashboard-exists)
if [[ "$dashboard_exists" == "true" ]]; then
echo "met=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if [[ "$dashboard_exists" == "false" ]]; then
echo "Dashboard issue does not exist yet; skipping targeted refresh."
echo "met=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "unexpected dashboard existence result: $dashboard_exists" >&2
exit 1
run-repo-dashboard:
needs: resolve-targets
if: needs.resolve-targets.outputs.dashboard_precondition_met == 'true'
permissions:
contents: write
strategy:
fail-fast: false
max-parallel: 1
matrix: ${{ fromJSON(needs.resolve-targets.outputs.matrix) }}
uses: ./.github/workflows/pull-request-dashboard-repo.yml
with:
repository: ${{ matrix.name }}
pr_number: ${{ needs.resolve-targets.outputs.pr_number }}
trigger_event: ${{ needs.resolve-targets.outputs.trigger_event }}
trigger_action: ${{ needs.resolve-targets.outputs.trigger_action }}
trigger_review_id: ${{ needs.resolve-targets.outputs.trigger_review_id }}
required_approvals: ${{ matrix.required_approvals || 1 }}
approver_teams_json: ${{ toJSON(matrix.approver_teams || fromJSON('[]')) }}
slack_channel: ${{ matrix.slack_channel }}
slack_user_mapping_json: ${{ toJSON(matrix.slack_user_mapping || fromJSON('{}')) }}
large_repo: ${{ matrix.large_repo || false }}
secrets:
PR_DASHBOARD_PRIVATE_KEY: ${{ secrets.PR_DASHBOARD_PRIVATE_KEY }}
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
notify-hourly-failure:
needs:
- resolve-targets
- run-repo-dashboard
# Notify for backfills: scheduled runs and unfiltered manual runs.
if: >-
always() &&
(
github.event_name == 'schedule' ||
(
github.event_name == 'workflow_dispatch' &&
inputs.repository == '' &&
inputs.pr_number == ''
)
)
permissions:
issues: write # needed to open/close the hourly failure tracking issue
uses: ./.github/workflows/workflow-failure-issue.yml
with:
# A superseded per-repo publish is cancelled (publish-dashboard uses
# cancel-in-progress: true), so count cancelled as success here to avoid
# opening noisy failure issues. Genuine failures still surface because
# matrix aggregation reports 'failure' in preference to 'cancelled'.
success: ${{ needs.resolve-targets.result == 'success' && (needs.run-repo-dashboard.result == 'success' || needs.run-repo-dashboard.result == 'cancelled') }}