Skip to content

Commit 769c108

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

File tree

1 file changed

+199
-0
lines changed

1 file changed

+199
-0
lines changed

.github/workflows/mac-test.yaml

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

0 commit comments

Comments
 (0)