-
Notifications
You must be signed in to change notification settings - Fork 11
205 lines (175 loc) · 6.49 KB
/
on-pr-changed.yml
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
name: on-pr-changed
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
permissions:
contents: read
pull-requests: read # needed for label-based CI configuration
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
configure:
runs-on: ubuntu-22.04
outputs:
profile: ${{ steps.set-validation-profile.outputs.profile }}
ignored: ${{ steps.set-validation-profile.outputs.ignored }}
defaults:
run:
shell: bash
steps:
- id: set-validation-profile
name: Set Validation Profile
run: |
#!/usr/bin/env bash
profile() {
# compute the CI profile based on PR state and labels
local result=none
local is_draft=${{ github.event.pull_request.draft }}
local label_none=${{ contains(github.event.pull_request.labels.*.name, 'ci:none') }}
local label_fast=${{ contains(github.event.pull_request.labels.*.name, 'ci:fast') }}
local label_full=${{ contains(github.event.pull_request.labels.*.name, 'ci:full') }}
while [[ $# -gt 0 ]]
do
case $1 in
+ci:none) label_none=true;;
+ci:fast) label_fast=true;;
+ci:full) label_full=true;;
-ci:none) label_none=false;;
-ci:fast) label_fast=false;;
-ci:full) label_full=false;;
+draft) is_draft=true;;
-draft) is_draft=false;;
esac
shift
done
# set default profile
result=none
[[ ${is_draft} == true ]] && result=fast
[[ ${is_draft} == false ]] && result=full
# override profile based on PR labels
[[ ${label_none} == true ]] && result=none
[[ ${label_fast} == true ]] && result=fast
[[ ${label_full} == true ]] && result=full
printf '%s\n' "${result}"
}
# compute previous profile to see if re-run is needed
PREVIOUS=none
case '${{ github.event.action }}' in
ready_for_review)
PREVIOUS="$(profile +draft)"
;;
labeled)
case '${{ github.event.label.name }}' in
ci:full) PREVIOUS=$(profile -ci:full);;
ci:fast) PREVIOUS=$(profile -ci:fast);;
ci:none) PREVIOUS=$(profile -ci:none);;
esac
;;
unlabeled)
case '${{ github.event.label.name }}' in
ci:full) PREVIOUS=$(profile +ci:full);;
ci:fast) PREVIOUS=$(profile +ci:fast);;
ci:none) PREVIOUS=$(profile +ci:none);;
esac
;;
esac
IGNORE_TRIGGER=false
case "$(profile)" in
full) [[ ${PREVIOUS} =~ ^(full)$ ]] && IGNORE_TRIGGER=true;;
fast) [[ ${PREVIOUS} =~ ^(fast|full)$ ]] && IGNORE_TRIGGER=true;;
none) [[ ${PREVIOUS} =~ ^(none|fast|full)$ ]] && IGNORE_TRIGGER=true;;
esac
printf 'ignored=%s\n' "${IGNORE_TRIGGER}" >> "${GITHUB_OUTPUT}"
printf 'profile=%s\n' "$(profile)" >> "${GITHUB_OUTPUT}"
- id: print-configuration
name: Display Selected Profile
run: |
#!/usr/bin/env bash
printf 'Finished configuration job:\n'
printf ' - selected validation profile: %s\n' '${{ steps.set-validation-profile.outputs.profile }}'
printf ' - could skip validation rerun: %s\n' '${{ steps.set-validation-profile.outputs.ignored }}'
printf ' - triggering event (full):\n'
cat "${GITHUB_EVENT_PATH}"
validation:
needs: [configure]
uses: ./.github/workflows/run-validation.yml
with:
profile: ${{ needs.configure.outputs.profile }}
docs:
needs: [configure]
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
env:
RUSTDOCFLAGS: -Dwarnings
steps:
- uses: actions/checkout@v4
- name: setup
uses: ./.github/actions/setup
- name: build API documentation
run: just api-docs
- name: build website
run: just website-pkg
benchmark:
needs: [configure]
uses: ./.github/workflows/run-benchmarks.yml
if: ${{ needs.configure.outputs.profile == 'full' }}
can-merge:
needs: [configure, docs, validation, benchmark]
name: PR is ready for a merge
runs-on: ubuntu-22.04
if: ${{ needs.configure.outputs.profile == 'full' }}
defaults:
run:
shell: bash
steps:
- name: validation profile is `full`
run: |
#!/usr/bin/env bash
printf 'validation profile: %s\n' '${{ needs.configure.outputs.profile }}'
if [[ '${{ needs.configure.outputs.profile }}' != full ]]; then
printf 'failure: full validation needed (try adding the PR label "ci:full" or mark the PR ready for review)\n'
exit 1
fi
if: always()
- name: validation was successful
run: |
#!/usr/bin/env bash
printf 'validation status: %s\n' '${{ needs.validation.result }}'
if [[ '${{ needs.validation.result }}' == skipped ]]; then
printf 'failure: validation job was skipped'
exit 1
fi
if [[ '${{ needs.validation.result }}' != success ]]; then
printf 'failure: validation job failed'
exit 1
fi
if: always()
- name: docs built successfully
run: |
#!/usr/bin/env bash
printf 'docs status: %s\n' '${{ needs.docs.result }}'
if [[ '${{ needs.docs.result }}' == skipped ]]; then
printf 'failure: docs build was skipped'
exit 1
fi
if [[ '${{ needs.docs.result }}' != success ]]; then
printf 'failure: error while building docs'
exit 1
fi
if: always()
- name: ran benchmark
run: |
#!/usr/bin/env bash
printf 'benchmark status: %s\n' '${{ needs.benchmark.result }}'
if [[ '${{ needs.benchmark.result }}' == skipped ]]; then
printf 'failure: benchmark was skipped'
exit 1
fi
if [[ '${{ needs.benchmark.result }}' != success ]]; then
printf 'failure: error while running benchmark'
exit 1
fi
if: always()