forked from elastic/cloudbeat
-
Notifications
You must be signed in to change notification settings - Fork 0
249 lines (212 loc) · 7.46 KB
/
Periodic-CI.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
243
244
245
246
247
248
249
name: Periodic-CI
on:
# On demand execution of workflow will run all suites.
workflow_dispatch:
inputs:
test-targets:
required: true
description: 'Specify test markers to run'
default: '[\"pre_merge\", \"file_system_rules\", \"k8s_object_rules\", \"process_api_server_rules\", \"process_controller_manager_rules\", \"process_etcd_rules\", \"process_kubelet_rules\", \"process_scheduler_rules\"]'
schedule:
# Nightly job. Running every day at 2 am
- cron: '00 02 * * 0-4'
# Weekly job running every saturday at 2 am
- cron: '00 02 * * 6'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GITHUB_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CONTAINER_SUFFIX: ${{ github.run_id }}
TEST_TARGETS_DEFAULT: '[\"pre_merge\", \"file_system_rules\", \"k8s_object_rules\", \"process_api_server_rules\", \"process_controller_manager_rules\", \"process_etcd_rules\", \"process_kubelet_rules\", \"process_scheduler_rules\"]'
permissions:
actions: read
checks: write
statuses: read
jobs:
Setup:
runs-on: ubuntu-20.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
timeout-minutes: 15
steps:
- id: Default
env:
TEST_TARGETS: ${{ env.TEST_TARGETS_DEFAULT }}
run: |
echo "TEST_MATRIX=$TEST_TARGETS" >> $GITHUB_ENV
- id: Nightly
if: github.event_name == 'schedule' && github.event.schedule == '00 02 * * 0-4'
env:
TEST_TARGETS: ${{ env.TEST_TARGETS_DEFAULT }}
run: echo "TEST_MATRIX=${TEST_TARGETS}" >> $GITHUB_ENV
- id: Weekly
if: github.event_name == 'schedule' && github.event.schedule == '00 02 * * 6'
env:
TEST_TARGETS: ${{ env.TEST_TARGETS_DEFAULT }}
run: echo "TEST_MATRIX=${TEST_TARGETS}" >> $GITHUB_ENV
- id: Push
if: github.event_name == 'push'
env:
TEST_TARGETS: '[\"pre_merge\", \"file_system_rules\"]'
run: |
echo "TEST_MATRIX=$TEST_TARGETS" >> $GITHUB_ENV
- id: Dispatch
if: github.event_name == 'workflow_dispatch'
env:
TEST_TARGETS: ${{ github.event.inputs.test-targets }}
run: echo "TEST_MATRIX=${TEST_TARGETS}" >> $GITHUB_ENV
- id: set-matrix
run: echo "{matrix}={${{ env.TEST_MATRIX}}}" >> $GITHUB_OUTPUT
Build:
name: Build
runs-on: ubuntu-20.04
timeout-minutes: 15
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: .go-version
- name: Fetch OPA version
run: echo "OPA_VERSION=$(go list -m -f {{.Version}} github.com/open-policy-agent/opa | sed 's/v//')" >> $GITHUB_ENV
- name: Setup OPA
uses: open-policy-agent/setup-opa@v2
with:
version: ${{ env.OPA_VERSION }}
- name: cache go dependencies
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: build cloudbeat
run: make
- name: build opa bundle
uses: magefile/mage-action@v2
with:
version: latest
args: BuildOpaBundle
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Build dependencies
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.workflow }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build cloudbeat-docker
uses: docker/build-push-action@v4
with:
context: .
push: false
tags: cloudbeat:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
outputs: type=docker,dest=/tmp/cloudbeat-${{ env.CONTAINER_SUFFIX }}.tar
- name: Build pytest-docker
uses: docker/build-push-action@v4
with:
context: ./tests/.
push: false
tags: cloudbeat-test:latest
cache-from: type=local,mode=max,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
outputs: type=docker,dest=/tmp/pytest-${{ env.CONTAINER_SUFFIX }}.tar
- name: Cache docker images
uses: actions/cache@v3
with:
path: /tmp/*.tar
key: ${{ runner.os }}-dockers-cache-${{ env.CONTAINER_SUFFIX }}
restore-keys: |
${{ runner.os }}-dockers-cache-${{ env.CONTAINER_SUFFIX }}
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
Test_Matrix:
needs: ['Build', 'Setup']
strategy:
fail-fast: false
matrix:
test-target: ${{fromJson(needs.Setup.outputs.matrix)}}
name: ${{ matrix.test-target }}-tests
runs-on: ubuntu-20.04
timeout-minutes: 90
steps:
- name: Check out the repo
uses: actions/checkout@v3
- uses: azure/setup-helm@v3
id: install
- uses: extractions/setup-just@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.5.0
with:
config: deploy/k8s/kind/kind-mono.yml
- name: Cache docker images
uses: actions/cache@v3
with:
path: /tmp/*.tar
key: ${{ runner.os }}-dockers-cache-${{ env.CONTAINER_SUFFIX }}
restore-keys: |
${{ runner.os }}-dockers-cache-
- name: Load images to kind
run: |
kind load image-archive /tmp/cloudbeat-${{ env.CONTAINER_SUFFIX }}.tar --name=kind-mono & kind load image-archive /tmp/pytest-${{ env.CONTAINER_SUFFIX }}.tar --name=kind-mono
- name: Deploy tests Helm chart
id: deploy_helm
run: |
just deploy-tests-helm-ci ${{ matrix.test-target }}
- name: Run Tests
id: run_tests
run: |
just run-tests-ci
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: allure_results-${{ matrix.test-target}}
path: tests/allure/results/
- name: clear cache
id: clear_cache
if: success()
run: rm -rf /tmp/${{ env.CONTAINER_SUFFIX }}}.tar
publish_results:
name: Publish Results
needs: Test_Matrix
if: always()
runs-on: ubuntu-20.04
steps:
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Extract Artifacts
run: |
mkdir -p tests/allure/results
find artifacts/ -type f -print0 | xargs -0 mv -t tests/allure/results
- name: Publish allure report
if: always()
uses: andrcuns/allure-publish-action@v2.2.3
with:
storageType: s3
resultsGlob: "tests/allure/results/*"
updatePr: actions
collapseSummary: false
summary: suites
summaryTableType: markdown
copyLatest: true
bucket: csp-allure-reports
prefix: allure_reports/cloudbeat/${{ github.ref_name }}
ignoreMissingResults: true
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: failure()
with:
limit-access-to-actor: true