ci(workflows): 添加Windows构建修复步骤到CI流程
添加NuGet安装、长路径支持、清理构建缓存等步骤 确保Windows环境下的Flutter构建能够成功执行
This commit is contained in:
parent
50f4237c74
commit
8cc88be5f6
@ -229,16 +229,77 @@ jobs:
|
|||||||
$env:PATH = "C:\flutter\bin;$env:PATH"
|
$env:PATH = "C:\flutter\bin;$env:PATH"
|
||||||
dart run build_runner build --delete-conflicting-outputs
|
dart run build_runner build --delete-conflicting-outputs
|
||||||
|
|
||||||
- name: Build Windows Debug
|
- name: Install NuGet
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
Write-Host "Installing NuGet..."
|
||||||
|
|
||||||
|
# Check if NuGet is already available
|
||||||
|
$nugetPath = Get-Command nuget -ErrorAction SilentlyContinue
|
||||||
|
if ($nugetPath) {
|
||||||
|
Write-Host "NuGet already installed: $($nugetPath.Source)"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download NuGet CLI
|
||||||
|
Write-Host "Downloading NuGet CLI..."
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "C:\nuget.exe" -TimeoutSec 120
|
||||||
|
} catch {
|
||||||
|
Write-Host "Download failed, trying alternative..."
|
||||||
|
# Try alternative download
|
||||||
|
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/v6.7.0/nuget.exe" -OutFile "C:\nuget.exe" -TimeoutSec 120
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add to PATH
|
||||||
|
$env:PATH = "C:\;$env:PATH"
|
||||||
|
Add-Content -Path $env:GITHUB_PATH -Value "C:\"
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
$nugetVersion = C:\nuget.exe help | Select-String -Pattern "NuGet Version" | Select-Object -First 1
|
||||||
|
Write-Host "NuGet installed: $nugetVersion"
|
||||||
|
|
||||||
|
- name: Fix long paths
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
Write-Host "Enabling long path support..."
|
||||||
|
|
||||||
|
# Enable long paths in Windows
|
||||||
|
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -Type DWORD -Force
|
||||||
|
|
||||||
|
# Also set for current user
|
||||||
|
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\AppModel\StateRepository\Cache\Package\Data\" -Name "LongPathsEnabled" -Value 1 -Type DWORD -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
Write-Host "Long path support enabled"
|
||||||
|
|
||||||
|
- name: Clean build cache
|
||||||
shell: powershell
|
shell: powershell
|
||||||
run: |
|
run: |
|
||||||
$env:PATH = "C:\flutter\bin;$env:PATH"
|
$env:PATH = "C:\flutter\bin;$env:PATH"
|
||||||
|
Write-Host "Cleaning build cache..."
|
||||||
|
flutter clean
|
||||||
|
|
||||||
|
Write-Host "Removing old build directories..."
|
||||||
|
if (Test-Path "build") {
|
||||||
|
Remove-Item -Path "build" -Recurse -Force
|
||||||
|
}
|
||||||
|
if (Test-Path "windows") {
|
||||||
|
Remove-Item -Path "windows" -Recurse -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Recreating Windows project..."
|
||||||
|
flutter create --platforms=windows .
|
||||||
|
|
||||||
|
- name: Build Windows Debug
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
$env:PATH = "C:\flutter\bin;C:\;$env:PATH"
|
||||||
flutter build windows
|
flutter build windows
|
||||||
|
|
||||||
- name: Build Windows Release
|
- name: Build Windows Release
|
||||||
shell: powershell
|
shell: powershell
|
||||||
run: |
|
run: |
|
||||||
$env:PATH = "C:\flutter\bin;$env:PATH"
|
$env:PATH = "C:\flutter\bin;C:\;$env:PATH"
|
||||||
flutter build windows --release
|
flutter build windows --release
|
||||||
|
|
||||||
- name: Upload Debug build artifacts
|
- name: Upload Debug build artifacts
|
||||||
|
|||||||
64
fix_windows_build.ps1
Normal file
64
fix_windows_build.ps1
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
# Windows 构建修复脚本
|
||||||
|
# 以管理员身份运行
|
||||||
|
|
||||||
|
Write-Host "=== Windows Flutter 构建修复 ===" -ForegroundColor Green
|
||||||
|
|
||||||
|
# 1. 安装 NuGet
|
||||||
|
Write-Host "`n1. 安装 NuGet..." -ForegroundColor Yellow
|
||||||
|
$nugetPath = "C:\nuget.exe"
|
||||||
|
if (-not (Test-Path $nugetPath)) {
|
||||||
|
try {
|
||||||
|
Write-Host "下载 NuGet..."
|
||||||
|
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $nugetPath
|
||||||
|
$env:PATH = "C:\;$env:PATH"
|
||||||
|
Write-Host "NuGet 安装成功" -ForegroundColor Green
|
||||||
|
} catch {
|
||||||
|
Write-Host "NuGet 下载失败: $_" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "NuGet 已存在" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
# 2. 启用长路径支持
|
||||||
|
Write-Host "`n2. 启用长路径支持..." -ForegroundColor Yellow
|
||||||
|
try {
|
||||||
|
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -Type DWORD -Force
|
||||||
|
Write-Host "长路径支持已启用" -ForegroundColor Green
|
||||||
|
} catch {
|
||||||
|
Write-Host "长路径设置失败: $_" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
|
||||||
|
# 3. 清理构建缓存
|
||||||
|
Write-Host "`n3. 清理构建缓存..." -ForegroundColor Yellow
|
||||||
|
if (Test-Path "build") {
|
||||||
|
Remove-Item -Path "build" -Recurse -Force
|
||||||
|
Write-Host "Build 目录已清理" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Test-Path "windows") {
|
||||||
|
Remove-Item -Path "windows" -Recurse -Force
|
||||||
|
Write-Host "Windows 目录已清理" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
# 4. 重新创建 Windows 项目
|
||||||
|
Write-Host "`n4. 重新创建 Windows 项目..." -ForegroundColor Yellow
|
||||||
|
flutter create --platforms=windows .
|
||||||
|
|
||||||
|
# 5. 获取依赖
|
||||||
|
Write-Host "`n5. 获取依赖..." -ForegroundColor Yellow
|
||||||
|
flutter pub get
|
||||||
|
|
||||||
|
# 6. 构建 Debug 版本
|
||||||
|
Write-Host "`n6. 构建 Debug 版本..." -ForegroundColor Yellow
|
||||||
|
flutter build windows
|
||||||
|
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "`n=== 构建成功! ===" -ForegroundColor Green
|
||||||
|
Write-Host "输出目录: build\windows\runner\Debug\" -ForegroundColor Cyan
|
||||||
|
} else {
|
||||||
|
Write-Host "`n=== 构建失败 ===" -ForegroundColor Red
|
||||||
|
Write-Host "请检查错误信息并尝试手动修复" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "`n修复完成!" -ForegroundColor Green
|
||||||
Loading…
x
Reference in New Issue
Block a user