-
Notifications
You must be signed in to change notification settings - Fork 53
299 lines (291 loc) · 10.9 KB
/
build_and_test_x86.yaml
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
name: Build & test x86_64
on:
workflow_call:
inputs:
flavor:
required: true
type: string
concurrency:
group: ci-${{ inputs.flavor }}-x86_64-${{ github.head_ref || github.ref }}-${{ github.repository }}
cancel-in-progress: true
jobs:
permissions:
content: read
build-os:
permissions:
packages: write
runs-on: ubuntu-latest
env:
FLAVOR: ${{ inputs.flavor }}
ARCH: x86_64
TOOLKIT_REPO: ghcr.io/${{ github.repository }}/elemental-cli
REPO: ghcr.io/${{ github.repository }}/elemental-${{ inputs.flavor }}
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.head.sha }}"
- run: |
git fetch --prune --unshallow
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build OS
run: |
make pull-toolkit
make ARCH=${{ env.ARCH }} DOCKER_ARGS=--load build-os
make ARCH=${{ env.ARCH }} DOCKER_ARGS=--push build-os
build-iso:
needs:
- build-os
runs-on: ubuntu-latest
env:
FLAVOR: ${{ inputs.flavor }}
ARCH: x86_64
TOOLKIT_REPO: ghcr.io/${{github.repository}}/elemental-cli
REPO: ghcr.io/${{ github.repository }}/elemental-${{ inputs.flavor }}
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.head.sha }}"
- run: |
git fetch --prune --unshallow
- name: Cached ISO
id: cache-iso
uses: actions/cache/restore@v4
env:
cache-name: pr-iso-build-x86_64-${{ inputs.flavor }}
enableCrossOsArchive: true
lookup-only: true
with:
path: /tmp/*.iso
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }}
- if: ${{ steps.cache-iso.outputs.cache-hit != 'true' }}
name: Build ISO
run: |
make pull-toolkit pull-os
make build-iso
sudo mv build/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.iso /tmp/
- if: ${{ steps.cache-iso.outputs.cache-hit != 'true' }}
name: Save ISO
id: save-iso
uses: actions/cache/save@v4
env:
cache-name: pr-iso-build-x86_64-${{ inputs.flavor }}
with:
path: /tmp/*.iso
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }}
enableCrossOsArchive: true
build-disk:
needs:
- build-os
runs-on: ubuntu-latest
env:
FLAVOR: ${{ inputs.flavor }}
ARCH: x86_64
TOOLKIT_REPO: ghcr.io/${{github.repository}}/elemental-cli
REPO: ghcr.io/${{ github.repository }}/elemental-${{ inputs.flavor }}
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.head.sha }}"
- run: |
git fetch --prune --unshallow
- name: Checks cached Disk
uses: actions/cache/restore@v4
id: cache-check
env:
cache-name: pr-disk-build-x86_64-${{ inputs.flavor }}
with:
path: /tmp/*.qcow2
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }}
enableCrossOsArchive: true
lookup-only: true
- if: ${{ steps.cache-check.outputs.cache-hit != 'true' }}
name: Cleanup worker
run: |
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET
sudo df -h
- if: ${{ steps.cache-check.outputs.cache-hit != 'true' }}
name: Install to disk
run: |
sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-utils coreutils
make pull-toolkit pull-os
sudo -E make ARCH=${{ env.ARCH }} build-disk
sudo mv build/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.qcow2 /tmp/
- if: ${{ steps.cache-check.outputs.cache-hit != 'true' }}
name: Save cached disk
id: cache-disk
uses: actions/cache/save@v4
env:
cache-name: pr-disk-build-x86_64-${{ inputs.flavor }}
with:
path: /tmp/*.qcow2
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }}
enableCrossOsArchive: true
detect:
runs-on: ubuntu-latest
outputs:
tests: ${{ steps.detect.outputs.tests }}
upgrade: ${{ steps.image.outputs.upgrade }}
toolkit: ${{ steps.image.outputs.toolkit }}
steps:
- id: detect
env:
FLAVOR: ${{ inputs.flavor }}
run: |
if [ "${FLAVOR}" == green ]; then
echo "tests=['test-upgrade', 'test-downgrade', 'test-recovery', 'test-fallback', 'test-fsck', 'test-grubfallback']" >> $GITHUB_OUTPUT
else
echo "tests=['test-active']" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.head.sha }}"
- id: image
env:
FLAVOR: ${{ inputs.flavor }}
run: |
git fetch --prune --unshallow
export TAG=$(git describe --tags --candidates=50 --abbrev=0)
export COMMIT=$(git rev-parse --short HEAD)
export VERSION=${TAG}-g${COMMIT}
echo "upgrade=ghcr.io/rancher/elemental-toolkit/elemental-${FLAVOR}:${VERSION}" >> $GITHUB_OUTPUT
echo "toolkit=ghcr.io/rancher/elemental-toolkit/elemental-cli:${VERSION}" >> $GITHUB_OUTPUT
tests-matrix:
needs:
- build-disk
- detect
runs-on: ubuntu-latest
env:
FLAVOR: ${{ inputs.flavor }}
ARCH: x86_64
COS_TIMEOUT: 1600
UPGRADE_ARGS: --toolkit-image=${{ needs.detect.outputs.toolkit }} --upgrade-image=${{ needs.detect.outputs.upgrade }}
strategy:
matrix:
test: ${{ fromJson(needs.detect.outputs.tests) }}
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.head.sha }}"
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install deps
run: |
make test-deps
- run: |
git fetch --prune --unshallow
- if: ${{ matrix.test == 'test-upgrade' }}
name: Download specific disk
run: |
wget -q --tries=3 https://github.com/rancher/elemental-toolkit/releases/download/v1.1.4/elemental-${{ inputs.flavor }}-v1.1.4.${{ env.ARCH }}.qcow2 -O /tmp/elemental-${{ inputs.flavor }}.${{ env.ARCH }}.qcow2
- if: ${{ matrix.test != 'test-upgrade' }}
name: Cached Disk
id: cache-disk
uses: actions/cache/restore@v4
env:
cache-name: pr-disk-build-x86_64-${{ inputs.flavor }}
with:
path: /tmp/*.qcow2
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- name: Enable KVM group perms
run: |
sudo apt-get update
sudo apt-get install qemu qemu-utils ovmf qemu-system-x86
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run ${{ matrix.test }}
run: |
make DISK=/tmp/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.qcow2 ELMNTL_TARGETARCH=${{ env.ARCH }} ELMNTL_FIRMWARE=/usr/share/OVMF/OVMF_CODE.fd ${{ matrix.test }}
- name: Upload serial console for ${{ matrix.test }}
uses: actions/upload-artifact@v4
if: always()
with:
name: serial-${{ env.ARCH }}-${{ env.FLAVOR }}-${{ matrix.test }}.log
path: tests/serial.log
if-no-files-found: error
overwrite: true
- name: Upload qemu stdout for ${{ matrix.test }}
uses: actions/upload-artifact@v4
if: failure()
with:
name: vmstdout-${{ env.ARCH }}-${{ env.FLAVOR }}-${{ matrix.test }}.log
path: tests/vmstdout
if-no-files-found: error
overwrite: true
- name: Stop test VM
if: always()
run: |
make test-clean
test-installer:
needs:
- build-iso
- detect
runs-on: ubuntu-latest
env:
FLAVOR: ${{ inputs.flavor }}
ARCH: x86_64
COS_TIMEOUT: 1600
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.head.sha }}"
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install deps
run: |
make test-deps
- run: |
git fetch --prune --unshallow
- name: Cached ISO
id: cache-iso
uses: actions/cache/restore@v4
env:
cache-name: pr-iso-build-x86_64-${{ inputs.flavor }}
with:
path: /tmp/*.iso
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- name: Enable KVM group perms
run: |
sudo apt-get update
sudo apt-get install qemu qemu-utils ovmf qemu-system-x86
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run installer test
run: |
make ISO=/tmp/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.iso ELMNTL_TARGETARCH=${{ env.ARCH }} ELMNTL_FIRMWARE=/usr/share/OVMF/OVMF_CODE.fd test-installer
- name: Upload serial console for installer tests
uses: actions/upload-artifact@v4
if: always()
with:
name: serial-${{ env.ARCH }}-${{ env.FLAVOR }}-installer.log
path: tests/serial.log
if-no-files-found: error
overwrite: true
- name: Upload qemu stdout for installer tests
uses: actions/upload-artifact@v4
if: failure()
with:
name: vmstdout-${{ env.ARCH }}-${{ env.FLAVOR }}-installer.log
path: tests/vmstdout
if-no-files-found: error
overwrite: true
- name: Stop test VM
if: always()
run: |
make test-clean