|
| 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 | + - name: Configure Git for ec2-user |
| 25 | + run: | |
| 26 | + |
| 27 | + # sudo chown -R ec2-user: .git |
| 28 | + git config --global --add safe.directory "*"' |
| 29 | + shell: bash |
| 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 | + # Debug step to see available users |
| 46 | + - name: List available users and system info |
| 47 | + run: | |
| 48 | + echo "Current user: $(whoami)" |
| 49 | + echo "Current user ID: $(id -u)" |
| 50 | + echo "Current user home: $HOME" |
| 51 | + echo "Console user: $(stat -f "%Su" /dev/console)" |
| 52 | + echo "All users:" |
| 53 | + dscl . -list /Users | grep -v '^_' |
| 54 | + echo "Users with home directories:" |
| 55 | + ls -la /Users/ |
| 56 | + echo "Environment variables:" |
| 57 | + env | sort |
| 58 | + echo "Brew info:" |
| 59 | + which brew || echo "brew not found in PATH" |
| 60 | + echo "PATH: $PATH" |
| 61 | + |
| 62 | + - name: Install Rosetta 2 |
| 63 | + run: echo "A" | softwareupdate --install-rosetta || true |
| 64 | + |
| 65 | + # Fix Homebrew permissions and setup environment |
| 66 | + - name: Fix Homebrew permissions and setup environment |
| 67 | + run: | |
| 68 | + echo "Fixing Homebrew permissions for ec2-user..." |
| 69 | + sudo chown -R ec2-user:staff /opt/homebrew |
| 70 | + |
| 71 | + # Create a cache directory that ec2-user can access |
| 72 | + sudo mkdir -p /tmp/homebrew-cache |
| 73 | + sudo chown -R ec2-user:staff /tmp/homebrew-cache |
| 74 | + |
| 75 | + # Create a .brewrc file for ec2-user with environment settings |
| 76 | + sudo -u ec2-user bash -c 'cat > /Users/ec2-user/.brewrc << EOF |
| 77 | + export HOMEBREW_NO_AUTO_UPDATE=1 |
| 78 | + export HOMEBREW_NO_INSTALL_CLEANUP=1 |
| 79 | + export HOMEBREW_CACHE=/tmp/homebrew-cache |
| 80 | + export HOMEBREW_NO_ENV_HINTS=1 |
| 81 | + EOF' |
| 82 | + |
| 83 | + # Make sure ec2-user sources the .brewrc file |
| 84 | + sudo -u ec2-user bash -c 'echo "source /Users/ec2-user/.brewrc" >> /Users/ec2-user/.zshrc' |
| 85 | + sudo -u ec2-user bash -c 'echo "source /Users/ec2-user/.brewrc" >> /Users/ec2-user/.bashrc' |
| 86 | + |
| 87 | + # Install dependencies using ec2-user with custom environment |
| 88 | + - name: Install dependencies |
| 89 | + run: | |
| 90 | + echo "Installing dependencies as ec2-user..." |
| 91 | + |
| 92 | + # Run brew with custom environment |
| 93 | + sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew install lz4 automake autoconf libtool yq' |
| 94 | + |
| 95 | + # Verify installation |
| 96 | + sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew list | grep lz4 || echo "lz4 not installed"' |
| 97 | + shell: bash |
| 98 | + |
| 99 | + # Install Finch |
| 100 | + - name: Install Finch |
| 101 | + run: | |
| 102 | + echo "Installing Finch as ec2-user..." |
| 103 | + |
| 104 | + # Run brew with custom environment |
| 105 | + sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew install finch --cask' |
| 106 | + |
| 107 | + # Verify installation |
| 108 | + sudo -u ec2-user bash -c 'source /Users/ec2-user/.brewrc && brew list | grep finch || echo "finch not installed"' |
| 109 | + |
| 110 | + # Find finch executable |
| 111 | + echo "Searching for finch executable..." |
| 112 | + sudo -u ec2-user bash -c 'which finch || echo "finch not in PATH"' |
| 113 | + sudo -u ec2-user bash -c 'find /Applications -name finch || echo "finch not found in /Applications"' |
| 114 | + sudo -u ec2-user bash -c 'find /usr/local -name finch || echo "finch not found in /usr/local"' |
| 115 | + |
| 116 | + # Set finch path for later steps |
| 117 | + FINCH_PATH=$(sudo -u ec2-user bash -c 'which finch || echo "/usr/local/bin/finch"') |
| 118 | + echo "FINCH_PATH=$FINCH_PATH" >> $GITHUB_ENV |
| 119 | + |
| 120 | + # Create .finch directory and config for ec2-user |
| 121 | + echo "Creating .finch directory and config for ec2-user..." |
| 122 | + sudo -u ec2-user bash -c 'mkdir -p /Users/ec2-user/.finch' |
| 123 | + sudo -u ec2-user bash -c 'echo "cpus: 4" > /Users/ec2-user/.finch/finch.yaml' |
| 124 | + sudo -u ec2-user bash -c 'echo "memory: 8GiB" >> /Users/ec2-user/.finch/finch.yaml' |
| 125 | + |
| 126 | + # Check finch version with HOME set to ec2-user's home |
| 127 | + echo "Checking finch version..." |
| 128 | + if ! sudo -u ec2-user bash -c 'HOME=/Users/ec2-user finch version'; then |
| 129 | + echo "finch version command failed, starting VM..." |
| 130 | + sudo -u ec2-user bash -c 'HOME=/Users/ec2-user finch vm start' |
| 131 | + fi |
| 132 | + shell: bash |
| 133 | + |
| 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 | + else |
| 145 | + echo "ERROR: Socket file not found at expected location /Applications/Finch/lima/data/finch/sock/finch.sock" |
| 146 | + exit 1 |
| 147 | + fi |
| 148 | + |
| 149 | + # Store the socket path for later steps |
| 150 | + echo "SOCKET_PATH=/Applications/Finch/lima/data/finch/sock/finch.sock" >> $GITHUB_ENV |
| 151 | + shell: bash |
| 152 | + |
| 153 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 154 | + with: |
| 155 | + # We need to get all the git tags to make version injection work. See VERSION in Makefile for more detail. |
| 156 | + fetch-depth: 0 |
| 157 | + persist-credentials: false |
| 158 | + submodules: recursive |
| 159 | + ssh-user: ec2-user |
| 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 | + cd ${{ github.workspace }} && DOCKER_HOST=unix:///Applications/Finch/lima/data/finch/sock/finch.sock make test-e2e |
| 166 | + shell: bash |
| 167 | + |
| 168 | + # Run e2e tests with OPA authorization |
| 169 | + - name: Run opa e2e tests |
| 170 | + run: | |
| 171 | + echo "Running e2e tests with OPA authorization as ec2-user..." |
| 172 | + |
| 173 | + echo "Using DOCKER_HOST=unix:///Applications/Finch/lima/data/finch/sock/finch.sock" |
| 174 | + sudo -u ec2-user bash -c "cd ${{ github.workspace }} && DOCKER_HOST=unix:///Applications/Finch/lima/data/finch/sock/finch.sock make test-e2e-opa" |
| 175 | + shell: bash |
| 176 | + |
| 177 | + # Cleanup |
| 178 | + - name: Stop Finch VM |
| 179 | + run: | |
| 180 | + echo "Stopping Finch VM as ec2-user..." |
| 181 | + |
| 182 | + # Stop VM using ec2-user with custom environment |
| 183 | + sudo -u ec2-user bash -c "source /Users/ec2-user/.brewrc && HOME=/Users/ec2-user finch vm stop" |
| 184 | + shell: bash |
| 185 | + if: always() |
0 commit comments