-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-release.ps1
More file actions
228 lines (178 loc) · 7.12 KB
/
Copy pathcreate-release.ps1
File metadata and controls
228 lines (178 loc) · 7.12 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#Requires -Version 5.1
<#
.SYNOPSIS
Creates release artifacts for ArbSh.
.DESCRIPTION
This script can:
1) Update docs/CHANGELOG.md (optional)
2) Publish ArbSh.Console and create a release zip
3) Optionally publish ArbSh.Terminal and create an installer package zip
containing:
- App/ (published terminal files)
- Install-ArbSh.ps1
- Uninstall-ArbSh.ps1
The installer scripts register Windows Explorer context menu entries:
"Open in ArbSh" for folder/background/drive, passing --working-dir.
.PARAMETER Version
Release version string (e.g. 0.8.1-alpha).
.PARAMETER RuntimeID
Target runtime identifier (default: win-x64).
.PARAMETER TargetFramework
Target framework (default: net9.0).
.PARAMETER CreateInstaller
When set, also builds the terminal installer package zip.
.PARAMETER SkipChangelogUpdate
When set, skips changelog modification.
#>
param(
[Parameter(Mandatory = $true)]
[string]$Version,
[string]$RuntimeID = "win-x64",
[string]$TargetFramework = "net9.0",
[switch]$CreateInstaller,
[switch]$SkipChangelogUpdate
)
$ErrorActionPreference = "Stop"
# --- Paths ---
$ProjectRoot = $PSScriptRoot
$ReleasesDir = Join-Path $ProjectRoot "releases"
$ChangelogPath = Join-Path $ProjectRoot "docs\CHANGELOG.md"
$ConsoleProject = Join-Path $ProjectRoot "src_csharp\ArbSh.Console\ArbSh.Console.csproj"
$TerminalProject = Join-Path $ProjectRoot "src_csharp\ArbSh.Terminal\ArbSh.Terminal.csproj"
$ConsolePublishDir = Join-Path $ProjectRoot "src_csharp\ArbSh.Console\bin\Release\$TargetFramework\$RuntimeID\publish"
$TerminalPublishDir = Join-Path $ProjectRoot "src_csharp\ArbSh.Terminal\bin\Release\$TargetFramework\$RuntimeID\publish"
$ConsoleZipName = "ArbSh-v$Version-$RuntimeID.zip"
$ConsoleZipPath = Join-Path $ReleasesDir $ConsoleZipName
$InstallerPackageName = "ArbSh-v$Version-$RuntimeID-installer.zip"
$InstallerPackagePath = Join-Path $ReleasesDir $InstallerPackageName
$InstallerStageDir = Join-Path $ReleasesDir "ArbSh-v$Version-$RuntimeID-installer"
$InstallerTemplateDir = Join-Path $ProjectRoot "installer"
function Write-Step {
param([string]$Message)
Write-Host "==> $Message"
}
function Ensure-Directory {
param([string]$Path)
if (-not (Test-Path -Path $Path -PathType Container)) {
New-Item -Path $Path -ItemType Directory -Force | Out-Null
}
}
function Update-Changelog {
if ($SkipChangelogUpdate) {
Write-Step "Skipping CHANGELOG update."
return
}
if (-not (Test-Path -Path $ChangelogPath -PathType Leaf)) {
Write-Warning "Changelog not found at: $ChangelogPath"
return
}
Write-Step "Updating changelog header for version $Version"
$content = Get-Content -Path $ChangelogPath -Raw
$currentDate = Get-Date -Format "yyyy-MM-dd"
$pattern = '(?m)^## \[Unreleased\](?:\s*-\s*YYYY-MM-DD)?\s*$'
if ($content -notmatch $pattern) {
Write-Warning "Could not find '## [Unreleased]' section. Skipping changelog update."
return
}
if ($content -match ("(?m)^## \[" + [regex]::Escape($Version) + "\]\s*-\s*\d{4}-\d{2}-\d{2}\s*$")) {
Write-Warning "Version $Version already exists in changelog. Skipping update."
return
}
$replacement = @"
## [Unreleased]
### Added
- (Future changes go here)
## [$Version] - $currentDate
"@
$updated = [regex]::Replace($content, $pattern, $replacement, 1)
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($ChangelogPath, $updated, $utf8NoBom)
}
function Invoke-DotNetPublish {
param(
[Parameter(Mandatory = $true)]
[string]$ProjectPath
)
if (-not (Test-Path -Path $ProjectPath -PathType Leaf)) {
throw "Project file not found: $ProjectPath"
}
Write-Step "Publishing: $ProjectPath"
& dotnet publish $ProjectPath -c Release -r $RuntimeID --self-contained true
if ($LASTEXITCODE -ne 0) {
throw "dotnet publish failed for $ProjectPath (exit code $LASTEXITCODE)."
}
}
function Build-ConsoleReleaseZip {
Write-Step "Publishing ArbSh.Console"
Invoke-DotNetPublish -ProjectPath $ConsoleProject
if (-not (Test-Path -Path $ConsolePublishDir -PathType Container)) {
throw "Console publish directory not found: $ConsolePublishDir"
}
Write-Step "Creating console zip: $ConsoleZipPath"
if (Test-Path -Path $ConsoleZipPath) {
Remove-Item -Path $ConsoleZipPath -Force
}
Compress-Archive -Path (Join-Path $ConsolePublishDir '*') -DestinationPath $ConsoleZipPath -Force
}
function Build-InstallerPackage {
Write-Step "Publishing ArbSh.Terminal"
Invoke-DotNetPublish -ProjectPath $TerminalProject
if (-not (Test-Path -Path $TerminalPublishDir -PathType Container)) {
throw "Terminal publish directory not found: $TerminalPublishDir"
}
if (-not (Test-Path -Path $InstallerTemplateDir -PathType Container)) {
throw "Installer template directory not found: $InstallerTemplateDir"
}
$installScript = Join-Path $InstallerTemplateDir "Install-ArbSh.ps1"
$uninstallScript = Join-Path $InstallerTemplateDir "Uninstall-ArbSh.ps1"
if (-not (Test-Path -Path $installScript -PathType Leaf)) {
throw "Install script missing: $installScript"
}
if (-not (Test-Path -Path $uninstallScript -PathType Leaf)) {
throw "Uninstall script missing: $uninstallScript"
}
if (Test-Path -Path $InstallerStageDir -PathType Container) {
Remove-Item -Path $InstallerStageDir -Recurse -Force
}
$stageAppDir = Join-Path $InstallerStageDir "App"
Ensure-Directory -Path $stageAppDir
Write-Step "Staging installer package files"
Copy-Item -Path (Join-Path $TerminalPublishDir '*') -Destination $stageAppDir -Recurse -Force
Copy-Item -Path $installScript -Destination (Join-Path $InstallerStageDir "Install-ArbSh.ps1") -Force
Copy-Item -Path $uninstallScript -Destination (Join-Path $InstallerStageDir "Uninstall-ArbSh.ps1") -Force
$readmePath = Join-Path $InstallerStageDir "README.txt"
$readme = @"
ArbSh Installer Package
Version: $Version
Runtime: $RuntimeID
How to install:
1) Open PowerShell
2) Run: .\Install-ArbSh.ps1
This installs ArbSh.Terminal for the current user and adds:
- Open in ArbSh (folder background)
- Open in ArbSh (folder)
- Open in ArbSh (drive)
It passes the selected location through:
--working-dir
"@
Set-Content -Path $readmePath -Value $readme -Encoding UTF8
if (Test-Path -Path $InstallerPackagePath -PathType Leaf) {
Remove-Item -Path $InstallerPackagePath -Force
}
Write-Step "Creating installer package zip: $InstallerPackagePath"
Compress-Archive -Path (Join-Path $InstallerStageDir '*') -DestinationPath $InstallerPackagePath -Force
}
Write-Step "Starting release process for version $Version"
Ensure-Directory -Path $ReleasesDir
Update-Changelog
Build-ConsoleReleaseZip
if ($CreateInstaller) {
Build-InstallerPackage
} else {
Write-Step "Installer packaging skipped. Use -CreateInstaller to enable."
}
Write-Step "Release process completed."
Write-Host "Console artifact: $ConsoleZipPath"
if ($CreateInstaller) {
Write-Host "Installer package: $InstallerPackagePath"
}