From ba5660c1cb7c5f31a9fb4813904a7e8323ad7bed Mon Sep 17 00:00:00 2001 From: Ponshu Developer Date: Sat, 11 Apr 2026 09:45:16 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20release=5Fto=5Fgitea.ps1=E3=81=ABAPK?= =?UTF-8?q?=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pubspec.yamlのversionとAPKの埋め込みversionNameが異なる場合は エラーで中断する。「バージョン上げ前ビルド→リリース」ミスを防ぐ。 Co-Authored-By: Claude Sonnet 4.6 --- release_to_gitea.ps1 | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/release_to_gitea.ps1 b/release_to_gitea.ps1 index 731d88d..57c7aaf 100644 --- a/release_to_gitea.ps1 +++ b/release_to_gitea.ps1 @@ -36,10 +36,34 @@ if ($apkFiles.Count -eq 0) { Write-Error "No APK files in: $ApkDir"; exit 1 } # Read version from pubspec.yaml $publine = Get-Content (Join-Path $PSScriptRoot "pubspec.yaml") | Where-Object { $_ -match "^version:" } | Select-Object -First 1 $version = if ($publine -match "version:\s*(\S+)") { $Matches[1].Split("+")[0] } else { "1.0.0" } -$dateStr = (Split-Path $ApkDir -Leaf).Substring(0, 10) +$buildNum = if ($publine -match "version:\s*[^+]+\+(\S+)") { $Matches[1] } else { "0" } +$dateStr = Get-Date -Format "yyyy-MM-dd" $tagName = "v$version" $relName = "Ponshu Room $version ($dateStr)" +# APKの埋め込みバージョンと pubspec.yaml が一致するか確認 +Write-Host " Checking APK version matches pubspec ($version+$buildNum)..." -ForegroundColor Gray +$firstApk = $apkFiles | Select-Object -First 1 +$apkInfo = & flutter.bat --version 2>$null +# aapt2 でバージョン確認(利用可能な場合) +$aapt2 = Get-ChildItem "$env:LOCALAPPDATA\Android\Sdk\build-tools" -Recurse -Filter "aapt2.exe" -ErrorAction SilentlyContinue | Sort-Object FullName -Descending | Select-Object -First 1 -ExpandProperty FullName +if ($aapt2) { + $apkDump = & $aapt2 dump badging $firstApk.FullName 2>$null | Select-String "versionName|versionCode" + $apkVersion = if ($apkDump -match "versionName='([^']+)'") { $Matches[1] } else { $null } + $apkBuild = if ($apkDump -match "versionCode='([^']+)'") { $Matches[1] } else { $null } + if ($apkVersion -and $apkVersion -ne $version) { + Write-Host "" + Write-Host " [ERROR] APK version mismatch!" -ForegroundColor Red + Write-Host " APK contains : $apkVersion (build $apkBuild)" -ForegroundColor Red + Write-Host " pubspec.yaml : $version+$buildNum" -ForegroundColor Red + Write-Host " -> Rebuild APKs after version bump, then retry." -ForegroundColor Yellow + exit 1 + } + Write-Host " OK: APK version = $apkVersion (build $apkBuild)" -ForegroundColor Green +} else { + Write-Host " (aapt2 not found, skipping version check)" -ForegroundColor DarkGray +} + Write-Host "================================================" -ForegroundColor Cyan Write-Host " Ponshu Room - Gitea Auto Release" -ForegroundColor Cyan Write-Host "================================================" -ForegroundColor Cyan