File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -151,14 +151,26 @@ jobs:
151151 # 安装 fastforge
152152 - name : Install fastforge
153153 run : dart pub global activate fastforge
154-
155154 # 获取 Flutter 版本号
156- - name : Get Flutter version
155+ - name : Get Flutter app version from pubspec.yaml
157156 id : get_version
157+ shell : pwsh
158158 run : |
159- $VERSION = (Get-Content pubspec.yaml | Select-String "version:" | ForEach-Object { $_ -replace "version:\s*", "" } | ForEach-Object { $_ -replace "\+.*", "" })
160- echo "Version: $VERSION"
161- echo "version=$VERSION" >> $env:GITHUB_OUTPUT
159+ $lines = Get-Content pubspec.yaml
160+ foreach ($line in $lines) {
161+ # 只匹配以 "version:" 开头(允许前导空格最多0个,即顶层字段)
162+ if ($line -match '^\s*version:\s*(\S+)') {
163+ $fullVersion = $matches[1] -replace '[\'"]', '' # 去掉引号
164+ # 可选:只取主版本(不含 build number)
165+ # $mainVersion = $fullVersion -replace '\+.*', ''
166+ # echo "version=$mainVersion" >> $env:GITHUB_OUTPUT
167+ echo "version=$fullVersion" >> $env:GITHUB_OUTPUT
168+ Write-Host "✅ Extracted version: $fullVersion"
169+ exit 0
170+ }
171+ }
172+ Write-Error "❌ No top-level 'version:' found in pubspec.yaml"
173+ exit 1
162174 # 使用 fastforge 打包 Windows exe
163175 - name : Package Windows exe
164176 run : fastforge package --platform windows --targets exe
You can’t perform that action at this time.
0 commit comments