|
| 1 | +name: 'Test Build Binary' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: 'read' |
| 8 | + |
| 9 | +defaults: |
| 10 | + run: |
| 11 | + shell: 'bash' |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-node-binary: |
| 15 | + name: 'Build Binary (${{ matrix.os }})' |
| 16 | + runs-on: '${{ matrix.os }}' |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + include: |
| 21 | + - os: 'ubuntu-latest' |
| 22 | + platform_name: 'linux-x64' |
| 23 | + arch: 'x64' |
| 24 | + - os: 'windows-latest' |
| 25 | + platform_name: 'win32-x64' |
| 26 | + arch: 'x64' |
| 27 | + - os: 'macos-latest' # Apple Silicon (ARM64) |
| 28 | + platform_name: 'darwin-arm64' |
| 29 | + arch: 'arm64' |
| 30 | + - os: 'macos-latest' # Intel (x64) running on ARM via Rosetta |
| 31 | + platform_name: 'darwin-x64' |
| 32 | + arch: 'x64' |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: 'Checkout' |
| 36 | + uses: 'actions/checkout@v4' |
| 37 | + |
| 38 | + - name: 'Optimize Windows Performance' |
| 39 | + if: "matrix.os == 'windows-latest'" |
| 40 | + run: | |
| 41 | + Set-MpPreference -DisableRealtimeMonitoring $true |
| 42 | + Stop-Service -Name "wsearch" -Force -ErrorAction SilentlyContinue |
| 43 | + Set-Service -Name "wsearch" -StartupType Disabled |
| 44 | + Stop-Service -Name "SysMain" -Force -ErrorAction SilentlyContinue |
| 45 | + Set-Service -Name "SysMain" -StartupType Disabled |
| 46 | + shell: 'powershell' |
| 47 | + |
| 48 | + - name: 'Set up Node.js' |
| 49 | + uses: 'actions/setup-node@v4' |
| 50 | + with: |
| 51 | + node-version-file: '.nvmrc' |
| 52 | + architecture: '${{ matrix.arch }}' |
| 53 | + cache: 'npm' |
| 54 | + |
| 55 | + - name: 'Install dependencies' |
| 56 | + run: 'npm ci' |
| 57 | + |
| 58 | + - name: 'Check Secrets' |
| 59 | + id: 'check_secrets' |
| 60 | + run: | |
| 61 | + echo "has_win_cert=${{ secrets.WINDOWS_PFX_BASE64 != '' }}" >> "$GITHUB_OUTPUT" |
| 62 | + echo "has_mac_cert=${{ secrets.MACOS_CERT_P12_BASE64 != '' }}" >> "$GITHUB_OUTPUT" |
| 63 | +
|
| 64 | + - name: 'Setup Windows SDK (Windows)' |
| 65 | + if: "matrix.os == 'windows-latest'" |
| 66 | + uses: 'microsoft/setup-msbuild@v2' |
| 67 | + |
| 68 | + - name: 'Add Signtool to Path (Windows)' |
| 69 | + if: "matrix.os == 'windows-latest'" |
| 70 | + run: | |
| 71 | + $signtoolPath = Get-ChildItem -Path "C:\Program Files (x86)\Windows Kits\10\bin" -Recurse -Filter "signtool.exe" | Sort-Object FullName -Descending | Select-Object -First 1 -ExpandProperty DirectoryName |
| 72 | + echo "Found signtool at: $signtoolPath" |
| 73 | + echo "$signtoolPath" >> $env:GITHUB_PATH |
| 74 | + shell: 'pwsh' |
| 75 | + |
| 76 | + - name: 'Setup macOS Keychain' |
| 77 | + if: "startsWith(matrix.os, 'macos') && steps.check_secrets.outputs.has_mac_cert == 'true' && github.event_name != 'pull_request'" |
| 78 | + env: |
| 79 | + BUILD_CERTIFICATE_BASE64: '${{ secrets.MACOS_CERT_P12_BASE64 }}' |
| 80 | + P12_PASSWORD: '${{ secrets.MACOS_CERT_PASSWORD }}' |
| 81 | + KEYCHAIN_PASSWORD: 'temp-password' |
| 82 | + run: | |
| 83 | + # Create the P12 file |
| 84 | + echo "$BUILD_CERTIFICATE_BASE64" | base64 --decode > certificate.p12 |
| 85 | +
|
| 86 | + # Create a temporary keychain |
| 87 | + security create-keychain -p "$KEYCHAIN_PASSWORD" build.keychain |
| 88 | + security default-keychain -s build.keychain |
| 89 | + security unlock-keychain -p "$KEYCHAIN_PASSWORD" build.keychain |
| 90 | +
|
| 91 | + # Import the certificate |
| 92 | + security import certificate.p12 -k build.keychain -P "$P12_PASSWORD" -T /usr/bin/codesign |
| 93 | +
|
| 94 | + # Allow codesign to access it |
| 95 | + security set-key-partition-list -S apple-tool:,apple: -s -k "$KEYCHAIN_PASSWORD" build.keychain |
| 96 | +
|
| 97 | + # Set Identity for build script |
| 98 | + echo "APPLE_IDENTITY=${{ secrets.MACOS_CERT_IDENTITY }}" >> "$GITHUB_ENV" |
| 99 | +
|
| 100 | + - name: 'Setup Windows Certificate' |
| 101 | + if: "matrix.os == 'windows-latest' && steps.check_secrets.outputs.has_win_cert == 'true' && github.event_name != 'pull_request'" |
| 102 | + env: |
| 103 | + PFX_BASE64: '${{ secrets.WINDOWS_PFX_BASE64 }}' |
| 104 | + PFX_PASSWORD: '${{ secrets.WINDOWS_PFX_PASSWORD }}' |
| 105 | + run: | |
| 106 | + $pfx_cert_byte = [System.Convert]::FromBase64String("$env:PFX_BASE64") |
| 107 | + $certPath = Join-Path (Get-Location) "cert.pfx" |
| 108 | + [IO.File]::WriteAllBytes($certPath, $pfx_cert_byte) |
| 109 | + echo "WINDOWS_PFX_FILE=$certPath" >> $env:GITHUB_ENV |
| 110 | + echo "WINDOWS_PFX_PASSWORD=$env:PFX_PASSWORD" >> $env:GITHUB_ENV |
| 111 | + shell: 'pwsh' |
| 112 | + |
| 113 | + - name: 'Build Binary' |
| 114 | + run: 'npm run build:binary' |
| 115 | + |
| 116 | + - name: 'Build Core Package' |
| 117 | + run: 'npm run build -w @google/gemini-cli-core' |
| 118 | + |
| 119 | + - name: 'Verify Output Exists' |
| 120 | + run: | |
| 121 | + if [ -f "dist/${{ matrix.platform_name }}/gemini" ]; then |
| 122 | + echo "Binary found at dist/${{ matrix.platform_name }}/gemini" |
| 123 | + elif [ -f "dist/${{ matrix.platform_name }}/gemini.exe" ]; then |
| 124 | + echo "Binary found at dist/${{ matrix.platform_name }}/gemini.exe" |
| 125 | + else |
| 126 | + echo "Error: Binary not found in dist/${{ matrix.platform_name }}/" |
| 127 | + ls -R dist/ |
| 128 | + exit 1 |
| 129 | + fi |
| 130 | +
|
| 131 | + - name: 'Smoke Test Binary' |
| 132 | + run: | |
| 133 | + echo "Running binary smoke test..." |
| 134 | + if [ -f "dist/${{ matrix.platform_name }}/gemini.exe" ]; then |
| 135 | + "./dist/${{ matrix.platform_name }}/gemini.exe" --version |
| 136 | + else |
| 137 | + "./dist/${{ matrix.platform_name }}/gemini" --version |
| 138 | + fi |
| 139 | +
|
| 140 | + - name: 'Run Integration Tests' |
| 141 | + if: "github.event_name != 'pull_request'" |
| 142 | + env: |
| 143 | + GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}' |
| 144 | + run: | |
| 145 | + echo "Running integration tests with binary..." |
| 146 | + if [[ "${{ matrix.os }}" == 'windows-latest' ]]; then |
| 147 | + BINARY_PATH="$(cygpath -m "$(pwd)/dist/${{ matrix.platform_name }}/gemini.exe")" |
| 148 | + else |
| 149 | + BINARY_PATH="$(pwd)/dist/${{ matrix.platform_name }}/gemini" |
| 150 | + fi |
| 151 | + echo "Using binary at $BINARY_PATH" |
| 152 | + export INTEGRATION_TEST_GEMINI_BINARY_PATH="$BINARY_PATH" |
| 153 | + npm run test:integration:sandbox:none -- --testTimeout=600000 |
| 154 | +
|
| 155 | + - name: 'Upload Artifact' |
| 156 | + uses: 'actions/upload-artifact@v4' |
| 157 | + with: |
| 158 | + name: 'gemini-cli-${{ matrix.platform_name }}' |
| 159 | + path: 'dist/${{ matrix.platform_name }}/' |
| 160 | + retention-days: 5 |
0 commit comments