-
Notifications
You must be signed in to change notification settings - Fork 650
226 lines (184 loc) · 8.41 KB
/
integration.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
name: Integration
on:
workflow_dispatch:
inputs:
snap-channel:
description: Snap Store channel
mac-x86-package:
description: macOS x86 package URL
mac-arm-package:
description: macOS ARM package URL
win-package:
description: Windows package URL
jobs:
GetMatrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Determine job matrix
id: set-matrix
run: |
set -euo pipefail
MATRIX=""
if [ -n '${{ github.event.inputs.snap-channel }}' ]; then
MATRIX+='{"os": "Linux", "vm": "linux", "driver": "qemu"}'
MATRIX+='{"os": "Linux", "vm": "linux", "driver": "lxd"}'
fi
if [ -n '${{ github.event.inputs.mac-x86-package }}' ]; then
MATRIX+='{"os": "macOS", "vm": "macos-11", "driver": "qemu", "arch": "x86_64" }'
MATRIX+='{"os": "macOS", "vm": "macos-12", "driver": "qemu", "arch": "x86_64" }'
fi
if [ -n '${{ github.event.inputs.mac-arm-package }}' ]; then
MATRIX+='{"os": "macOS", "driver": "qemu", "arch": "arm64" }'
fi
if [ -n '${{ github.event.inputs.win-package }}' ]; then
MATRIX+='{"os": "Windows", "vm": "windows-10", "driver": "hyperv"}'
MATRIX+='{"os": "Windows", "vm": "windows-11", "driver": "hyperv"}'
fi
echo "${MATRIX}" | jq -cs '{"include": . }' | awk '{ print "matrix=" $0 }' >> $GITHUB_OUTPUT
CI:
needs: GetMatrix
runs-on: testflinger
# Windows is pretty slow unfortunately.
timeout-minutes: 120
strategy:
matrix: ${{ fromJSON(needs.GetMatrix.outputs.matrix) }}
env:
TESTFLINGER_FILE: testflinger-${{ matrix.os }}-${{ matrix.driver }}.yaml
steps:
- name: Write the testflinger job
uses: DamianReeves/[email protected]
with:
path: ${{ env.TESTFLINGER_FILE }}
write-mode: overwrite
contents: |
job_queue: ${{ matrix.os == 'macOS' && matrix.arch == 'arm64' && 'macos-arm' || matrix.vm }}
output_timeout: 2400
provision_data:
${{ matrix.vm && format('vmx: /Users/cibot/Virtual Machines.localized/{0}.vmwarevm/{0}.vmx', matrix.vm) || '' }}
snapshot: Testflinger
${{ matrix.os == 'Linux' && 'image_url: https://cloud-images.ubuntu.com/releases/jammy/release/ubuntu-22.04-server-cloudimg-amd64.img' || '' }}
${{ matrix.vm == 'windows-10' && 'username: ieuser' || '' }}
${{ matrix.vm == 'windows-11' && 'username: user' || '' }}
vmx_config:
memsize: 4096
vhv.enable: true
vpmc.enable: true
test_data:
test_cmds: |
set -xeuo pipefail
MP=multipass
[ '${{ matrix.os }}' == 'macOS' ] && MP=/usr/local/bin/multipass
function _run() {{
ssh ${{ '${{SSH_OPTS}} "${{DEVICE_USER}}@${{DEVICE_IP}}" -- "${{@}}"' }}
}}
# Retry $1 times, with $2 seconds in between tries
function _retry() {{
tries=$1
interval=$2
shift 2
for try in $( seq $tries ); do
RC=0
${{ '"${{@}}"' }} || RC=$?
[ $RC -eq 0 -o $try -eq $tries ] && return $RC
sleep $interval;
done
}}
# Retry $1 times, with $2 seconds in between tries, until $3 greps
function _retry_grep() {{
tries=$1
interval=$2
pattern=$3
shift 3
for try in $( seq $tries ); do
RC=0
${{ '"${{@}}"' }} | grep --quiet -e "$pattern" || RC=$?
[ $RC -eq 0 -o $try -eq $tries ] && return $RC
sleep $interval;
done
}}
# Log journal entries on bad exit
function _exit() {{
RC=$?
if [ '${{ matrix.os }}' == 'Linux' ]; then
[ $RC -eq 0 ] || _run sudo journalctl -u snap.multipass*
elif [ '${{ matrix.os }}' == 'macOS' ]; then
[ $RC -eq 0 ] || _run sudo cat /Library/Logs/Multipass/multipassd.log
# Authenticate the root user
_run $MP set local.passphrase=foobar || true
# Sleep 20 seconds to allow daemon to restart
sleep 20
_run sudo $MP authenticate foobar || true
( echo y; echo y ) | _run sudo PATH=/bin:/usr/local/bin /bin/sh "/Library/Application\\ Support/com.canonical.multipass/uninstall.sh" || true
_run sudo rm -rf /Library/Logs/Multipass
fi
}}
trap _exit EXIT
function _ps() {{
_run powershell -noprofile -noninteractive -command ${{ '${{@}}' }}
}}
function _install() {{
PACKAGE="$1"
if [ '${{ matrix.os }}' == 'Linux' ]; then
# Give snapd time to settle
_retry 5 30 _run sudo sh -c "snap\ list\ multipass && sudo snap refresh multipass --channel ${PACKAGE} || sudo snap install multipass --channel ${PACKAGE}"
elif [ '${{ matrix.os }}' == 'macOS' ]; then
_run curl --location --output multipass.pkg "${PACKAGE}"
_run sudo installer -dumplog -target / -pkg multipass.pkg
elif [ '${{ matrix.os }}' == 'Windows' ]; then
_ps "(New-Object System.Net.WebClient).DownloadFile('${PACKAGE}', 'multipass-installer.exe')"
_run .\\multipass-installer.exe /S
fi
}}
if [ '${{ matrix.os }}' == 'Linux' ]; then
OVERRIDE_CONF="/etc/systemd/system/snap.multipass.multipassd.service.d/override.conf"
_run sudo mkdir -p $( dirname ${OVERRIDE_CONF} )
_run sudo tee ${OVERRIDE_CONF} <<EOF
[Service]
ExecStart=
ExecStart=/usr/bin/snap run multipass.multipassd --verbosity trace
EOF
_install ${{ github.event.inputs.snap-channel }}
elif [ '${{ matrix.os }}' == 'macOS' ]; then
( echo y; echo y ) | _run sudo PATH=/bin:/usr/local/bin /bin/sh "/Library/Application\\ Support/com.canonical.multipass/uninstall.sh" || true
_install ${{ matrix.arch == 'arm64' && github.event.inputs.mac-arm-package || github.event.inputs.mac-x86-package }}
elif [ '${{ matrix.os }}' == 'Windows' ]; then
_install ${{ github.event.inputs.win-package }}
if [ '${{ matrix.driver }}' == 'hyperv' ]; then
_ps "Set-Variable ProgressPreference SilentlyContinue; Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart"
_ps "Restart-Computer -Force"
sleep 120
fi
fi
if [ '${{ matrix.driver }}' == 'lxd' ]; then
_run sudo snap connect multipass:lxd lxd
_run sudo lxd init --auto
fi
_retry_grep 12 5 "multipassd" _run $MP version
_run $MP set local.driver=${{ matrix.driver }}
# Wait for the daemon to restart
_retry_grep 12 5 '^${{ matrix.driver }}' _run $MP get local.driver
# and for the streams to flow down
_retry_grep 12 5 "\w,lts\W" _run $MP find
# Launch and test primary
_run $MP start --timeout 1200
_run $MP list
_run $MP exec primary -- uname -a
- name: Run the job
id: run
uses: nick-fields/retry@v2
with:
timeout_minutes: 60
max_attempts: 2
command: |
JOB_ID=$( testflinger-cli submit --quiet ${TESTFLINGER_FILE} )
echo "${JOB_ID}" > testflinger_job
testflinger-cli poll "${JOB_ID}"
[ "$( testflinger-cli results ${JOB_ID} | jq -r .test_status )" == "0" ]
on_retry_command: |
testflinger-cli cancel "$( cat testflinger_job )"
- name: Cancel the job
if: ${{ cancelled() }}
run: |
if [ -f testflinger_job ]; then testflinger-cli cancel "$( cat testflinger_job )"; fi