From 74ed001d76e6fb4194c60f80475705c4459a64fb Mon Sep 17 00:00:00 2001 From: Akiba So Date: Sun, 21 Jun 2026 04:18:54 +0800 Subject: [PATCH] ci: auto-install Flutter from cn mirror Run 8: Flutter is not on the runner (PATH, FLUTTER_ROOT and common dirs are all empty). Make the workflow self-contained: if Flutter is not found, download the pinned 3.41.4 SDK from storage.flutter-io.cn into a persistent C:\flutter-ci dir (reused on later runs) and add it to PATH. --- .gitea/workflows/ci.yml | 51 ++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 00b960d..df5bd86 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -31,32 +31,55 @@ jobs: - name: Checkout uses: https://gitea.com/actions/checkout@v4 - # The runner's Actions shell often does not inherit Flutter on PATH, so - # locate it and add it to PATH for subsequent steps. Set a system env var - # FLUTTER_ROOT to your Flutter SDK dir, or add Flutter's bin to PATH. - - name: Locate Flutter + # 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\bin','C:\src\flutter\bin','C:\tools\flutter\bin','C:\dev\flutter\bin', - "$env:USERPROFILE\flutter\bin","$env:USERPROFILE\development\flutter\bin", - "$env:LOCALAPPDATA\flutter\bin",'C:\fvm\default\bin' + '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" ) - $found = $null foreach ($c in $candidates) { - if ($c -and (Test-Path (Join-Path $c 'flutter.bat'))) { $found = $c; break } + 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 + } } - if (-not $found) { - Write-Error "Flutter not found on PATH or in common locations. Add Flutter's bin to the runner PATH, or set repo variable FLUTTER_ROOT to your Flutter SDK directory." - exit 1 + # 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 + for ($i = 1; $i -le 3 -and -not $ok; $i++) { + try { Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing; $ok = $true } + catch { Write-Host "download 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 } - Write-Host "Found Flutter at $found" - Add-Content -Path $env:GITHUB_PATH -Value $found + 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