name: CI on: push: branches: [main] tags: ["v*"] pull_request: branches: [main] workflow_dispatch: # Targets a self-hosted Windows runner inside mainland China. See README # "Continuous integration" for runner prerequisites. Key points: # * github.com is unreachable here, so the checkout action is pulled from the # gitea.com mirror. If gitea.com is also unreachable, use the manual # checkout fallback below (it clones from your own Gitea instance). # * Flutter must be pre-installed on the runner (the dev machine). We do NOT # download the SDK. # * pub/Flutter use the flutter-io.cn mirrors; the sqlite3 native binary is # vendored (vendor/sqlite3/), so neither is downloaded from GitHub. # * The flutter_onnxruntime plugin downloads the ONNX Runtime native lib from # GitHub during the Windows build; we route that through the local proxy. env: PUB_HOSTED_URL: https://pub.flutter-io.cn FLUTTER_STORAGE_BASE_URL: https://storage.flutter-io.cn jobs: windows: name: Windows build runs-on: windows-latest steps: - name: Checkout uses: https://gitea.com/actions/checkout@v4 # Ensure Flutter is available. The runner's Actions shell does not have # Flutter on PATH, so: use it if present (PATH / FLUTTER_ROOT / common # dirs), otherwise install the pinned SDK from the flutter-io.cn mirror # into a persistent dir (C:\flutter-ci) that is reused across runs. - name: Set up Flutter shell: powershell run: | $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' if (Get-Command flutter -ErrorAction SilentlyContinue) { Write-Host "flutter already on PATH"; exit 0 } $candidates = @() if ($env:FLUTTER_ROOT) { $candidates += (Join-Path $env:FLUTTER_ROOT 'bin') } $candidates += @( 'C:\flutter-ci\flutter\bin','C:\flutter\bin','C:\src\flutter\bin', 'C:\tools\flutter\bin','C:\dev\flutter\bin', "$env:USERPROFILE\flutter\bin","$env:LOCALAPPDATA\flutter\bin" ) foreach ($c in $candidates) { if ($c -and (Test-Path (Join-Path $c 'flutter.bat'))) { Write-Host "Found Flutter at $c" Add-Content -Path $env:GITHUB_PATH -Value $c exit 0 } } # Install the pinned SDK from the China mirror into a persistent dir. $root = 'C:\flutter-ci' $bin = Join-Path $root 'flutter\bin' if (-not (Test-Path (Join-Path $bin 'flutter.bat'))) { $url = 'https://storage.flutter-io.cn/flutter_infra_release/releases/stable/windows/flutter_windows_3.41.4-stable.zip' $zip = Join-Path $env:TEMP 'flutter_sdk.zip' New-Item -ItemType Directory -Force -Path $root | Out-Null Write-Host "Downloading Flutter SDK from $url" $ok = $false # curl.exe (bundled on Windows 10+) streams to disk and is far # faster than Invoke-WebRequest for a ~1GB file. Fall back to IWR. $curl = "$env:SystemRoot\System32\curl.exe" if (Test-Path $curl) { & $curl -L --fail --retry 3 --retry-delay 5 -o $zip $url if ($LASTEXITCODE -eq 0 -and (Test-Path $zip)) { $ok = $true } else { Write-Host "curl download failed (exit $LASTEXITCODE), falling back" } } if (-not $ok) { for ($i = 1; $i -le 3 -and -not $ok; $i++) { try { Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing; $ok = $true } catch { Write-Host "IWR attempt $i failed: $_"; Start-Sleep 5 } } } if (-not $ok) { Write-Error "Failed to download Flutter SDK"; exit 1 } Write-Host "Extracting to $root (this is slow on first run)" Expand-Archive -Path $zip -DestinationPath $root -Force Remove-Item $zip -Force } if (-not (Test-Path (Join-Path $bin 'flutter.bat'))) { Write-Error "Flutter install failed"; exit 1 } Write-Host "Flutter ready at $bin" Add-Content -Path $env:GITHUB_PATH -Value $bin - name: Flutter version run: flutter --version - name: Install dependencies run: flutter pub get # Quality gates run but never block the build, so a usable .exe is always # produced even if a different toolchain version reports new lints. - name: Format check (non-blocking) continue-on-error: true run: dart format --output=none --set-exit-if-changed lib test - name: Analyze (non-blocking) continue-on-error: true run: flutter analyze - name: Test (non-blocking) continue-on-error: true run: flutter test --reporter expanded - name: Enable Windows desktop run: flutter config --enable-windows-desktop # CMake's file(DOWNLOAD) honours these proxy vars when fetching ONNX # Runtime. Defaults to the local clash/v2ray proxy; override with repo # secrets HTTP_PROXY / HTTPS_PROXY if yours differs. Install ONNX Runtime # system-wide to skip the download entirely. - name: Build Windows release env: HTTP_PROXY: http://127.0.0.1:7890 HTTPS_PROXY: http://127.0.0.1:7890 http_proxy: http://127.0.0.1:7890 https_proxy: http://127.0.0.1:7890 run: flutter build windows --release - name: Show build output shell: powershell run: Get-ChildItem build\windows\x64\runner\Release - name: Package artifact shell: powershell run: Compress-Archive -Path "build/windows/x64/runner/Release/*" -DestinationPath "badnote-windows-x64.zip" -Force - name: Upload artifact (best-effort) continue-on-error: true uses: https://gitea.com/actions/upload-artifact@v3 with: name: badnote-windows-x64 path: badnote-windows-x64.zip if-no-files-found: warn