-
Notifications
You must be signed in to change notification settings - Fork 23
242 lines (216 loc) · 9.21 KB
/
pr-comment-trigger.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: Run Uptest
on:
workflow_call:
inputs:
trigger-keyword:
description: 'Keyword to trigger the workflow, defaults to /test-examples'
default: '/test-examples'
required: false
type: string
go-version:
description: 'Go version to use if building needs to be done'
default: '1.20'
required: false
type: string
package-type:
default: 'provider'
required: false
type: string
cleanup-disk:
description: "If set to true, an initial step will be run to reclaim some extra disk space for the uptest job in this workflow"
required: false
type: boolean
default: false
update-test-parameter:
description: 'Input parameter to use during update step. If this field
is empty, then the update step will be skipped.
The update parameter should be a serialized JSON object and if the JSON
object has nested children, then there must be only one leaf.
Example: {"tags":{"uptest":"update"}}
This parameter will add a tag to the test resource.'
default: ''
required: false
type: string
runs-on:
default: e2-standard-8
required: false
type: string
secrets:
UPTEST_CLOUD_CREDENTIALS:
description: 'Uptest cloud credentials to be passed to the uptest target as environment variable'
required: true
UPTEST_DATASOURCE:
description: 'A set of key-value pairs to be injected into the uptest'
required: false
jobs:
debug:
runs-on: ${{ inputs.runs-on }}
steps:
- name: Debug
run: |
echo "Trigger keyword: ${{ inputs.trigger-keyword }}"
echo "Go version: ${{ inputs.go-version }}"
echo "github.event.comment.author_association: ${{ github.event.comment.author_association }}"
get-example-list:
if: ${{ (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'CONTRIBUTOR' ) &&
github.event.issue.pull_request &&
contains(github.event.comment.body, inputs.trigger-keyword ) }}
runs-on: ${{ inputs.runs-on }}
outputs:
example_list: ${{ steps.get-example-list-name.outputs.example-list }}
example_hash: ${{ steps.get-example-list-name.outputs.example-hash }}
steps:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
submodules: true
- name: Checkout PR
id: checkout-pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr checkout ${{ github.event.issue.number }}
git submodule update --init --recursive
OUTPUT=$(git log -1 --format='%H')
echo "commit-sha=$OUTPUT" >> $GITHUB_OUTPUT
- name: Prepare The Example List
env:
COMMENT: ${{ github.event.comment.body }}
id: get-example-list-name
run: |
PATHS=$(echo $COMMENT | sed 's/^.*\${{ inputs.trigger-keyword }}="//g' | cut -d '"' -f 1 | sed 's/,/ /g')
EXAMPLE_LIST=""
for P in $PATHS; do EXAMPLE_LIST="${EXAMPLE_LIST},$(find $P -name '*.yaml' | tr '\n' ',')"; done
sudo apt-get -y install coreutils
COUNT=$(echo ${EXAMPLE_LIST:1} | grep -o ".yaml" | wc -l)
if [ $COUNT -gt 1 ]; then EXAMPLE_HASH=$(echo ${EXAMPLE_LIST} | md5sum | cut -f1 -d" "); else EXAMPLE_HASH=$(echo ${EXAMPLE_LIST:1} | sed 's/.$//'); fi
echo "Examples: ${EXAMPLE_LIST:1}"
echo "Example Hash: ${EXAMPLE_HASH}"
echo "example-list=${EXAMPLE_LIST:1}" >> $GITHUB_OUTPUT
echo "example-hash=${EXAMPLE_HASH}" >> $GITHUB_OUTPUT
- name: Create Pending Status Check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \
-f state='pending' \
-f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
-f description='Running...' \
-f context="Uptest-${{ steps.get-example-list-name.outputs.example-hash }}"
uptest:
if: ${{ (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'CONTRIBUTOR' ) &&
github.event.issue.pull_request &&
contains(github.event.comment.body, inputs.trigger-keyword ) }}
runs-on: ${{ inputs.runs-on }}
needs: get-example-list
steps:
- name: Cleanup Disk
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
if: ${{ inputs.cleanup-disk }}
with:
android: true
dotnet: true
haskell: true
tool-cache: true
large-packages: false
swap-storage: false
- name: Setup QEMU
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2
with:
platforms: all
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
submodules: true
- name: Setup Go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3
with:
go-version: ${{ inputs.go-version }}
- name: Checkout PR
id: checkout-pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr checkout ${{ github.event.issue.number }}
git submodule update --init --recursive
OUTPUT=$(git log -1 --format='%H')
echo "commit-sha=$OUTPUT" >> $GITHUB_OUTPUT
- name: Find Go Caches
if: ${{ inputs.package-type == 'provider' }}
id: go
run: |
echo "cache=$(make go.cachedir)" >> $GITHUB_OUTPUT
echo "modcache=$(make go.mod.cachedir)" >> $GITHUB_OUTPUT
- name: Cache the Go Build Cache
if: ${{ inputs.package-type == 'provider' }}
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
with:
path: ${{ steps.go.outputs.cache }}
key: ${{ runner.os }}-build-uptest-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-uptest-
- name: Cache the Go Dependencies
if: ${{ inputs.package-type == 'provider' }}
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
with:
path: ${{ steps.go.outputs.modcache }}
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-pkg-
- name: Vendor Dependencies
if: ${{ inputs.package-type == 'provider' }}
run: make vendor vendor.check
- name: Run Uptest
id: run-uptest
env:
UPTEST_CLOUD_CREDENTIALS: ${{ secrets.UPTEST_CLOUD_CREDENTIALS }}
UPTEST_EXAMPLE_LIST: ${{ needs.get-example-list.outputs.example_list }}
UPTEST_TEST_DIR: ./_output/controlplane-dump
UPTEST_DATASOURCE_PATH: .work/uptest-datasource.yaml
UPTEST_UPDATE_PARAMETER: ${{ inputs.update-test-parameter }}
run: |
mkdir -p .work && echo "${{ secrets.UPTEST_DATASOURCE }}" > .work/uptest-datasource.yaml
make e2e
- name: Create Successful Status Check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EXAMPLE_HASH: ${{ needs.get-example-list.outputs.example_hash }}
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \
-f state='success' \
-f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
-f description='Passed' \
-f context="Uptest-${EXAMPLE_HASH}"
- name: Collect Cluster Dump
if: always()
run: |
make controlplane.dump
- name: Upload Cluster Dump
if: always()
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
with:
name: controlplane-dump
path: ./_output/controlplane-dump
- name: Cleanup
if: always()
run: |
eval $(make --no-print-directory build.vars)
${KUBECTL} delete managed --all || true
- name: Create Unsuccessful Status Check
if: failure()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EXAMPLE_HASH: ${{ needs.get-example-list.outputs.example_hash }}
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \
-f state='failure' \
-f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
-f description='Failed' \
-f context="Uptest-${EXAMPLE_HASH}"