279 lines
14 KiB
PowerShell
279 lines
14 KiB
PowerShell
# tools/Publish-Release.ps1
|
|
# Everything2Everything 자동화 릴리즈 배포 스크립트 (Forgejo git.chanpaca.net 연동)
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory = $true, HelpMessage = "릴리즈 버전 (예: 1.0.6)")]
|
|
[ValidatePattern('^\d+\.\d+\.\d+$')]
|
|
[string]$Version,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$ReleaseNotes = "TDD RED 체계 및 초엄격 디자인 감사 적용, UI 정렬/패딩/빈상태 결함 수정",
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$ForgejoHost = "https://git.chanpaca.net",
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$ForgejoOwner = "yunchan",
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$ForgejoRepo = "Everything2Everything",
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[switch]$SkipTests,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[switch]$DryRun
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$ProgressPreference = 'SilentlyContinue'
|
|
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
|
$RootDir = Split-Path -Parent $ScriptDir
|
|
$Tag = "v$Version"
|
|
$FourPartVersion = "$Version.0"
|
|
|
|
function Import-EnvFile {
|
|
param([string]$Path)
|
|
if (Test-Path $Path) {
|
|
Get-Content $Path | Where-Object { $_ -match '^\s*([^#=\s]+)\s*=\s*(.*)$' } | ForEach-Object {
|
|
$key = $matches[1].Trim()
|
|
$val = $matches[2].Trim().Trim('"').Trim("'")
|
|
if (-not [string]::IsNullOrEmpty($key) -and -not [Environment]::GetEnvironmentVariable($key)) {
|
|
[Environment]::SetEnvironmentVariable($key, $val, 'Process')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Import-EnvFile (Join-Path $RootDir '.env')
|
|
|
|
# Forgejo 인증은 .gitignore 된 .env 의 FORGEJO_TOKEN 으로만 받는다 (스크립트에 자격증명을 두지 않는다).
|
|
# 몇 분짜리 빌드를 돌리기 전에 먼저 확인한다.
|
|
if (-not $env:FORGEJO_TOKEN -and -not $DryRun) {
|
|
Write-Error "FORGEJO_TOKEN 이 없습니다. 저장소 루트 .env 에 FORGEJO_TOKEN=<액세스 토큰> 을 넣으세요. (Forgejo → 설정 → 애플리케이션 → 액세스 토큰, 권한: write:repository)"
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "==========================================================" -ForegroundColor Cyan
|
|
Write-Host " Everything2Everything 릴리즈 파이프라인" -ForegroundColor Cyan
|
|
Write-Host " 버전: $Version (Tag: $Tag, Manifest: $FourPartVersion)" -ForegroundColor Cyan
|
|
Write-Host " 대상: $ForgejoHost/$ForgejoOwner/$ForgejoRepo" -ForegroundColor Cyan
|
|
Write-Host "==========================================================" -ForegroundColor Cyan
|
|
|
|
# Native command failures do not obey ErrorActionPreference by themselves.
|
|
function Invoke-GitChecked {
|
|
param([Parameter(ValueFromRemainingArguments = $true)][string[]]$GitArguments)
|
|
$result = & git @GitArguments
|
|
if ($LASTEXITCODE -ne 0) { throw "git 작업 실패: $($GitArguments -join ' ') (exit $LASTEXITCODE)" }
|
|
return $result
|
|
}
|
|
|
|
# Release only committed source; never silently omit dirty application code.
|
|
Push-Location $RootDir
|
|
try {
|
|
$dirty = git status --porcelain
|
|
if ($LASTEXITCODE -ne 0) { throw "Git 상태 확인 실패" }
|
|
if ($dirty) { throw "미커밋 변경사항이 있습니다. 릴리즈할 코드를 먼저 커밋하세요." }
|
|
$branch = Invoke-GitChecked symbolic-ref --quiet --short HEAD
|
|
if (-not $branch) { throw "분리된 HEAD에서는 릴리즈할 수 없습니다." }
|
|
$localTag = Invoke-GitChecked tag -l $Tag
|
|
$remoteTag = git ls-remote --tags forgejo "refs/tags/$Tag" "refs/tags/$Tag^{}"
|
|
if ($LASTEXITCODE -ne 0) { throw "원격 태그 확인 실패" }
|
|
if ($localTag -or $remoteTag) { throw "이미 존재하는 태그: $Tag. 새 버전을 사용하세요." }
|
|
if ($DryRun) {
|
|
Write-Host "DryRun: 변경 없이 사전 검사만 완료. 테스트·버전 변경·빌드·게시를 실행하지 않았습니다."
|
|
return
|
|
}
|
|
} finally { Pop-Location }
|
|
|
|
# ── Gate 1: 테스트 스위트 100% 통과 검증 ────────────────────────────────
|
|
if (-not $SkipTests) {
|
|
Write-Host "`n[Gate 1] TDD 테스트 스위트 전체 실행 중..." -ForegroundColor Yellow
|
|
$testResult = dotnet test (Join-Path $RootDir "src/Everything2Everything.Tests/Everything2Everything.Tests.csproj") -c Release
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "테스트 스위트 실행 실패! 릴리즈가 중단되었습니다."
|
|
exit 1
|
|
}
|
|
Write-Host "✅ 테스트 스위트 100% 통과 (0 실패)" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "`n[Gate 1] 테스트 건너뜀 (-SkipTests 플래그)" -ForegroundColor DarkGray
|
|
}
|
|
|
|
# ── Gate 2: 버전 동기화 ──────────────────────────────────────────────
|
|
Write-Host "`n[Gate 2] 버전 번호 동기화 중..." -ForegroundColor Yellow
|
|
|
|
# 1. Package.appxmanifest
|
|
$manifestPath = Join-Path $RootDir "packaging/Package.appxmanifest"
|
|
if (Test-Path $manifestPath) {
|
|
$xml = [xml](Get-Content $manifestPath -Raw)
|
|
$identity = $xml.Package.Identity
|
|
if ($identity) {
|
|
$oldVer = $identity.Version
|
|
$identity.Version = $FourPartVersion
|
|
$xml.Save($manifestPath)
|
|
Write-Host " - Package.appxmanifest: $oldVer -> $FourPartVersion" -ForegroundColor Gray
|
|
}
|
|
}
|
|
|
|
# 2. Everything2Everything.App.csproj
|
|
$appCsprojPath = Join-Path $RootDir "src/Everything2Everything.App/Everything2Everything.App.csproj"
|
|
if (Test-Path $appCsprojPath) {
|
|
$csprojContent = Get-Content $appCsprojPath -Raw
|
|
if ($csprojContent -match '<Version>([^<]+)</Version>') {
|
|
$csprojContent = $csprojContent -replace '<Version>[^<]+</Version>', "<Version>$Version</Version>"
|
|
} else {
|
|
$csprojContent = $csprojContent -replace '<PropertyGroup>', "<PropertyGroup>`n <Version>$Version</Version>"
|
|
}
|
|
Set-Content $appCsprojPath $csprojContent
|
|
Write-Host " - Everything2Everything.App.csproj: Version -> $Version" -ForegroundColor Gray
|
|
}
|
|
|
|
Write-Host "✅ 버전 동기화 완료" -ForegroundColor Green
|
|
|
|
# ── Gate 3: Release 빌드 & 아티팩트 패키징 ──────────────────────────────
|
|
Write-Host "`n[Gate 3] 릴리즈 아티팩트 빌드 중..." -ForegroundColor Yellow
|
|
|
|
$publishDir = Join-Path $RootDir "publish"
|
|
$distDir = Join-Path $RootDir "packaging/dist"
|
|
|
|
if (-not $DryRun) {
|
|
# 0. 실행 중인 인스턴스 중지 (파일 잠금 방지)
|
|
Stop-Process -Name "Everything2Everything" -Force -ErrorAction SilentlyContinue
|
|
Start-Sleep -Milliseconds 500
|
|
|
|
# 1. Portable EXE Publish
|
|
Write-Host " - Portable 바이너리 빌드 (win-x64 Release)..." -ForegroundColor Gray
|
|
dotnet publish (Join-Path $RootDir "src/Everything2Everything.App/Everything2Everything.App.csproj") `
|
|
-c Release -r win-x64 --self-contained false -o $publishDir
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "Portable 바이너리 빌드 실패!"
|
|
exit 1
|
|
}
|
|
|
|
# 2. Portable ZIP 압축
|
|
$portableZip = Join-Path $RootDir "packaging/dist/Everything2Everything-$Version-win-x64-portable.zip"
|
|
if (-not (Test-Path $distDir)) { New-Item -ItemType Directory -Path $distDir -Force | Out-Null }
|
|
if (Test-Path $portableZip) { Remove-Item $portableZip -Force }
|
|
Compress-Archive -Path "$publishDir\*" -DestinationPath $portableZip
|
|
Write-Host " - Portable ZIP 생성: $portableZip" -ForegroundColor Gray
|
|
|
|
# 3. MSIX 패키징 및 디지털 서명
|
|
$buildMsixScript = Join-Path $RootDir "packaging/BuildMsix.ps1"
|
|
if (Test-Path $buildMsixScript) {
|
|
Write-Host " - MSIX 패키징 및 자동 서명 실행..." -ForegroundColor Gray
|
|
& pwsh -File $buildMsixScript -Configuration Release -Platform x64 -Sign
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "MSIX 패키징 및 서명 실패!"
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
if (-not (Test-Path (Join-Path $distDir "Everything2Everything-x64.msix"))) { throw "MSIX 파일이 생성되지 않았습니다." }
|
|
|
|
# 서명 무결성 검증 (0x800B010A 방지 게이트)
|
|
$msixFile = Join-Path $distDir "Everything2Everything-x64.msix"
|
|
if (Test-Path $msixFile) {
|
|
$sig = Get-AuthenticodeSignature $msixFile
|
|
if ($sig.Status -ne 'Valid') {
|
|
Write-Error "MSIX 서명 검증 실패 (Status: $($sig.Status))! 미서명 패키지는 배포할 수 없습니다."
|
|
exit 1
|
|
}
|
|
Write-Host " - MSIX 디지털 서명 검증 통과 (Status: Valid, Signer: $($sig.SignerCertificate.Subject))" -ForegroundColor Green
|
|
}
|
|
|
|
# 4. Inno Setup 표준 설치 파일(Setup-x64.exe) 빌드
|
|
$iscc = "C:\Users\encep\AppData\Local\Programs\Inno Setup 6\ISCC.exe"
|
|
if (-not (Test-Path $iscc)) {
|
|
$iscc = (Get-Command iscc -ErrorAction SilentlyContinue)?.Source
|
|
}
|
|
$innoScript = Join-Path $RootDir "packaging/Everything2Everything.iss"
|
|
$innoExe = Join-Path $distDir "Everything2Everything-$Version-Setup-x64.exe"
|
|
if ((Test-Path $iscc) -and (Test-Path $innoScript)) {
|
|
Write-Host " - Inno Setup 표준 설치 파일 빌드..." -ForegroundColor Gray
|
|
& $iscc "/DMyAppVersion=$Version" $innoScript
|
|
if ($LASTEXITCODE -eq 0 -and (Test-Path $innoExe)) {
|
|
Write-Host " - Inno Setup 빌드 성공: $innoExe" -ForegroundColor Green
|
|
} else {
|
|
throw "Inno Setup 빌드 실패 (코드 $LASTEXITCODE)"
|
|
}
|
|
}
|
|
|
|
if (-not (Test-Path $innoExe)) { throw "Inno Setup 설치 파일이 생성되지 않았습니다." }
|
|
|
|
# 5. 1-클릭 설치 번들 ZIP 생성 (MSIX + .cer + Install.cmd + Install.ps1)
|
|
$setupZip = Join-Path $distDir "Everything2Everything-$Version-Setup.zip"
|
|
$cerFile = Join-Path $distDir "Everything2Everything-DevCert.cer"
|
|
$installCmd = Join-Path $RootDir "packaging/Install.cmd"
|
|
$installPs1 = Join-Path $RootDir "packaging/Install.ps1"
|
|
|
|
$bundleFiles = @($msixFile)
|
|
if (Test-Path $cerFile) { $bundleFiles += $cerFile }
|
|
if (Test-Path $installCmd) { $bundleFiles += $installCmd }
|
|
if (Test-Path $installPs1) { $bundleFiles += $installPs1 }
|
|
|
|
if (Test-Path $setupZip) { Remove-Item $setupZip -Force }
|
|
Compress-Archive -Path $bundleFiles -DestinationPath $setupZip
|
|
Write-Host " - 1-클릭 MSIX 설치 번들 ZIP 생성: $setupZip" -ForegroundColor Gray
|
|
} else {
|
|
Write-Host " (DryRun: 빌드 단계 건너뜀)" -ForegroundColor DarkGray
|
|
}
|
|
|
|
Write-Host "✅ 아티팩트 패키징 완료" -ForegroundColor Green
|
|
|
|
# ── Gate 4: Git 커밋, 태그 및 원격 푸시 ───────────────────────────────
|
|
Push-Location $RootDir
|
|
try {
|
|
# Only version files may have changed during the build.
|
|
$allowed = @('packaging/Package.appxmanifest', 'src/Everything2Everything.App/Everything2Everything.App.csproj')
|
|
$changed = @(Invoke-GitChecked diff --name-only HEAD)
|
|
if (@($changed | Where-Object { $_ -notin $allowed }).Count -gt 0) {
|
|
throw "빌드 중 소스가 변경되었습니다. 다시 검증하고 커밋하세요."
|
|
}
|
|
$untracked = @(Invoke-GitChecked ls-files --others --exclude-standard)
|
|
if ($untracked.Count -gt 0) { throw "빌드 중 미추적 파일이 생성되었습니다. 검토 후 다시 실행하세요." }
|
|
Invoke-GitChecked add -- $manifestPath $appCsprojPath | Out-Null
|
|
& git diff --cached --quiet
|
|
$diffExit = $LASTEXITCODE
|
|
if ($diffExit -eq 1) {
|
|
Invoke-GitChecked -c user.name="Yun Chan" commit -m "chore(release): $Tag" | Out-Null
|
|
} elseif ($diffExit -ne 0) { throw "버전 변경 확인 실패" }
|
|
$releaseCommit = (Invoke-GitChecked rev-parse HEAD).Trim()
|
|
Invoke-GitChecked tag -a $Tag -m "Release $Tag" | Out-Null
|
|
Invoke-GitChecked push forgejo HEAD | Out-Null
|
|
Invoke-GitChecked push forgejo "refs/tags/$Tag" | Out-Null
|
|
} finally { Pop-Location }
|
|
|
|
# ── Gate 5: Forgejo release and assets; every failure is fatal ─────────
|
|
$authHeader = @{ Authorization = "token $env:FORGEJO_TOKEN" }
|
|
$releaseUrl = "$ForgejoHost/api/v1/repos/$ForgejoOwner/$ForgejoRepo/releases"
|
|
$releaseBody = @{
|
|
tag_name = $Tag
|
|
target_commitish = $releaseCommit
|
|
name = "Everything2Everything $Tag"
|
|
body = $ReleaseNotes
|
|
draft = $true
|
|
prerelease = $false
|
|
} | ConvertTo-Json
|
|
try {
|
|
# Keep incomplete uploads as a draft, publish only after asset verification.
|
|
$releaseResponse = Invoke-RestMethod -Uri $releaseUrl -Method Post -Headers $authHeader -ContentType 'application/json' -Body $releaseBody
|
|
if (-not $releaseResponse.id) { throw "릴리즈 응답에 ID가 없습니다." }
|
|
$assets = @($portableZip, $msixFile, $setupZip, $innoExe)
|
|
if (Test-Path -LiteralPath $cerFile) { $assets += $cerFile }
|
|
foreach ($asset in $assets) {
|
|
if (-not (Test-Path -LiteralPath $asset -PathType Leaf)) { throw "필수 배포 파일 누락: $asset" }
|
|
$file = Get-Item -LiteralPath $asset
|
|
if ($file.Length -le 0) { throw "빈 배포 파일: $asset" }
|
|
$uploadUrl = "$releaseUrl/$($releaseResponse.id)/assets?name=$([Uri]::EscapeDataString($file.Name))"
|
|
$uploaded = Invoke-RestMethod -Uri $uploadUrl -Method Post -Headers $authHeader -Form @{ attachment = $file }
|
|
if ($uploaded.size -ne $file.Length -or -not $uploaded.browser_download_url -or $uploaded.name -ne $file.Name) {
|
|
throw "첨부 파일 검증 실패: $($file.Name)"
|
|
}
|
|
}
|
|
$published = Invoke-RestMethod -Uri "$releaseUrl/$($releaseResponse.id)" -Method Patch -Headers $authHeader -ContentType 'application/json' -Body '{"draft":false}'
|
|
if ($published.draft -ne $false -or $published.tag_name -ne $Tag) { throw "릴리즈 공개 상태 확인 실패" }
|
|
Write-Host "Everything2Everything $Tag 배포 완료: $($published.html_url)" -ForegroundColor Green
|
|
} catch {
|
|
throw "Forgejo 릴리즈 배포 실패. 태그나 draft를 자동 삭제하지 않습니다. 원인을 확인하세요: $_"
|
|
}
|