Repository navigation
Expand file tree
/
Copy pathpublish-cli.ps1
More file actions
140 lines (125 loc) · 6.07 KB
/
Copy pathpublish-cli.ps1
File metadata and controls
140 lines (125 loc) · 6.07 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<#
.SYNOPSIS
Publishes self-contained, trimmed single-file XISOSharp CLI binaries.
.DESCRIPTION
Publishes XISOSharp.Cli for each requested RID into publish/<rid>/.
The published single-file binary is named XISOSharp(.exe) (renamed by the
csproj RenamePublishedExeToXisoSharp target; the build AssemblyName stays
XISOSharp.Cli to avoid colliding with the XISOSharp library DLL).
PublishSingleFile/PublishTrimmed come from XISOSharp.Cli.csproj; this script
just loops RIDs and enforces --self-contained. Requires the .NET SDK pinned
in global.json (cross-OS/arm64 publishes work from any host).
.EXAMPLE
./publish-cli.ps1
Publishes the default seven RIDs (win-x86, win-x64, win-arm64, linux-x64, linux-arm64, osx-x64, osx-arm64).
.EXAMPLE
./publish-cli.ps1 -Rid win-x64,win-x86 -Zip
Publishes 32/64-bit Windows and packages each output as
release_<version>_<rid>.zip (Linux: .tar.gz, macOS: .dmg), matching the
asset names the CLI update checker looks for on the GitHub release.
#>
[CmdletBinding()]
param(
[string[]]$Rid = @('win-x86', 'win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64'),
[string]$Configuration = 'Release',
[string]$OutputRoot = '',
[string]$Version = '',
[switch]$Zip
)
$ErrorActionPreference = 'Stop'
if ([string]::IsNullOrWhiteSpace($OutputRoot)) {
$OutputRoot = Join-Path $PSScriptRoot 'publish'
}
# Version for the -Zip asset names (release_<version>_<rid>.<ext>), from the
# exact git tag so it matches the GitHub release the bundles attach to. An
# untagged HEAD must not silently reuse the previous tag: that would overwrite
# a shipped release bundle (AGENTS.md). Pass -Version <x.y.z> to build a
# planned release before tagging. Without -Zip the value is only cosmetic.
$cliVersion = $Version
if ([string]::IsNullOrWhiteSpace($cliVersion)) {
$cliVersion = (& git -C $PSScriptRoot describe --tags --exact-match 2>$null)
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($cliVersion)) {
if ($Zip) {
throw "-Zip needs an exact release tag or -Version <x.y.z>: refusing to overwrite a shipped release bundle from an untagged commit."
}
$cliVersion = (& git -C $PSScriptRoot describe --tags --abbrev=0 2>$null)
if ([string]::IsNullOrWhiteSpace($cliVersion)) {
$cliVersion = '0.0.0-dev'
}
}
}
$cliVersion = $cliVersion -replace '^[vV]', ''
# Release-asset RID fragments (UpdateChecker convention): macOS ships as
# MacOsX-*, RIDs without a convention entry fall back to the raw RID.
$assetRidMap = @{
'win-x64' = 'win-x64'
'win-x86' = 'win-x86'
'win-arm64' = 'win-arm64'
'linux-x64' = 'linux-x64'
'linux-arm64' = 'linux-arm64'
'osx-x64' = 'MacOsX-x64'
'osx-arm64' = 'MacOsX-arm64'
}
function Get-ArchiveExtension([string]$Rid) {
if ($Rid.StartsWith('linux-', [StringComparison]::Ordinal)) { return 'tar.gz' }
if ($Rid.StartsWith('osx-', [StringComparison]::Ordinal)) { return 'dmg' }
return 'zip'
}
$isMacOsHost = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform(
[System.Runtime.InteropServices.OSPlatform]::OSX)
foreach ($r in $Rid) {
$outDir = Join-Path $OutputRoot $r
Write-Host "Publishing $r -> $outDir" -ForegroundColor Cyan
# AGENTS.md hard rule: publish/<rid> is an artifact store, never deleted.
# Publish into a temp stage, then merge over the same-named files.
$stage = Join-Path ([System.IO.Path]::GetTempPath()) "xiso_publish_cli/$r"
if (Test-Path -LiteralPath $stage) {
Remove-Item -LiteralPath $stage -Recurse -Force
}
New-Item -ItemType Directory -Path $stage -Force | Out-Null
# NOTE: -f net11.0 is explicit so the shippable target stays unambiguous;
# net11.0 ships as a self-contained binary.
& dotnet publish (Join-Path $PSScriptRoot 'XISOSharp.Cli/XISOSharp.Cli.csproj') `
-c $Configuration -f net11.0 -r $r --self-contained -o $stage
if ($LASTEXITCODE -ne 0) {
throw "dotnet publish failed for RID $r (exit $LASTEXITCODE)."
}
New-Item -ItemType Directory -Path $outDir -Force | Out-Null
Copy-Item -Path (Join-Path $stage '*') -Destination $outDir -Recurse -Force
Remove-Item -LiteralPath $stage -Recurse -Force
$exe = if ($r.StartsWith('win-')) { 'XISOSharp.exe' } else { 'XISOSharp' }
$bin = Join-Path $outDir $exe
if (-not (Test-Path -LiteralPath $bin)) {
throw "Expected binary missing after publish: $bin (expected the published single-file exe to be renamed to XISOSharp(.exe) by the csproj RenamePublishedExeToXisoSharp target)"
}
$sizeMB = ((Get-Item -LiteralPath $bin).Length / 1MB).ToString('0.0')
Write-Host " OK: $bin ($sizeMB MB)" -ForegroundColor Green
if ($Zip) {
if ($r.StartsWith('osx-', [StringComparison]::Ordinal) -and -not $isMacOsHost) {
Write-Warning "Skipping .dmg for ${r}: hdiutil is only available on macOS. Run this on macOS to build the release asset."
continue
}
$assetRid = if ($assetRidMap.ContainsKey($r)) { $assetRidMap[$r] } else { $r }
$extension = Get-ArchiveExtension $r
$archivePath = Join-Path $OutputRoot "release_${cliVersion}_${assetRid}.${extension}"
if (Test-Path -LiteralPath $archivePath) {
Remove-Item -LiteralPath $archivePath -Force
}
switch ($extension) {
'zip' {
Compress-Archive -Path (Join-Path $outDir '*') -DestinationPath $archivePath
}
'tar.gz' {
& tar -czf $archivePath -C $outDir .
if ($LASTEXITCODE -ne 0) { throw "tar failed for $archivePath (exit $LASTEXITCODE)." }
}
'dmg' {
& hdiutil create -volname "XISOSharp $cliVersion" -srcfolder $outDir `
-ov -format UDZO $archivePath
if ($LASTEXITCODE -ne 0) { throw "hdiutil failed for $archivePath (exit $LASTEXITCODE)." }
}
}
Write-Host " packaged: $archivePath" -ForegroundColor Green
}
}
Write-Host "Done. Binaries under $OutputRoot" -ForegroundColor Green