-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-release.ps1
More file actions
91 lines (75 loc) · 3.25 KB
/
build-release.ps1
File metadata and controls
91 lines (75 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Build Release Script for certz
# Compiles a release binary and writes checksums.txt. Release notes are
# generated separately by scripts/release.ps1.
param(
[string]$OutputDir = "",
[string]$Configuration = "Release",
[string]$RuntimeIdentifier = "win-x64"
)
$ErrorActionPreference = "Stop"
$ProjectRoot = $PSScriptRoot
# Default output directory is release/<RuntimeIdentifier> (e.g. release/win-x64, release/linux-x64)
if (-not $OutputDir) {
$OutputDir = "release/$RuntimeIdentifier"
}
$OutputPath = Join-Path $ProjectRoot $OutputDir
Write-Host "Building certz release..." -ForegroundColor Cyan
# Clean and create output directory
if (Test-Path $OutputPath) {
Remove-Item $OutputPath -Recurse -Force
}
New-Item -ItemType Directory -Path $OutputPath | Out-Null
# Build the project
Write-Host "Publishing project..." -ForegroundColor Yellow
dotnet publish "$ProjectRoot\src\certz\certz.csproj" `
-c $Configuration `
-r $RuntimeIdentifier `
-o $OutputPath `
--self-contained true `
-p:PublishSingleFile=true `
-p:PublishReadyToRun=true `
-p:PublishTrimmed=true
if ($LASTEXITCODE -ne 0) {
Write-Error "Build failed with exit code $LASTEXITCODE"
exit $LASTEXITCODE
}
if ($RuntimeIdentifier.StartsWith("win")) { $BuiltName = "certz.exe" } else { $BuiltName = "certz" }
$BuiltPath = Join-Path $OutputPath $BuiltName
if (-not (Test-Path $BuiltPath)) {
Write-Error "$BuiltName was not found in output directory"
exit 1
}
# Get version from csproj (needed for the output filename)
$CsprojPath = Join-Path $ProjectRoot "src\certz\certz.csproj"
[xml]$Csproj = Get-Content $CsprojPath
$Version = $Csproj.Project.PropertyGroup.Version
if (-not $Version) {
$Version = "Unknown"
}
# Rename to certz-<version>-<rid>[.exe] so uploads are unambiguous
# e.g. certz-0.3.0-win-x64.exe, certz-0.3.0-linux-x64
if ($RuntimeIdentifier.StartsWith("win")) { $ExeName = "certz-$Version-$RuntimeIdentifier.exe" } else { $ExeName = "certz-$Version-$RuntimeIdentifier" }
$ExePath = Join-Path $OutputPath $ExeName
Rename-Item -Path $BuiltPath -NewName $ExeName
Write-Host "Build successful!" -ForegroundColor Green
# Calculate file hash
Write-Host "Calculating file hash..." -ForegroundColor Yellow
$FileHash = (Get-FileHash -Path $ExePath -Algorithm SHA256).Hash
# Write checksums.txt (sha256sum-compatible format)
$ChecksumsPath = Join-Path $OutputPath "checksums.txt"
$hashLine = "$($FileHash.ToLower()) $ExeName"
$hashLine | Out-File -FilePath $ChecksumsPath -Encoding utf8NoBOM -Append
Write-Host "Checksums written to: $ChecksumsPath" -ForegroundColor Yellow
# Write per-binary .sha256 file (used by scoop autoupdate)
$Sha256Path = Join-Path $OutputPath "$ExeName.sha256"
$hashLine | Out-File -FilePath $Sha256Path -Encoding utf8NoBOM -NoNewline
Write-Host "SHA256 file written to: $Sha256Path" -ForegroundColor Yellow
Write-Host ""
Write-Host "Release build complete!" -ForegroundColor Green
Write-Host "Output directory: $OutputPath" -ForegroundColor Cyan
Write-Host "Version: $Version" -ForegroundColor Cyan
Write-Host "SHA256: $FileHash" -ForegroundColor Cyan
Write-Host "Checksums: $ChecksumsPath" -ForegroundColor Cyan
Write-Host ""
Write-Host "Files created:" -ForegroundColor Yellow
Get-ChildItem $OutputPath | ForEach-Object { Write-Host " - $($_.Name)" }