ci: auto-install Flutter from cn mirror
Some checks failed
CI / Windows build (push) Has been cancelled
Some checks failed
CI / Windows build (push) Has been cancelled
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.
This commit is contained in:
@@ -31,32 +31,55 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: https://gitea.com/actions/checkout@v4
|
uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
# The runner's Actions shell often does not inherit Flutter on PATH, so
|
# Ensure Flutter is available. The runner's Actions shell does not have
|
||||||
# locate it and add it to PATH for subsequent steps. Set a system env var
|
# Flutter on PATH, so: use it if present (PATH / FLUTTER_ROOT / common
|
||||||
# FLUTTER_ROOT to your Flutter SDK dir, or add Flutter's bin to PATH.
|
# dirs), otherwise install the pinned SDK from the flutter-io.cn mirror
|
||||||
- name: Locate Flutter
|
# into a persistent dir (C:\flutter-ci) that is reused across runs.
|
||||||
|
- name: Set up Flutter
|
||||||
shell: powershell
|
shell: powershell
|
||||||
run: |
|
run: |
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$ProgressPreference = 'SilentlyContinue'
|
||||||
if (Get-Command flutter -ErrorAction SilentlyContinue) {
|
if (Get-Command flutter -ErrorAction SilentlyContinue) {
|
||||||
Write-Host "flutter already on PATH"; exit 0
|
Write-Host "flutter already on PATH"; exit 0
|
||||||
}
|
}
|
||||||
$candidates = @()
|
$candidates = @()
|
||||||
if ($env:FLUTTER_ROOT) { $candidates += (Join-Path $env:FLUTTER_ROOT 'bin') }
|
if ($env:FLUTTER_ROOT) { $candidates += (Join-Path $env:FLUTTER_ROOT 'bin') }
|
||||||
$candidates += @(
|
$candidates += @(
|
||||||
'C:\flutter\bin','C:\src\flutter\bin','C:\tools\flutter\bin','C:\dev\flutter\bin',
|
'C:\flutter-ci\flutter\bin','C:\flutter\bin','C:\src\flutter\bin',
|
||||||
"$env:USERPROFILE\flutter\bin","$env:USERPROFILE\development\flutter\bin",
|
'C:\tools\flutter\bin','C:\dev\flutter\bin',
|
||||||
"$env:LOCALAPPDATA\flutter\bin",'C:\fvm\default\bin'
|
"$env:USERPROFILE\flutter\bin","$env:LOCALAPPDATA\flutter\bin"
|
||||||
)
|
)
|
||||||
$found = $null
|
|
||||||
foreach ($c in $candidates) {
|
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
|
|
||||||
}
|
}
|
||||||
Write-Host "Found Flutter at $found"
|
# Install the pinned SDK from the China mirror into a persistent dir.
|
||||||
Add-Content -Path $env:GITHUB_PATH -Value $found
|
$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
|
||||||
|
}
|
||||||
|
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
|
- name: Flutter version
|
||||||
run: flutter --version
|
run: flutter --version
|
||||||
|
|||||||
Reference in New Issue
Block a user