|
| 1 | +name: samcli-vm |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + schedule: |
| 8 | + - cron: '0 8 * * *' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +env: |
| 12 | + GO_VERSION: '1.24.x' |
| 13 | + PYTHON_VERSION: '3.11' |
| 14 | + PYTHON_BINARY: 'python3.11' |
| 15 | + AWS_DEFAULT_REGION: "${{ secrets.REGION }}" |
| 16 | + BY_CANARY: true # allows full testing |
| 17 | + SAM_CLI_DEV: 1 |
| 18 | + SAM_CLI_TELEMETRY: 0 |
| 19 | + DOCKER_HOST: unix:///Applications/Finch/lima/data/finch/sock/finch.sock |
| 20 | + DOCKER_CONFIG: /Users/ec2-user/.finch |
| 21 | + |
| 22 | +permissions: |
| 23 | + id-token: write |
| 24 | + contents: read |
| 25 | + |
| 26 | +jobs: |
| 27 | + samcli-vm-test: |
| 28 | + runs-on: codebuild-finch-daemon-arm64-2-instance-${{ github.run_id }}-${{ github.run_attempt }} |
| 29 | + steps: |
| 30 | + |
| 31 | + - name: Clean macOS runner workspace |
| 32 | + run: | |
| 33 | + rm -rf ${{ github.workspace }}/* |
| 34 | +
|
| 35 | + - name: Configure Git for ec2-user |
| 36 | + run: | |
| 37 | + git config --global --add safe.directory "*" |
| 38 | + shell: bash |
| 39 | + |
| 40 | + - name: Set up Go |
| 41 | + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 |
| 42 | + with: |
| 43 | + go-version: ${{ env.GO_VERSION }} |
| 44 | + cache: false |
| 45 | + |
| 46 | + - name: Configure Go for ec2-user |
| 47 | + run: | |
| 48 | + chown -R ec2-user:staff $GOPATH || true |
| 49 | + chown -R ec2-user:staff $RUNNER_TOOL_CACHE/go || true |
| 50 | +
|
| 51 | + - name: Install Rosetta 2 |
| 52 | + run: su ec2-user -c 'echo "A" | /usr/sbin/softwareupdate --install-rosetta --agree-to-license || true' |
| 53 | + |
| 54 | + - name: Set up Python |
| 55 | + uses: actions/setup-python@v5 |
| 56 | + with: |
| 57 | + python-version: ${{ env.PYTHON_VERSION }} |
| 58 | + |
| 59 | + - name: Configure Python for ec2-user |
| 60 | + run: | |
| 61 | + # Make Python accessible to ec2-user |
| 62 | + chown -R ec2-user:staff $(${{ env.PYTHON_BINARY }} -c "import site; print(site.USER_BASE)") || true |
| 63 | + # Or symlink to ec2-user's PATH |
| 64 | + ln -sf $(which ${{ env.PYTHON_BINARY }}) /usr/local/bin/${{ env.PYTHON_BINARY }} || true |
| 65 | +
|
| 66 | + - name: Configure Homebrew for ec2-user |
| 67 | + run: | |
| 68 | + echo "Creating .brewrc file for ec2-user..." |
| 69 | + cat > /Users/ec2-user/.brewrc << 'EOF' |
| 70 | + # Homebrew environment setup |
| 71 | + export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH" |
| 72 | + export HOMEBREW_PREFIX="/opt/homebrew" |
| 73 | + export HOMEBREW_CELLAR="/opt/homebrew/Cellar" |
| 74 | + export HOMEBREW_REPOSITORY="/opt/homebrew" |
| 75 | + export HOMEBREW_NO_AUTO_UPDATE=1 |
| 76 | + EOF |
| 77 | + chown ec2-user:staff /Users/ec2-user/.brewrc |
| 78 | +
|
| 79 | + # Fix Homebrew permissions |
| 80 | + echo "Setting permissions for Homebrew directories..." |
| 81 | + mkdir -p /opt/homebrew/Cellar |
| 82 | + chown -R ec2-user:staff /opt/homebrew |
| 83 | + shell: bash |
| 84 | + |
| 85 | + - name: Install dependencies |
| 86 | + run: | |
| 87 | + echo "Installing dependencies as ec2-user..." |
| 88 | + su ec2-user -c 'source /Users/ec2-user/.brewrc && brew install lz4 automake autoconf libtool yq' |
| 89 | + shell: bash |
| 90 | + |
| 91 | + - name: Checkout finch-daemon repo |
| 92 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 93 | + with: |
| 94 | + fetch-depth: 0 |
| 95 | + persist-credentials: false |
| 96 | + submodules: recursive |
| 97 | + |
| 98 | + - name: Configure workspace for ec2-user |
| 99 | + run: | |
| 100 | + chown -R ec2-user:staff ${{ github.workspace }} |
| 101 | +
|
| 102 | + - name: Install Finch |
| 103 | + run: | |
| 104 | + echo "Installing Finch as ec2-user..." |
| 105 | + su ec2-user -c 'source /Users/ec2-user/.brewrc && brew install finch --cask' |
| 106 | + su ec2-user -c 'source /Users/ec2-user/.brewrc && brew list | grep finch || echo "finch not installed"' |
| 107 | + mkdir -p /private/var/run/finch-lima |
| 108 | + cat /etc/passwd |
| 109 | + chown ec2-user:daemon /private/var/run/finch-lima |
| 110 | + shell: bash |
| 111 | + |
| 112 | + - name: Build binaries |
| 113 | + run: | |
| 114 | + echo "Building cross architecture binaries..." |
| 115 | + su ec2-user -c 'cd ${{ github.workspace }} && STATIC=1 GOPROXY=direct GOOS=linux GOARCH=arm64 make' |
| 116 | + su ec2-user -c 'finch vm remove -f' || true |
| 117 | + cp -f ${{ github.workspace }}/bin/finch-daemon /Applications/Finch/finch-daemon/finch-daemon |
| 118 | + # Restart finch-daemon with new binary |
| 119 | + su ec2-user -c 'finch vm stop' || true |
| 120 | + su ec2-user -c 'finch vm start' || true |
| 121 | + shell: bash |
| 122 | + |
| 123 | + - name: Check Finch version |
| 124 | + run: | |
| 125 | + echo "Initializing VM and checking version..." |
| 126 | + # Clean up any leftover network state |
| 127 | + sudo pkill -f socket_vmnet || true |
| 128 | + sudo rm -f /private/var/run/finch-lima/*.sock || true |
| 129 | + su ec2-user -c 'finch vm init' |
| 130 | + sleep 5 # Wait for services to be ready |
| 131 | + echo "Checking Finch version..." |
| 132 | + su ec2-user -c 'LIMA_HOME=/Applications/Finch/lima/data /Applications/Finch/lima/bin/limactl shell finch curl --unix-socket /var/run/finch.sock -X GET http:/v1.43/version' |
| 133 | + shell: bash |
| 134 | + |
| 135 | + - name: Configure AWS credentials |
| 136 | + uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df # v4.2.1 |
| 137 | + with: |
| 138 | + role-to-assume: ${{ secrets.SAMCLI_VM_ROLE_SYNC }} |
| 139 | + role-session-name: samcli-finch-vm-sequential-tests |
| 140 | + aws-region: ${{ secrets.REGION }} |
| 141 | + |
| 142 | + - name: Install Docker CLI for SAM CLI compatibility |
| 143 | + run: | |
| 144 | + echo "Checking Docker CLI installation..." |
| 145 | + if ! su ec2-user -c 'which docker' > /dev/null 2>&1; then |
| 146 | + echo "Installing Docker CLI..." |
| 147 | + su ec2-user -c 'source /Users/ec2-user/.brewrc && brew install --formula docker' |
| 148 | + else |
| 149 | + echo "Docker CLI already installed" |
| 150 | + fi |
| 151 | + shell: bash |
| 152 | + |
| 153 | + - name: Checkout SAM CLI |
| 154 | + uses: actions/checkout@v4 |
| 155 | + with: |
| 156 | + repository: aws/aws-sam-cli |
| 157 | + submodules: recursive |
| 158 | + path: aws-sam-cli |
| 159 | + |
| 160 | + - name: Set up SAM CLI from source |
| 161 | + run: | |
| 162 | + # Move to ec2-user home and change ownership |
| 163 | + sudo rm -rf /Users/ec2-user/aws-sam-cli || true |
| 164 | + sudo mv aws-sam-cli /Users/ec2-user/aws-sam-cli |
| 165 | + sudo chown -R ec2-user:staff /Users/ec2-user/aws-sam-cli |
| 166 | +
|
| 167 | + # Install and setup (use full path) |
| 168 | + su ec2-user -c 'cd /Users/ec2-user/aws-sam-cli && ${{ env.PYTHON_BINARY }} -m pip install --upgrade pip --user' |
| 169 | + su ec2-user -c 'cd /Users/ec2-user/aws-sam-cli && SAM_CLI_DEV=1 ${{ env.PYTHON_BINARY }} -m pip install -e ".[dev]" --user' |
| 170 | + su ec2-user -c 'cd /Users/ec2-user/aws-sam-cli && export PATH="/Users/ec2-user/Library/Python/${{ env.PYTHON_VERSION }}/bin:$PATH" && samdev --version' |
| 171 | + shell: bash |
| 172 | + |
| 173 | + - name: Run unit tests |
| 174 | + continue-on-error: true |
| 175 | + run: ./scripts/samcli-vm/run-unit-tests.sh |
| 176 | + |
| 177 | + - name: Run sync tests |
| 178 | + continue-on-error: true |
| 179 | + run: ./scripts/samcli-vm/run-sync-tests.sh |
| 180 | + |
| 181 | + - name: Run package tests |
| 182 | + continue-on-error: true |
| 183 | + run: ./scripts/samcli-vm/run-package-tests.sh |
| 184 | + |
| 185 | + - name: Run start-api tests |
| 186 | + continue-on-error: true |
| 187 | + run: ./scripts/samcli-vm/run-start-api-tests.sh |
| 188 | + |
| 189 | + - name: Run start-lambda tests |
| 190 | + continue-on-error: true |
| 191 | + run: ./scripts/samcli-vm/run-start-lambda-tests.sh |
| 192 | + |
| 193 | + - name: Patch SAM CLI for Docker image cleanup |
| 194 | + continue-on-error: true |
| 195 | + run: | |
| 196 | + # Apply git patch to handle ImageNotFound exceptions for all Docker tests |
| 197 | + su ec2-user -c 'cd /Users/ec2-user/aws-sam-cli && git apply ${{ github.workspace }}/scripts/samcli-vm/invoke-teardown.patch' |
| 198 | + shell: bash |
| 199 | + |
| 200 | + - name: Run invoke tests |
| 201 | + continue-on-error: true |
| 202 | + run: ./scripts/samcli-vm/run-invoke-tests.sh |
| 203 | + |
| 204 | + # ensuring resources are clean post-test |
| 205 | + cleanup: |
| 206 | + runs-on: ubuntu-latest |
| 207 | + needs: samcli-vm-test |
| 208 | + if: always() |
| 209 | + steps: |
| 210 | + - name: Checkout repository |
| 211 | + uses: actions/checkout@v4 |
| 212 | + |
| 213 | + - name: Configure AWS credentials |
| 214 | + uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df |
| 215 | + with: |
| 216 | + role-to-assume: ${{ secrets.SAMCLI_VM_ROLE_SYNC }} |
| 217 | + role-session-name: cleanup |
| 218 | + aws-region: ${{ secrets.REGION }} |
| 219 | + |
| 220 | + - name: Comprehensive AWS resource cleanup |
| 221 | + timeout-minutes: 10 |
| 222 | + run: ./scripts/cleanup-aws-resources.sh |
0 commit comments