Skip to content

Commit c71183a

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

File tree

1 file changed

+210
-0
lines changed

1 file changed

+210
-0
lines changed

.github/workflows/mac-test.yaml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
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'
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 /opt -name finch || echo "finch not found in /opt"'
116+
sudo -u ec2-user bash -c 'find /usr/local -name finch || echo "finch not found in /usr/local"'
117+
118+
# Check finch version
119+
echo "Checking finch version..."
120+
sudo -u ec2-user bash -c 'finch version || echo "finch version command failed"'
121+
122+
# Set finch path for later steps
123+
FINCH_PATH=$(sudo -u ec2-user bash -c 'which finch || echo "/Applications/Finch/finch"')
124+
echo "FINCH_PATH=$FINCH_PATH" >> $GITHUB_ENV
125+
shell: bash
126+
127+
# Initialize and start Finch VM
128+
- name: Initialize Finch VM
129+
run: |
130+
echo "Initializing Finch VM as ec2-user..."
131+
132+
# Initialize VM using ec2-user with custom environment
133+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && finch vm init"
134+
135+
# Check VM status after initialization
136+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && finch vm ls"
137+
shell: bash
138+
139+
- name: Start Finch VM
140+
run: |
141+
echo "Starting Finch VM as ec2-user..."
142+
143+
# Start VM using ec2-user with custom environment
144+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && finch vm start"
145+
146+
# Verify VM is running
147+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && finch vm ls"
148+
149+
# Check finch info
150+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && finch info"
151+
152+
# Check socket path
153+
echo "Checking Finch socket path..."
154+
sudo -u ec2-user bash -c 'ls -la /Users/ec2-user/.finch/run/ || echo "No .finch/run directory"'
155+
sudo -u ec2-user bash -c 'ls -la /Applications/Finch/lima/data/finch/sock/ || echo "No /Applications/Finch/lima/data/finch/sock/ directory"'
156+
sudo -u ec2-user bash -c 'find /Applications -name "finch.sock" || echo "No finch.sock found in /Applications"'
157+
sudo -u ec2-user bash -c 'find /Users/ec2-user -name "finch.sock" || echo "No finch.sock found in /Users/ec2-user"'
158+
shell: bash
159+
160+
# Run e2e tests inside the Finch VM
161+
- name: Run e2e tests
162+
run: |
163+
echo "Running e2e tests as ec2-user..."
164+
165+
# Get the socket path from finch info
166+
SOCKET_PATH=$(sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && finch info | grep 'Socket:' | awk '{print \$2}'")
167+
echo "Detected socket path: $SOCKET_PATH"
168+
169+
# If socket path is empty, try to find it
170+
if [ -z "$SOCKET_PATH" ]; then
171+
echo "Socket path not found in finch info, searching for it..."
172+
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 "/Applications/Finch/lima/data/finch/sock/finch.sock"')
173+
echo "Found socket path: $SOCKET_PATH"
174+
fi
175+
176+
# Run tests using ec2-user with custom environment
177+
echo "Using DOCKER_HOST=unix://$SOCKET_PATH"
178+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && cd ${{ github.workspace }} && DOCKER_HOST=unix://$SOCKET_PATH make test-e2e"
179+
shell: bash
180+
181+
# Run e2e tests with OPA authorization
182+
- name: Run opa e2e tests
183+
run: |
184+
echo "Running e2e tests with OPA authorization as ec2-user..."
185+
186+
# Get the socket path from finch info
187+
SOCKET_PATH=$(sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && finch info | grep 'Socket:' | awk '{print \$2}'")
188+
echo "Detected socket path: $SOCKET_PATH"
189+
190+
# If socket path is empty, try to find it
191+
if [ -z "$SOCKET_PATH" ]; then
192+
echo "Socket path not found in finch info, searching for it..."
193+
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 "/Applications/Finch/lima/data/finch/sock/finch.sock"')
194+
echo "Found socket path: $SOCKET_PATH"
195+
fi
196+
197+
# Run tests using ec2-user with custom environment
198+
echo "Using DOCKER_HOST=unix://$SOCKET_PATH"
199+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && cd ${{ github.workspace }} && DOCKER_HOST=unix://$SOCKET_PATH make test-e2e-opa"
200+
shell: bash
201+
202+
# Cleanup
203+
- name: Stop Finch VM
204+
run: |
205+
echo "Stopping Finch VM as ec2-user..."
206+
207+
# Stop VM using ec2-user with custom environment
208+
sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && finch vm stop"
209+
shell: bash
210+
if: always()

0 commit comments

Comments
 (0)