From 48294d2a8448ac8093d757ee6ca8902b1a9e6e15 Mon Sep 17 00:00:00 2001 From: Zen Dodd Date: Sat, 5 Dec 2026 00:18:20 +1000 Subject: [PATCH] ci: share VM host package setup --- .github/scripts/changes.py | 2 ++ .github/scripts/prepare-vm-host.sh | 28 ++++++++++++++++++++ .github/scripts/test-changes.py | 1 + .github/workflows/bsd.yml | 21 +++------------ .github/workflows/interoperability-tests.yml | 8 +++--- .github/workflows/other.yml | 7 +---- 6 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 .github/scripts/prepare-vm-host.sh diff --git a/.github/scripts/changes.py b/.github/scripts/changes.py index 84c7201a8..ae7411a22 100644 --- a/.github/scripts/changes.py +++ b/.github/scripts/changes.py @@ -106,6 +106,8 @@ def script(selected, name): enable(selected, 'linux', 'diagnostics') elif name == 'install-cygwin.ps1': enable(selected, 'other', 'diagnostics') + elif name == 'prepare-vm-host.sh': + enable(selected, 'bsd', 'other', 'diagnostics', 'interoperability') elif name == 'ubuntu-apt.sh': enable(selected, 'linux', 'bsd', 'other', 'android', 'archive', 'diagnostics', 'versions', 'valgrind', 'interoperability', 'asan', 'coverage', 'static_analysis') diff --git a/.github/scripts/prepare-vm-host.sh b/.github/scripts/prepare-vm-host.sh new file mode 100644 index 000000000..27c21cb1b --- /dev/null +++ b/.github/scripts/prepare-vm-host.sh @@ -0,0 +1,28 @@ +#!/bin/sh +set -eu + +case "${1-}" in + retry|update-first) mode=$1; shift ;; + *) echo 'usage: prepare-vm-host.sh {retry|update-first} {base|autotools}' >&2; exit 2 ;; +esac +if [ "$#" -ne 1 ]; then + echo 'usage: prepare-vm-host.sh {retry|update-first} {base|autotools}' >&2 + exit 2 +fi + +case "${1-}" in + base) set -- qemu-utils qemu-system-x86 ovmf ;; + autotools) set -- autoconf automake qemu-utils qemu-system-x86 ovmf ;; + *) echo 'unknown VM host package set' >&2; exit 2 ;; +esac + +if [ "$mode" = update-first ]; then + sh .github/scripts/ubuntu-apt.sh update + exec sh .github/scripts/ubuntu-apt.sh install -y "$@" +fi + +if sh .github/scripts/ubuntu-apt.sh install -y -q -o Acquire::Retries=3 --no-install-recommends "$@"; then + exit 0 +fi +sh .github/scripts/ubuntu-apt.sh update -q +exec sh .github/scripts/ubuntu-apt.sh install -y -q -o Acquire::Retries=3 --no-install-recommends "$@" diff --git a/.github/scripts/test-changes.py b/.github/scripts/test-changes.py index 962b312eb..4b51b1c4b 100644 --- a/.github/scripts/test-changes.py +++ b/.github/scripts/test-changes.py @@ -90,6 +90,7 @@ def test_ci_files_select_their_owner(self): '.github/scripts/changes.py': full_selection, '.github/scripts/test-changes.py': {'diagnostics'}, '.github/scripts/check-platform.py': {'linux', 'macos', 'other', 'diagnostics'}, + '.github/scripts/prepare-vm-host.sh': {'bsd', 'other', 'diagnostics', 'interoperability'}, '.github/scripts/ubuntu-apt.sh': full_selection - {'macos'}, '.github/actions/interoperability/action.yml': {'interoperability', 'diagnostics'}, '.github/actions/interop-upload/action.yml': {'interoperability', 'diagnostics'}, diff --git a/.github/workflows/bsd.yml b/.github/workflows/bsd.yml index 11418159d..b77161d13 100644 --- a/.github/workflows/bsd.yml +++ b/.github/workflows/bsd.yml @@ -30,12 +30,7 @@ jobs: persist-credentials: false - name: Prepare VM host timeout-minutes: 10 - run: | - set -- qemu-utils qemu-system-x86 ovmf - sh .github/scripts/ubuntu-apt.sh install -y -q -o Acquire::Retries=3 --no-install-recommends "$@" || { - sh .github/scripts/ubuntu-apt.sh update -q - sh .github/scripts/ubuntu-apt.sh install -y -q -o Acquire::Retries=3 --no-install-recommends "$@" - } + run: sh .github/scripts/prepare-vm-host.sh retry base - name: Run VM and collect results uses: vmactions/freebsd-vm@c46abacb49f09938ca4e1702d15d836285d694cc # v1.5.9 with: @@ -94,12 +89,7 @@ jobs: persist-credentials: false - name: Prepare VM host timeout-minutes: 10 - run: | - set -- autoconf automake qemu-utils qemu-system-x86 ovmf - sh .github/scripts/ubuntu-apt.sh install -y -q -o Acquire::Retries=3 --no-install-recommends "$@" || { - sh .github/scripts/ubuntu-apt.sh update -q - sh .github/scripts/ubuntu-apt.sh install -y -q -o Acquire::Retries=3 --no-install-recommends "$@" - } + run: sh .github/scripts/prepare-vm-host.sh retry autotools - name: Prepare source run: ./prepare-source - name: Run VM and collect results @@ -166,12 +156,7 @@ jobs: persist-credentials: false - name: Prepare VM host timeout-minutes: 10 - run: | - set -- qemu-utils qemu-system-x86 ovmf - sh .github/scripts/ubuntu-apt.sh install -y -q -o Acquire::Retries=3 --no-install-recommends "$@" || { - sh .github/scripts/ubuntu-apt.sh update -q - sh .github/scripts/ubuntu-apt.sh install -y -q -o Acquire::Retries=3 --no-install-recommends "$@" - } + run: sh .github/scripts/prepare-vm-host.sh retry base - name: Run VM and collect results uses: vmactions/openbsd-vm@f1ca8bc8ecc5b6ef7218e5b914836e067e1546d3 # v1.4.9 with: diff --git a/.github/workflows/interoperability-tests.yml b/.github/workflows/interoperability-tests.yml index 6b7533de0..797e7e052 100644 --- a/.github/workflows/interoperability-tests.yml +++ b/.github/workflows/interoperability-tests.yml @@ -48,7 +48,7 @@ jobs: with: persist-credentials: false - name: Prepare VM host - run: sh .github/scripts/ubuntu-apt.sh update && sh .github/scripts/ubuntu-apt.sh install -y qemu-utils qemu-system-x86 ovmf + run: sh .github/scripts/prepare-vm-host.sh update-first base - name: Configure and build uses: vmactions/freebsd-vm@c46abacb49f09938ca4e1702d15d836285d694cc # v1.5.9 with: @@ -75,7 +75,7 @@ jobs: with: persist-credentials: false - name: Prepare VM host - run: sh .github/scripts/ubuntu-apt.sh update && sh .github/scripts/ubuntu-apt.sh install -y autoconf automake qemu-utils qemu-system-x86 ovmf + run: sh .github/scripts/prepare-vm-host.sh update-first autotools - name: Prepare source run: ./prepare-source - name: Configure and build @@ -115,7 +115,7 @@ jobs: with: persist-credentials: false - name: Prepare VM host - run: sh .github/scripts/ubuntu-apt.sh update && sh .github/scripts/ubuntu-apt.sh install -y qemu-utils qemu-system-x86 ovmf + run: sh .github/scripts/prepare-vm-host.sh update-first base - name: Configure and build uses: vmactions/openbsd-vm@f1ca8bc8ecc5b6ef7218e5b914836e067e1546d3 # v1.4.9 with: @@ -178,7 +178,7 @@ jobs: with: persist-credentials: false - name: Prepare VM host - run: sh .github/scripts/ubuntu-apt.sh update && sh .github/scripts/ubuntu-apt.sh install -y qemu-utils qemu-system-x86 ovmf + run: sh .github/scripts/prepare-vm-host.sh update-first base - name: Configure and build uses: vmactions/solaris-vm@87d3c436511cef802cd1637f86f73b1a97715c8c # v1.4.1 with: diff --git a/.github/workflows/other.yml b/.github/workflows/other.yml index ce5686b1d..6484e3f10 100644 --- a/.github/workflows/other.yml +++ b/.github/workflows/other.yml @@ -103,12 +103,7 @@ jobs: persist-credentials: false - name: Prepare VM host timeout-minutes: 10 - run: | - set -- qemu-utils qemu-system-x86 ovmf - sh .github/scripts/ubuntu-apt.sh install -y -q -o Acquire::Retries=3 --no-install-recommends "$@" || { - sh .github/scripts/ubuntu-apt.sh update -q - sh .github/scripts/ubuntu-apt.sh install -y -q -o Acquire::Retries=3 --no-install-recommends "$@" - } + run: sh .github/scripts/prepare-vm-host.sh retry base - name: Run VM and collect results uses: vmactions/solaris-vm@87d3c436511cef802cd1637f86f73b1a97715c8c # v1.4.1 with: