-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish-release.ps1
More file actions
247 lines (206 loc) · 10.4 KB
/
publish-release.ps1
File metadata and controls
247 lines (206 loc) · 10.4 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<#
.SYNOPSIS
Automated GitHub release publisher with TOC version auto-detection.
.DESCRIPTION
Reads version from SimpleUnitFrames.toc, sets GitHub token, and publishes release.
This is a convenience wrapper around upload-github-release.ps1.
.PARAMETER TocFile
Path to the TOC file (default: ./SimpleUnitFrames.toc)
.PARAMETER OwnerRepo
GitHub repository in owner/repo format (default: pfchrono/SimpleUnitFrames)
.PARAMETER GitHubToken
GitHub Personal Access Token with 'repo' scope.
If not provided, will read from GITHUB_TOKEN environment variable.
.PARAMETER ReleasesDir
Directory containing release archives (default: ./releases)
.PARAMETER DryRun
Show what would be done without actually publishing
.EXAMPLE
.\publish-release.ps1 -GitHubToken 'ghp_xxxxx'
.EXAMPLE
.\publish-release.ps1
# Uses GITHUB_TOKEN environment variable
.EXAMPLE
.\publish-release.ps1 -Version '1.26.0'
# Override TOC version detection (useful if TOC already bumped to next version)
.EXAMPLE
$env:GITHUB_TOKEN = 'ghp_xxxxx'
.\publish-release.ps1 -DryRun
#>
[CmdletBinding()]
param(
[Parameter()]
[string]$Version,
[Parameter()]
[string]$TocFile = "./SimpleUnitFrames.toc",
[Parameter()]
[string]$OwnerRepo = "pfchrono/SimpleUnitFrames",
[Parameter()]
[string]$GitHubToken,
[Parameter()]
[string]$ReleasesDir = "./releases",
[Parameter()]
[switch]$DryRun
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
# Function: Extract version from TOC file
function Get-VersionFromToc {
param([string]$TocPath)
if (-not (Test-Path $TocPath)) {
throw "TOC file not found: $TocPath"
}
$content = Get-Content $TocPath -Raw
if ($content -match '##\s*Version:\s*([0-9]+\.[0-9]+\.[0-9]+)') {
# Extract only major.minor.patch (ignore date suffix)
return $Matches[1]
}
throw "Could not extract version from TOC file: $TocPath"
}
# Function: Verify prerequisites
function Test-Prerequisites {
# Check if upload-github-release.ps1 exists
$uploadScript = Join-Path $PSScriptRoot "upload-github-release.ps1"
if (-not (Test-Path $uploadScript)) {
throw "Required script not found: upload-github-release.ps1"
}
return $uploadScript
}
# Main execution
try {
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host "SimpleUnitFrames Release Publisher" -ForegroundColor Green
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
# Verify prerequisites
Write-Host "→ Verifying prerequisites..." -ForegroundColor Yellow
$uploadScriptPath = Test-Prerequisites
Write-Host " ✓ upload-github-release.ps1 found" -ForegroundColor Green
# Extract version from TOC or use override
Write-Host ""
if ($Version) {
Write-Host "→ Using version override: $Version" -ForegroundColor Yellow
} else {
Write-Host "→ Reading version from TOC file..." -ForegroundColor Yellow
$Version = Get-VersionFromToc -TocPath $TocFile
}
Write-Host " ✓ Version: $Version" -ForegroundColor Green
# Construct paths
$archiveName = "SimpleUnitFrames-$version.zip"
$archivePath = Join-Path $ReleasesDir $archiveName
$releaseNotesFile = "RELEASE_NOTES_v$version.md"
# Verify archive exists
Write-Host ""
Write-Host "→ Verifying release archive..." -ForegroundColor Yellow
if (-not (Test-Path $archivePath)) {
throw "Release archive not found: $archivePath`nPlease run build-release.ps1 first."
}
$archiveSize = (Get-Item $archivePath).Length / 1MB
Write-Host (" ✓ Archive found: {0:N2} MB" -f $archiveSize) -ForegroundColor Green
# Verify release notes exist
Write-Host ""
Write-Host "→ Verifying release notes..." -ForegroundColor Yellow
if (-not (Test-Path $releaseNotesFile)) {
Write-Host " ⚠ Release notes not found: $releaseNotesFile" -ForegroundColor Yellow
Write-Host " Will create release without detailed notes." -ForegroundColor Yellow
$releaseNotesFile = $null
} else {
Write-Host " ✓ Release notes found: $releaseNotesFile" -ForegroundColor Green
}
# Handle GitHub token
Write-Host ""
Write-Host "→ Checking GitHub authentication..." -ForegroundColor Yellow
if ($GitHubToken) {
$env:GITHUB_TOKEN = $GitHubToken
Write-Host " ✓ Token provided via parameter" -ForegroundColor Green
} elseif ($env:GITHUB_TOKEN) {
Write-Host " ✓ Token found in GITHUB_TOKEN environment variable" -ForegroundColor Green
} else {
throw "GitHub token required. Provide via -GitHubToken parameter or GITHUB_TOKEN environment variable."
}
# Display summary
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host "Release Configuration" -ForegroundColor Green
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host " Version: " -NoNewline; Write-Host $version -ForegroundColor White
Write-Host " Repository: " -NoNewline; Write-Host $OwnerRepo -ForegroundColor White
Write-Host " Archive: " -NoNewline; Write-Host $archivePath -ForegroundColor White
Write-Host " Archive Size: " -NoNewline; Write-Host ("{0:N2} MB" -f $archiveSize) -ForegroundColor White
Write-Host " Release Notes: " -NoNewline
if ($releaseNotesFile) {
Write-Host $releaseNotesFile -ForegroundColor White
} else {
Write-Host "(none)" -ForegroundColor Gray
}
Write-Host ""
if ($DryRun) {
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host "DRY RUN - Would Execute:" -ForegroundColor Yellow
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host " & `"$uploadScriptPath`" ```" -ForegroundColor Gray
Write-Host " -Version '$version' ```" -ForegroundColor Gray
Write-Host " -ArchivePath '$archivePath' ```" -ForegroundColor Gray
Write-Host " -OwnerRepo '$OwnerRepo' ```" -ForegroundColor Gray
if ($releaseNotesFile) {
Write-Host " -ReleaseNotesFile '$releaseNotesFile'" -ForegroundColor Gray
}
Write-Host ""
Write-Host "✓ Dry run complete. No changes made." -ForegroundColor Green
Write-Host ""
return
}
# Confirm before publishing
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
$confirmation = Read-Host "Publish release v$version to GitHub? (y/N)"
if ($confirmation -notmatch '^[Yy]') {
Write-Host ""
Write-Host "✗ Release cancelled by user." -ForegroundColor Yellow
Write-Host ""
return
}
# Execute upload
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host "Publishing Release to GitHub" -ForegroundColor Green
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
$uploadParams = @{
Version = $version
ArchivePath = $archivePath
OwnerRepo = $OwnerRepo
}
if ($releaseNotesFile) {
$uploadParams['ReleaseNotesFile'] = $releaseNotesFile
}
& $uploadScriptPath @uploadParams
if ($LASTEXITCODE -eq 0) {
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host "✓ Release v$version Published Successfully!" -ForegroundColor Green
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "View release at: https://github.com/$OwnerRepo/releases/tag/v$version" -ForegroundColor Cyan
Write-Host ""
} else {
throw "Release publication failed with exit code: $LASTEXITCODE"
}
} catch {
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host "✗ Error Publishing Release" -ForegroundColor Red
Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Red
Write-Host ""
Write-Host $_.Exception.Message -ForegroundColor Red
Write-Host ""
if ($_.Exception.InnerException) {
Write-Host "Inner Exception:" -ForegroundColor Yellow
Write-Host $_.Exception.InnerException.Message -ForegroundColor Red
Write-Host ""
}
exit 1
}