Integration #1958
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v3 | |
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 |