From 8cc88be5f68cf891efaec47f626f33848095cd31 Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Sat, 8 Nov 2025 23:50:07 -0800 Subject: [PATCH] =?UTF-8?q?ci(workflows):=20=E6=B7=BB=E5=8A=A0Windows?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E4=BF=AE=E5=A4=8D=E6=AD=A5=E9=AA=A4=E5=88=B0?= =?UTF-8?q?CI=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加NuGet安装、长路径支持、清理构建缓存等步骤 确保Windows环境下的Flutter构建能够成功执行 --- .gitea/workflows/docker.yml | 65 +++++++++++++++++++++++++++++++++++-- fix_windows_build.ps1 | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 fix_windows_build.ps1 diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml index a2bde11..41dd38a 100644 --- a/.gitea/workflows/docker.yml +++ b/.gitea/workflows/docker.yml @@ -229,16 +229,77 @@ jobs: $env:PATH = "C:\flutter\bin;$env:PATH" 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 run: | $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 - name: Build Windows Release shell: powershell run: | - $env:PATH = "C:\flutter\bin;$env:PATH" + $env:PATH = "C:\flutter\bin;C:\;$env:PATH" flutter build windows --release - name: Upload Debug build artifacts diff --git a/fix_windows_build.ps1 b/fix_windows_build.ps1 new file mode 100644 index 0000000..736864f --- /dev/null +++ b/fix_windows_build.ps1 @@ -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 \ No newline at end of file