Skip to content

chore: run e2e in finch vm #4

chore: run e2e in finch vm

chore: run e2e in finch vm #4

Workflow file for this run

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: Setup tmate session
uses: mxschmitt/action-tmate@v3
- 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
- name: Install Rosetta 2
run: echo "A" | softwareupdate --install-rosetta || true
- name: Install dependencies
run: |
# Install dependencies without using root
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root, installing as non-root user"
# Try to find brew path
BREW_PATH=$(sudo -u $(stat -f "%Su" /dev/console) which brew || echo "/opt/homebrew/bin/brew")
# Install dependencies using sudo -u to run as the console user
sudo -u $(stat -f "%Su" /dev/console) $BREW_PATH install lz4 automake autoconf libtool yq
else
brew install lz4 automake autoconf libtool yq
fi
shell: zsh {0}
# Install Finch
- name: Install Finch
run: |
# Install Finch without using root
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root, installing as non-root user"
# Try to find brew path
BREW_PATH=$(sudo -u $(stat -f "%Su" /dev/console) which brew || echo "/opt/homebrew/bin/brew")
# Install Finch using sudo -u to run as the console user
sudo -u $(stat -f "%Su" /dev/console) $BREW_PATH install finch
else
brew install finch
fi
shell: zsh {0}
# Initialize and start Finch VM
- name: Initialize Finch VM
run: |
# Ensure finch commands run as the same user who installed it
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root, switching to regular user for finch commands"
# Try to find finch path
FINCH_PATH=$(sudo -u $(stat -f "%Su" /dev/console) which finch || echo "/opt/homebrew/bin/finch")
# Initialize VM using sudo -u to run as the console user
sudo -u $(stat -f "%Su" /dev/console) $FINCH_PATH vm init
else
finch vm init
fi
- name: Start Finch VM
run: |
# Ensure finch commands run as the same user who installed it
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root, switching to regular user for finch commands"
# Try to find finch path
FINCH_PATH=$(sudo -u $(stat -f "%Su" /dev/console) which finch || echo "/opt/homebrew/bin/finch")
# Start VM using sudo -u to run as the console user
sudo -u $(stat -f "%Su" /dev/console) $FINCH_PATH vm start
else
finch vm start
fi
# Run e2e tests inside the Finch VM
- name: Run e2e tests
run: |
# Run tests as the same user who installed and started Finch
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root, switching to regular user for tests"
# Run tests using sudo -u to run as the console user
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"
else
export DOCKER_HOST=unix:///Applications/Finch/lima/data/finch/sock/finch.sock
make test-e2e
fi
# Run e2e tests with OPA authorization
- name: Run opa e2e tests
run: |
# Run tests as the same user who installed and started Finch
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root, switching to regular user for tests"
# Run tests using sudo -u to run as the console user
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"
else
export DOCKER_HOST=unix:///Applications/Finch/lima/data/finch/sock/finch.sock
make test-e2e-opa
fi
# Cleanup
- name: Stop Finch VM
run: |
# Ensure finch commands run as the same user who installed it
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root, switching to regular user for finch commands"
# Try to find finch path
FINCH_PATH=$(sudo -u $(stat -f "%Su" /dev/console) which finch || echo "/opt/homebrew/bin/finch")
# Stop VM using sudo -u to run as the console user
sudo -u $(stat -f "%Su" /dev/console) $FINCH_PATH vm stop
else
finch vm stop
fi
if: always()