Skip to content

Commit b3bdb51

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

File tree

1 file changed

+252
-0
lines changed

1 file changed

+252
-0
lines changed

.github/workflows/mac-test.yaml

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
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+
46+
# Debug step to see available users
47+
- name: List available users and system info
48+
run: |
49+
echo "Current user: $(whoami)"
50+
echo "Current user ID: $(id -u)"
51+
echo "Current user home: $HOME"
52+
echo "Console user: $(stat -f "%Su" /dev/console)"
53+
echo "All users:"
54+
dscl . -list /Users | grep -v '^_'
55+
echo "Users with home directories:"
56+
ls -la /Users/
57+
echo "Environment variables:"
58+
env | sort
59+
echo "Brew info:"
60+
which brew || echo "brew not found in PATH"
61+
echo "PATH: $PATH"
62+
63+
- name: Install Rosetta 2
64+
run: echo "A" | softwareupdate --install-rosetta || true
65+
66+
# Fix Homebrew permissions and setup environment
67+
- name: Fix Homebrew permissions and setup environment
68+
run: |
69+
echo "Fixing Homebrew permissions for ec2-user..."
70+
sudo chown -R ec2-user:staff /opt/homebrew
71+
72+
# Create a cache directory that ec2-user can access
73+
sudo mkdir -p /tmp/homebrew-cache
74+
sudo chown -R ec2-user:staff /tmp/homebrew-cache
75+
76+
# Create a .brewrc file for ec2-user with environment settings
77+
sudo -u ec2-user bash -c 'cat > /Users/ec2-user/.brewrc << EOF
78+
export HOMEBREW_NO_AUTO_UPDATE=1
79+
export HOMEBREW_NO_INSTALL_CLEANUP=1
80+
export HOMEBREW_CACHE=/tmp/homebrew-cache
81+
export HOMEBREW_NO_ENV_HINTS=1
82+
EOF'
83+
84+
# Make sure ec2-user sources the .brewrc file
85+
sudo -u ec2-user bash -c 'echo "source /Users/ec2-user/.brewrc" >> /Users/ec2-user/.zshrc'
86+
sudo -u ec2-user bash -c 'echo "source /Users/ec2-user/.brewrc" >> /Users/ec2-user/.bashrc'
87+
88+
# Install dependencies using ec2-user with custom environment
89+
- name: Install dependencies
90+
run: |
91+
echo "Installing dependencies as ec2-user..."
92+
93+
# Run brew with custom environment
94+
sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew install lz4 automake autoconf libtool yq'
95+
96+
# Verify installation
97+
sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew list | grep lz4 || echo "lz4 not installed"'
98+
shell: bash
99+
100+
# Install Finch
101+
- name: Install Finch
102+
run: |
103+
echo "Installing Finch as ec2-user..."
104+
105+
# Run brew with custom environment
106+
sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew install finch --cask'
107+
108+
# Verify installation
109+
sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew list | grep finch || echo "finch not installed"'
110+
111+
# Find finch executable
112+
echo "Searching for finch executable..."
113+
sudo -u ec2-user bash -c 'which finch || echo "finch not in PATH"'
114+
sudo -u ec2-user bash -c 'find /Applications -name finch || echo "finch not found in /Applications"'
115+
sudo -u ec2-user bash -c 'find /usr/local -name finch || echo "finch not found in /usr/local"'
116+
117+
# Set finch path for later steps
118+
FINCH_PATH=$(sudo -u ec2-user bash -c 'which finch || echo "/usr/local/bin/finch"')
119+
echo "FINCH_PATH=$FINCH_PATH" >> $GITHUB_ENV
120+
121+
# Create .finch directory and config for ec2-user
122+
echo "Creating .finch directory and config for ec2-user..."
123+
sudo -u ec2-user bash -c 'mkdir -p /Users/ec2-user/.finch'
124+
sudo -u ec2-user bash -c 'echo "cpus: 4" > /Users/ec2-user/.finch/finch.yaml'
125+
sudo -u ec2-user bash -c 'echo "memory: 8GiB" >> /Users/ec2-user/.finch/finch.yaml'
126+
127+
# Check finch version with HOME set to ec2-user's home
128+
echo "Checking finch version..."
129+
if ! sudo -u ec2-user bash -c 'HOME=/Users/ec2-user finch version'; then
130+
echo "finch version command failed, starting VM..."
131+
sudo -u ec2-user bash -c 'HOME=/Users/ec2-user finch vm start'
132+
fi
133+
shell: bash
134+
135+
136+
# Check for Finch socket
137+
- name: Check for Finch socket
138+
run: |
139+
echo "Checking for Finch socket at /Applications/Finch/lima/data/finch/sock/finch.sock..."
140+
141+
# Check if the socket file exists
142+
if sudo -u ec2-user bash -c 'test -S /Applications/Finch/lima/data/finch/sock/finch.sock'; then
143+
echo "Socket file exists"
144+
145+
# Check if the socket is active (can connect)
146+
if sudo -u ec2-user bash -c 'nc -z -U /Applications/Finch/lima/data/finch/sock/finch.sock'; then
147+
echo "Socket is active and accepting connections"
148+
else
149+
echo "Socket file exists but is not accepting connections"
150+
# List socket details
151+
sudo -u ec2-user bash -c 'ls -la /Applications/Finch/lima/data/finch/sock/finch.sock'
152+
echo "ERROR: Socket exists but is not accepting connections"
153+
exit 1
154+
fi
155+
else
156+
echo "Socket file not found at /Applications/Finch/lima/data/finch/sock/finch.sock"
157+
158+
# Try to find the socket elsewhere
159+
echo "Searching for finch.sock in /Applications..."
160+
sudo -u ec2-user bash -c 'find /Applications -name "finch.sock" 2>/dev/null || echo "No finch.sock found in /Applications"'
161+
162+
# Check if the directory structure exists
163+
echo "Checking directory structure..."
164+
sudo -u ec2-user bash -c 'ls -la /Applications/Finch/lima/data/ 2>/dev/null || echo "Directory structure does not exist"'
165+
166+
# Check if Finch is running
167+
echo "Checking if Finch VM is running..."
168+
sudo -u ec2-user bash -c 'HOME=/Users/ec2-user finch vm status || echo "Failed to get Finch VM status"'
169+
170+
echo "ERROR: Socket file not found at expected location /Applications/Finch/lima/data/finch/sock/finch.sock"
171+
exit 1
172+
fi
173+
174+
# Store the socket path for later steps
175+
echo "SOCKET_PATH=/Applications/Finch/lima/data/finch/sock/finch.sock" >> $GITHUB_ENV
176+
shell: bash
177+
178+
# Run e2e tests inside the Finch VM
179+
- name: Run e2e tests
180+
run: |
181+
echo "Running e2e tests as ec2-user..."
182+
183+
# Get the socket path from finch info
184+
# SOCKET_PATH=$(sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch info | grep 'Socket:' | awk '{print \$2}'")
185+
echo "Detected socket path: $SOCKET_PATH"
186+
187+
# If socket path is empty, try to find it
188+
if [ -z "$SOCKET_PATH" ]; then
189+
echo "Socket path not found in finch info, searching for it..."
190+
SOCKET_PATH=$(sudo -u ec2-user bash -c 'find /Users/ec2-user/.finch -name "finch.sock" 2>/dev/null || find /Applications -name "finch.sock" 2>/dev/null || echo ""')
191+
echo "Found socket path: $SOCKET_PATH"
192+
fi
193+
194+
# If socket path is still empty, use a default path
195+
if [ -z "$SOCKET_PATH" ]; then
196+
echo "Using default socket path"
197+
SOCKET_PATH="/Users/ec2-user/.finch/run/finch.sock"
198+
fi
199+
200+
# Ensure socket path is not empty
201+
if [ -z "$SOCKET_PATH" ]; then
202+
echo "Error: Could not determine socket path"
203+
exit 1
204+
fi
205+
206+
# Run tests using ec2-user with custom environment
207+
echo "Using DOCKER_HOST=unix://$SOCKET_PATH"
208+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user && cd ${{ github.workspace }} && DOCKER_HOST=unix://$SOCKET_PATH make test-e2e"
209+
shell: bash
210+
211+
# Run e2e tests with OPA authorization
212+
- name: Run opa e2e tests
213+
run: |
214+
echo "Running e2e tests with OPA authorization as ec2-user..."
215+
216+
# Get the socket path from finch info
217+
SOCKET_PATH=$(sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch info | grep 'Socket:' | awk '{print \$2}'")
218+
echo "Detected socket path: $SOCKET_PATH"
219+
220+
# If socket path is empty, try to find it
221+
if [ -z "$SOCKET_PATH" ]; then
222+
echo "Socket path not found in finch info, searching for it..."
223+
SOCKET_PATH=$(sudo -u ec2-user bash -c 'find /Users/ec2-user/.finch -name "finch.sock" 2>/dev/null || find /Applications -name "finch.sock" 2>/dev/null || echo ""')
224+
echo "Found socket path: $SOCKET_PATH"
225+
fi
226+
227+
# If socket path is still empty, use a default path
228+
if [ -z "$SOCKET_PATH" ]; then
229+
echo "Using default socket path"
230+
SOCKET_PATH="/Users/ec2-user/.finch/run/finch.sock"
231+
fi
232+
233+
# Ensure socket path is not empty
234+
if [ -z "$SOCKET_PATH" ]; then
235+
echo "Error: Could not determine socket path"
236+
exit 1
237+
fi
238+
239+
# Run tests using ec2-user with custom environment
240+
echo "Using DOCKER_HOST=unix://$SOCKET_PATH"
241+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user && cd ${{ github.workspace }} && DOCKER_HOST=unix://$SOCKET_PATH make test-e2e-opa"
242+
shell: bash
243+
244+
# Cleanup
245+
- name: Stop Finch VM
246+
run: |
247+
echo "Stopping Finch VM as ec2-user..."
248+
249+
# Stop VM using ec2-user with custom environment
250+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch vm stop"
251+
shell: bash
252+
if: always()

0 commit comments

Comments
 (0)