Skip to content

Commit 94dbd79

Browse files
committed
Use script to pick the qemu formula for the desired version
This will automatically pick the right bottle for the OS of the runner, and we can easily change the QEMU version number without having to look up commit ids manually. Signed-off-by: Jan Dubois <[email protected]>
1 parent a04f7c3 commit 94dbd79

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ jobs:
370370

371371
upgrade:
372372
name: "Upgrade test"
373-
# The QEMU bottle URL needs to be updated when the runner is upgraded from Monterey
374373
runs-on: macos-12
375374
timeout-minutes: 120
376375
strategy:
@@ -388,15 +387,14 @@ jobs:
388387
with:
389388
template: https://raw.githubusercontent.com/lima-vm/lima/${{ matrix.oldver }}/examples/ubuntu-lts.yaml
390389
- name: Install test dependencies
390+
env:
391+
# brew-install-version.sh calls `gh`, which needs the token
392+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
391393
run: |
392394
brew install bash coreutils
393395
# QEMU 9.1.0 seems to break on GitHub runners, both on Monterey and Ventura
394396
# We revert back to 8.2.1, which seems to work fine
395-
# The SHA1 for the Monterey bottle comes from https://github.com/Homebrew/homebrew-core/blob/4c7ffca/Formula/q/qemu.rb
396-
brew uninstall --ignore-dependencies --force qemu
397-
curl -L -o qemu-8.2.1.monterey.bottle.tar.gz -H "Authorization: Bearer QQ==" \
398-
https://ghcr.io/v2/homebrew/core/qemu/blobs/sha256:41c77f6bac3e8c1664c665fbe2b19b19ee9da57f8e1ad6697348286710cc3575
399-
brew install --ignore-dependencies ./qemu-8.2.1.monterey.bottle.tar.gz
397+
./hack/brew-install-version.sh qemu 8.2.1
400398
- name: Test
401399
uses: nick-fields/retry@v3
402400
with:

hack/brew-install-version.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# This script only works for formulas in the homebrew-core
3+
4+
set -eu -o pipefail
5+
6+
FORMULA=$1
7+
VERSION=$2
8+
9+
export HOMEBREW_NO_AUTO_UPDATE=1
10+
export HOMEBREW_NO_INSTALL_UPGRADE=1
11+
export HOMEBREW_NO_INSTALL_CLEANUP=1
12+
13+
TAP=lima/tap
14+
if ! brew tap | grep -q "^${TAP}\$"; then
15+
brew tap-new "$TAP"
16+
fi
17+
18+
# Get the commit id for the commit that updated this bottle
19+
SHA=$(gh search commits --repo homebrew/homebrew-core "${FORMULA}: update ${VERSION} bottle" --json sha --jq "last|.sha")
20+
if [[ -z $SHA ]]; then
21+
echo "${FORMULA} ${VERSION} not found"
22+
exit 1
23+
fi
24+
25+
OUTPUT="$(brew --repo "$TAP")/Formula/${FORMULA}.rb"
26+
RAW="https://raw.githubusercontent.com/Homebrew/homebrew-core"
27+
curl -s "${RAW}/${SHA}/Formula/${FORMULA::1}/${FORMULA}.rb" -o "$OUTPUT"
28+
29+
if brew ls -1 | grep -q "^${FORMULA}\$"; then
30+
brew uninstall "$FORMULA" --ignore-dependencies
31+
fi
32+
brew install "${TAP}/${FORMULA}"

0 commit comments

Comments
 (0)