Skip to content

Commit 5e18c72

Browse files
committed
chore: run e2e in finch vm
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 7ec7d02 commit 5e18c72

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

.github/workflows/mac-test.yaml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: macOS Tests
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths-ignore:
7+
- '**.md'
8+
pull_request:
9+
branches:
10+
- main
11+
paths-ignore:
12+
- '**.md'
13+
workflow_dispatch:
14+
env:
15+
GO_VERSION: '1.23.8'
16+
jobs:
17+
mac-test:
18+
runs-on: codebuild-Test-fd-codebuild-mac-${{ github.run_id }}-${{ github.run_attempt }}
19+
timeout-minutes: 30
20+
steps:
21+
- name: Clean macOS runner workspace
22+
run: |
23+
rm -rf ${{ github.workspace }}/*
24+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
with:
26+
# We need to get all the git tags to make version injection work. See VERSION in Makefile for more detail.
27+
fetch-depth: 0
28+
persist-credentials: false
29+
submodules: recursive
30+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
31+
with:
32+
go-version: ${{ env.GO_VERSION }}
33+
cache: false
34+
- name: Clean up previous files
35+
run: |
36+
sudo rm -rf /opt/finch
37+
sudo rm -rf ~/.finch
38+
sudo rm -rf ./_output
39+
if pgrep '^qemu-system'; then
40+
sudo pkill '^qemu-system'
41+
fi
42+
if pgrep '^socket_vmnet'; then
43+
sudo pkill '^socket_vmnet'
44+
fi
45+
- name: Install Rosetta 2
46+
run: echo "A" | softwareupdate --install-rosetta || true
47+
- name: Install dependencies
48+
run: |
49+
# Install dependencies without using root
50+
if [ "$(id -u)" -eq 0 ]; then
51+
echo "Running as root, installing as non-root user"
52+
# Try to find brew path
53+
BREW_PATH=$(sudo -u $(stat -f "%Su" /dev/console) which brew || echo "/opt/homebrew/bin/brew")
54+
55+
# Install dependencies using sudo -u to run as the console user
56+
sudo -u $(stat -f "%Su" /dev/console) $BREW_PATH install lz4 automake autoconf libtool yq
57+
else
58+
brew install lz4 automake autoconf libtool yq
59+
fi
60+
shell: zsh {0}
61+
62+
# Install Finch
63+
- name: Install Finch
64+
run: |
65+
# Install Finch without using root
66+
if [ "$(id -u)" -eq 0 ]; then
67+
echo "Running as root, installing as non-root user"
68+
# Try to find brew path
69+
BREW_PATH=$(sudo -u $(stat -f "%Su" /dev/console) which brew || echo "/opt/homebrew/bin/brew")
70+
71+
# Install Finch using sudo -u to run as the console user
72+
sudo -u $(stat -f "%Su" /dev/console) $BREW_PATH install finch
73+
else
74+
brew install finch
75+
fi
76+
shell: zsh {0}
77+
78+
# Initialize and start Finch VM
79+
- name: Initialize Finch VM
80+
run: |
81+
# Ensure finch commands run as the same user who installed it
82+
if [ "$(id -u)" -eq 0 ]; then
83+
echo "Running as root, switching to regular user for finch commands"
84+
# Try to find finch path
85+
FINCH_PATH=$(sudo -u $(stat -f "%Su" /dev/console) which finch || echo "/opt/homebrew/bin/finch")
86+
87+
# Initialize VM using sudo -u to run as the console user
88+
sudo -u $(stat -f "%Su" /dev/console) $FINCH_PATH vm init
89+
else
90+
finch vm init
91+
fi
92+
93+
- name: Start Finch VM
94+
run: |
95+
# Ensure finch commands run as the same user who installed it
96+
if [ "$(id -u)" -eq 0 ]; then
97+
echo "Running as root, switching to regular user for finch commands"
98+
# Try to find finch path
99+
FINCH_PATH=$(sudo -u $(stat -f "%Su" /dev/console) which finch || echo "/opt/homebrew/bin/finch")
100+
101+
# Start VM using sudo -u to run as the console user
102+
sudo -u $(stat -f "%Su" /dev/console) $FINCH_PATH vm start
103+
else
104+
finch vm start
105+
fi
106+
107+
# Run e2e tests inside the Finch VM
108+
- name: Run e2e tests
109+
run: |
110+
# Run tests as the same user who installed and started Finch
111+
if [ "$(id -u)" -eq 0 ]; then
112+
echo "Running as root, switching to regular user for tests"
113+
# Run tests using sudo -u to run as the console user
114+
sudo -u $(stat -f "%Su" /dev/console) bash -c "cd ${{ github.workspace }} && DOCKER_HOST=unix:///Applications/Finch/lima/data/finch/sock/finch.sock make test-e2e"
115+
else
116+
export DOCKER_HOST=unix:///Applications/Finch/lima/data/finch/sock/finch.sock
117+
make test-e2e
118+
fi
119+
120+
# Run e2e tests with OPA authorization
121+
- name: Run opa e2e tests
122+
run: |
123+
# Run tests as the same user who installed and started Finch
124+
if [ "$(id -u)" -eq 0 ]; then
125+
echo "Running as root, switching to regular user for tests"
126+
# Run tests using sudo -u to run as the console user
127+
sudo -u $(stat -f "%Su" /dev/console) bash -c "cd ${{ github.workspace }} && DOCKER_HOST=unix:///Applications/Finch/lima/data/finch/sock/finch.sock make test-e2e-opa"
128+
else
129+
export DOCKER_HOST=unix:///Applications/Finch/lima/data/finch/sock/finch.sock
130+
make test-e2e-opa
131+
fi
132+
133+
# Cleanup
134+
- name: Stop Finch VM
135+
run: |
136+
# Ensure finch commands run as the same user who installed it
137+
if [ "$(id -u)" -eq 0 ]; then
138+
echo "Running as root, switching to regular user for finch commands"
139+
# Try to find finch path
140+
FINCH_PATH=$(sudo -u $(stat -f "%Su" /dev/console) which finch || echo "/opt/homebrew/bin/finch")
141+
142+
# Stop VM using sudo -u to run as the console user
143+
sudo -u $(stat -f "%Su" /dev/console) $FINCH_PATH vm stop
144+
else
145+
finch vm stop
146+
fi
147+
if: always()

0 commit comments

Comments
 (0)