chore: run e2e in finch vm #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: macOS Tests | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - '**.md' | |
| pull_request: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - '**.md' | |
| workflow_dispatch: | |
| env: | |
| GO_VERSION: '1.23.8' | |
| jobs: | |
| mac-test: | |
| runs-on: codebuild-Test-fd-codebuild-mac-${{ github.run_id }}-${{ github.run_attempt }} | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Clean macOS runner workspace | |
| run: | | |
| rm -rf ${{ github.workspace }}/* | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| # We need to get all the git tags to make version injection work. See VERSION in Makefile for more detail. | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| submodules: recursive | |
| - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| cache: false | |
| - name: Clean up previous files | |
| run: | | |
| sudo rm -rf /opt/finch | |
| sudo rm -rf ~/.finch | |
| sudo rm -rf ./_output | |
| if pgrep '^qemu-system'; then | |
| sudo pkill '^qemu-system' | |
| fi | |
| if pgrep '^socket_vmnet'; then | |
| sudo pkill '^socket_vmnet' | |
| fi | |
| # Debug step to see available users | |
| - name: List available users and system info | |
| run: | | |
| echo "Current user: $(whoami)" | |
| echo "Current user ID: $(id -u)" | |
| echo "Current user home: $HOME" | |
| echo "Console user: $(stat -f "%Su" /dev/console)" | |
| echo "All users:" | |
| dscl . -list /Users | grep -v '^_' | |
| echo "Users with home directories:" | |
| ls -la /Users/ | |
| echo "Environment variables:" | |
| env | sort | |
| echo "Brew info:" | |
| which brew || echo "brew not found in PATH" | |
| echo "PATH: $PATH" | |
| - name: Install Rosetta 2 | |
| run: echo "A" | softwareupdate --install-rosetta || true | |
| # Fix Homebrew permissions and setup environment | |
| - name: Fix Homebrew permissions and setup environment | |
| run: | | |
| echo "Fixing Homebrew permissions for ec2-user..." | |
| sudo chown -R ec2-user:staff /opt/homebrew | |
| # Create a cache directory that ec2-user can access | |
| sudo mkdir -p /tmp/homebrew-cache | |
| sudo chown -R ec2-user:staff /tmp/homebrew-cache | |
| # Create a .brewrc file for ec2-user with environment settings | |
| sudo -u ec2-user bash -c 'cat > /Users/ec2-user/.brewrc << EOF | |
| export HOMEBREW_NO_AUTO_UPDATE=1 | |
| export HOMEBREW_NO_INSTALL_CLEANUP=1 | |
| export HOMEBREW_CACHE=/tmp/homebrew-cache | |
| export HOMEBREW_NO_ENV_HINTS=1 | |
| EOF' | |
| # Make sure ec2-user sources the .brewrc file | |
| sudo -u ec2-user bash -c 'echo "source /Users/ec2-user/.brewrc" >> /Users/ec2-user/.zshrc' | |
| sudo -u ec2-user bash -c 'echo "source /Users/ec2-user/.brewrc" >> /Users/ec2-user/.bashrc' | |
| # Install dependencies using ec2-user with custom environment | |
| - name: Install dependencies | |
| run: | | |
| echo "Installing dependencies as ec2-user..." | |
| # Run brew with custom environment | |
| sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew install lz4 automake autoconf libtool yq' | |
| # Verify installation | |
| sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew list | grep lz4 || echo "lz4 not installed"' | |
| shell: bash | |
| # Install Finch | |
| - name: Install Finch | |
| run: | | |
| echo "Installing Finch as ec2-user..." | |
| # Run brew with custom environment | |
| sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew install finch' | |
| # Verify installation | |
| sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew list | grep finch || echo "finch not installed"' | |
| # Find finch executable | |
| echo "Searching for finch executable..." | |
| sudo -u ec2-user bash -c 'which finch || echo "finch not in PATH"' | |
| sudo -u ec2-user bash -c 'find /Applications -name finch || echo "finch not found in /Applications"' | |
| sudo -u ec2-user bash -c 'find /usr/local -name finch || echo "finch not found in /usr/local"' | |
| # Set finch path for later steps | |
| FINCH_PATH=$(sudo -u ec2-user bash -c 'which finch || echo "/usr/local/bin/finch"') | |
| echo "FINCH_PATH=$FINCH_PATH" >> $GITHUB_ENV | |
| # Create .finch directory and config for ec2-user | |
| echo "Creating .finch directory and config for ec2-user..." | |
| sudo -u ec2-user bash -c 'mkdir -p /Users/ec2-user/.finch' | |
| sudo -u ec2-user bash -c 'echo "cpus: 4" > /Users/ec2-user/.finch/finch.yaml' | |
| sudo -u ec2-user bash -c 'echo "memory: 8GiB" >> /Users/ec2-user/.finch/finch.yaml' | |
| # Check finch version with HOME set to ec2-user's home | |
| echo "Checking finch version..." | |
| sudo -u ec2-user bash -c 'HOME=/Users/ec2-user finch version || echo "finch version command failed"' | |
| shell: bash | |
| # Initialize and start Finch VM | |
| - name: Initialize Finch VM | |
| run: | | |
| echo "Initializing Finch VM as ec2-user..." | |
| # Initialize VM using ec2-user with custom environment and HOME set | |
| sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch vm init" | |
| # Check VM status after initialization | |
| sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch vm ls" | |
| shell: bash | |
| - name: Start Finch VM | |
| run: | | |
| echo "Starting Finch VM as ec2-user..." | |
| # Start VM using ec2-user with custom environment and HOME set | |
| sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch vm start" | |
| # Verify VM is running | |
| sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch vm ls" | |
| # Check finch info | |
| sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch info" | |
| # Check socket path | |
| echo "Checking Finch socket path..." | |
| sudo -u ec2-user bash -c 'ls -la /Users/ec2-user/.finch/run/ || echo "No .finch/run directory"' | |
| sudo -u ec2-user bash -c 'ls -la /Applications/Finch/lima/data/finch/sock/ || echo "No /Applications/Finch/lima/data/finch/sock/ directory"' | |
| sudo -u ec2-user bash -c 'find /Applications -name "finch.sock" || echo "No finch.sock found in /Applications"' | |
| sudo -u ec2-user bash -c 'find /Users/ec2-user -name "finch.sock" || echo "No finch.sock found in /Users/ec2-user"' | |
| shell: bash | |
| # Run e2e tests inside the Finch VM | |
| - name: Run e2e tests | |
| run: | | |
| echo "Running e2e tests as ec2-user..." | |
| # Get the socket path from finch info | |
| SOCKET_PATH=$(sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch info | grep 'Socket:' | awk '{print \$2}'") | |
| echo "Detected socket path: $SOCKET_PATH" | |
| # If socket path is empty, try to find it | |
| if [ -z "$SOCKET_PATH" ]; then | |
| echo "Socket path not found in finch info, searching for it..." | |
| 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 "/Users/ec2-user/.finch/run/finch.sock"') | |
| echo "Found socket path: $SOCKET_PATH" | |
| fi | |
| # Run tests using ec2-user with custom environment | |
| echo "Using DOCKER_HOST=unix://$SOCKET_PATH" | |
| 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" | |
| shell: bash | |
| # Run e2e tests with OPA authorization | |
| - name: Run opa e2e tests | |
| run: | | |
| echo "Running e2e tests with OPA authorization as ec2-user..." | |
| # Get the socket path from finch info | |
| SOCKET_PATH=$(sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch info | grep 'Socket:' | awk '{print \$2}'") | |
| echo "Detected socket path: $SOCKET_PATH" | |
| # If socket path is empty, try to find it | |
| if [ -z "$SOCKET_PATH" ]; then | |
| echo "Socket path not found in finch info, searching for it..." | |
| 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 "/Users/ec2-user/.finch/run/finch.sock"') | |
| echo "Found socket path: $SOCKET_PATH" | |
| fi | |
| # Run tests using ec2-user with custom environment | |
| echo "Using DOCKER_HOST=unix://$SOCKET_PATH" | |
| 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" | |
| shell: bash | |
| # Cleanup | |
| - name: Stop Finch VM | |
| run: | | |
| echo "Stopping Finch VM as ec2-user..." | |
| # Stop VM using ec2-user with custom environment | |
| sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch vm stop" | |
| shell: bash | |
| if: always() |