Files
BadNote/.gitea/workflows/ci.yml
Akiba So 5dbef7c986
Some checks failed
CI / Windows build (push) Failing after 7m12s
ci: pin sqlite3 + pre-fetch onnxruntime offline
Run 11 reached the build and revealed two issues:
- Runner re-resolved sqlite3 to 3.3.3 (cn mirror), mismatching the
  vendored 3.3.2 binary hash. Pin it via dependency_overrides.
- flutter_onnxruntime's github download of ONNX Runtime failed.
  Pre-fetch it via a China-accessible proxy into the plugin's
  expected build path so it skips the download and bundles the dll.
2026-06-21 05:40:00 +08:00

173 lines
7.6 KiB
YAML

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
# The flutter_onnxruntime plugin downloads the ONNX Runtime native lib
# from github.com during the build, which is blocked here. Pre-place the
# extracted SDK where the plugin expects it (via a China-accessible GitHub
# proxy) so it skips the download and still bundles onnxruntime.dll.
- name: Pre-fetch ONNX Runtime
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
$ver = 'onnxruntime-win-x64-1.22.0'
$dst = 'build\windows\x64\plugins\flutter_onnxruntime\onnxruntime'
$marker = Join-Path $dst "$ver\include\onnxruntime_cxx_api.h"
if (Test-Path $marker) { Write-Host "ONNX Runtime already present"; exit 0 }
New-Item -ItemType Directory -Force -Path $dst | Out-Null
$zip = Join-Path $env:TEMP 'ort.zip'
$gh = "github.com/microsoft/onnxruntime/releases/download/v1.22.0/$ver.zip"
$urls = @("https://gh-proxy.com/https://$gh", "https://ghfast.top/https://$gh", "https://$gh")
$curl = "$env:SystemRoot\System32\curl.exe"
$ok = $false
foreach ($u in $urls) {
Write-Host "Fetching ONNX Runtime: $u"
& $curl -L --fail --retry 2 --retry-delay 5 -o $zip $u
if ($LASTEXITCODE -eq 0 -and (Test-Path $zip)) { $ok = $true; break }
Write-Host " failed (exit $LASTEXITCODE)"
}
if (-not $ok) { Write-Error "Failed to fetch ONNX Runtime from all mirrors"; exit 1 }
Expand-Archive -Path $zip -DestinationPath $dst -Force
Remove-Item $zip -Force
if (-not (Test-Path $marker)) { Write-Error "ONNX Runtime not in expected layout"; exit 1 }
Write-Host "ONNX Runtime ready at $dst\$ver"
# Proxy vars are kept as a fallback in case the pre-fetch above is bypassed
# (CMake's file(DOWNLOAD) honours them).
- 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