-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcut-release.ps1
More file actions
380 lines (334 loc) · 13.8 KB
/
cut-release.ps1
File metadata and controls
380 lines (334 loc) · 13.8 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<#
.SYNOPSIS
Cuts a GraphCompose release: bumps pom versions, updates the
showcase site links, regenerates the examples manifest, runs
verify, commits, tags, pushes — then flips the showcase links
back to develop so ongoing dev work stays linkable.
.DESCRIPTION
Modes:
Default — full release cut. Requires clean develop in
sync with origin. Performs all 10 steps end
to end with prompts before each remote
action (push develop, push tag, merge to
main).
-DryRun — print every step without executing it. Use
to preview what the release will do.
-SkipPush — perform local changes (bump, tag, commit)
but do NOT push. Useful for staging a
release locally before publishing.
-PostReleaseOnly — skip the release work entirely. Just flips
ShowcaseMetadata.GH_BASE back to /blob/develop,
re-runs ShowcaseSync, and commits +
pushes that change. Use after a release
was cut and you want ongoing develop work
to have linkable View Code buttons.
-SkipVerify — skip the mvnw verify gate. Only use when
you've just run verify yourself and don't
want to wait another minute.
.EXAMPLE
pwsh ./scripts/cut-release.ps1 -Version 1.6.0
# full release of v1.6.0
.EXAMPLE
pwsh ./scripts/cut-release.ps1 -Version 1.6.0 -DryRun
# preview what would happen
.EXAMPLE
pwsh ./scripts/cut-release.ps1 -PostReleaseOnly
# post-release: flip showcase links back to develop
.NOTES
Author: Artem Demchyshyn
Pre-conditions:
- on develop branch
- working tree clean
- develop in sync with origin/develop
- tag v$Version doesn't already exist
Post-release reminder: after pushing the tag, merge develop into
main so GitHub Pages picks up the new docs, then run this script
with -PostReleaseOnly to flip the showcase links back to develop
for ongoing v1.x.y dev work.
#>
[CmdletBinding(DefaultParameterSetName='Release')]
param(
[Parameter(Mandatory=$true, ParameterSetName='Release')]
[string]$Version,
[Parameter(ParameterSetName='Release')]
[switch]$DryRun,
[Parameter(ParameterSetName='Release')]
[switch]$SkipPush,
[Parameter(ParameterSetName='Release')]
[switch]$SkipVerify,
[Parameter(Mandatory=$true, ParameterSetName='PostRelease')]
[switch]$PostReleaseOnly
)
$ErrorActionPreference = 'Stop'
$repoRoot = (Resolve-Path "$PSScriptRoot/..").Path
$showcaseMetadata = Join-Path $repoRoot 'examples/src/main/java/com/demcha/examples/support/ShowcaseMetadata.java'
$mvnw = Join-Path $repoRoot 'mvnw.cmd'
function Step($n, $title) {
Write-Host ""
Write-Host "[$n] $title" -ForegroundColor Cyan
}
function Note($message) {
Write-Host " $message" -ForegroundColor DarkGray
}
function Run($command) {
if ($DryRun) {
Write-Host " [DRY RUN] $command" -ForegroundColor Yellow
} else {
Write-Host " > $command" -ForegroundColor DarkGray
Invoke-Expression $command
if ($LASTEXITCODE -ne 0) {
throw "Command failed (exit $LASTEXITCODE): $command"
}
}
}
function Update-PomVersion($pomPath, $newVersion) {
if (-not (Test-Path $pomPath)) {
Note "skip (no file): $pomPath"
return
}
$content = Get-Content $pomPath -Raw
$changed = $false
# 1. Project's own <version> tag (the FIRST <version> in the file,
# before <parent> or any dependency entries).
$projectRegex = [regex]'<version>[\w\.\-]+</version>'
$projectNew = "<version>$newVersion</version>"
$afterProject = $projectRegex.Replace($content, $projectNew, 1)
if ($content -ne $afterProject) {
$content = $afterProject
$changed = $true
Note "bumped <version>: $pomPath -> $projectNew"
}
# 2. <graphcompose.version> property (if present). Subordinate POMs
# (examples/, benchmarks/) declare this property and depend on
# "io.github.demchaav:graphcompose:${graphcompose.version}". The
# property must track the project version so the published tag
# actually resolves on a fresh CI agent without a populated
# local m2. Bug surfaced in v1.6.0 release CI: the property
# stayed at 1.6.0-beta.1 while the project version flipped to
# 1.6.0 and CI failed at "Could not find artifact ...:1.6.0-beta.1".
$propertyRegex = [regex]'<graphcompose\.version>[\w\.\-]+</graphcompose\.version>'
$propertyNew = "<graphcompose.version>$newVersion</graphcompose.version>"
$afterProperty = $propertyRegex.Replace($content, $propertyNew, 1)
if ($content -ne $afterProperty) {
$content = $afterProperty
$changed = $true
Note "bumped <graphcompose.version>: $pomPath -> $propertyNew"
}
if (-not $changed) {
Note "no change: $pomPath (version already $newVersion?)"
return
}
if ($DryRun) {
Write-Host " [DRY RUN] Bump $pomPath -> $newVersion" -ForegroundColor Yellow
} else {
[System.IO.File]::WriteAllText($pomPath, $content)
}
}
function Update-ShowcaseGhBase($newRef) {
if (-not (Test-Path $showcaseMetadata)) {
throw "ShowcaseMetadata.java not found: $showcaseMetadata"
}
$content = Get-Content $showcaseMetadata -Raw
$regex = [regex]'private static final String GH_BASE = "https://github\.com/DemchaAV/GraphCompose/blob/[^"]+";'
$newLine = "private static final String GH_BASE = `"https://github.com/DemchaAV/GraphCompose/blob/$newRef`";"
$newContent = $regex.Replace($content, $newLine, 1)
if ($content -eq $newContent) {
Note "no change: ShowcaseMetadata GH_BASE (already $newRef)"
return $false
}
if ($DryRun) {
Write-Host " [DRY RUN] ShowcaseMetadata GH_BASE -> /blob/$newRef" -ForegroundColor Yellow
} else {
[System.IO.File]::WriteAllText($showcaseMetadata, $newContent)
Note "GH_BASE -> /blob/$newRef"
}
return $true
}
function Run-ShowcaseSync {
if ($DryRun) {
Write-Host " [DRY RUN] $mvnw -f examples/pom.xml exec:java -Dexec.mainClass=com.demcha.examples.support.ShowcaseSync" -ForegroundColor Yellow
return
}
Push-Location $repoRoot
try {
& $mvnw -f examples/pom.xml exec:java -Dexec.mainClass=com.demcha.examples.support.ShowcaseSync 2>&1 | ForEach-Object {
if ($_ -match 'Synced|Wrote manifest|BUILD SUCCESS|BUILD FAILURE|ERROR') {
Write-Host " $_" -ForegroundColor DarkGray
}
}
if ($LASTEXITCODE -ne 0) {
throw "ShowcaseSync failed (exit $LASTEXITCODE)"
}
} finally {
Pop-Location
}
}
# ============================================================
# Mode: -PostReleaseOnly
# ============================================================
if ($PostReleaseOnly) {
Push-Location $repoRoot
try {
Step 1 "Switch ShowcaseMetadata GH_BASE back to /blob/develop"
$changed = Update-ShowcaseGhBase 'develop'
if ($changed -or $DryRun) {
Step 2 "Regenerate docs/examples.json with develop links"
Run-ShowcaseSync
Step 3 "Commit"
$msg = "post-release: flip showcase links back to /blob/develop"
if ($DryRun) {
Write-Host " [DRY RUN] git commit -m `"$msg`"" -ForegroundColor Yellow
} else {
git add $showcaseMetadata 'docs/examples.json'
git commit -m $msg
}
Step 4 "Push develop"
if ($DryRun) {
Write-Host " [DRY RUN] git push origin develop" -ForegroundColor Yellow
} else {
git push origin develop
}
} else {
Note "GH_BASE already points to develop. Nothing to do."
}
} finally {
Pop-Location
}
Write-Host ""
Write-Host "Done. Ongoing develop work has linkable View Code buttons again." -ForegroundColor Green
return
}
# ============================================================
# Mode: full release cut
# ============================================================
Push-Location $repoRoot
try {
$tag = "v$Version"
Step 0 "Pre-flight checks"
# 1. On develop branch?
$branch = (git rev-parse --abbrev-ref HEAD).Trim()
if ($branch -ne 'develop') {
throw "Not on develop branch (currently on $branch). Switch to develop first."
}
Note "branch: develop OK"
# 2. Working tree clean?
$status = git status --porcelain
if ($status) {
throw "Working tree has uncommitted changes. Commit or stash first."
}
Note "working tree: clean OK"
# 3. In sync with origin?
git fetch origin develop --quiet
$local = (git rev-parse develop).Trim()
$remote = (git rev-parse origin/develop).Trim()
if ($local -ne $remote) {
throw "Local develop ($local) is not in sync with origin/develop ($remote). Pull/push first."
}
Note "in sync with origin/develop OK"
# 4. Tag doesn't already exist?
$existingTag = git tag -l $tag
if ($existingTag) {
throw "Tag $tag already exists. Bump version or delete the tag."
}
git fetch origin "refs/tags/$tag`:refs/tags/$tag" 2>&1 | Out-Null
$existingTag = git tag -l $tag
if ($existingTag) {
throw "Tag $tag exists on origin. Bump version or delete the remote tag."
}
Note ("tag {0}: available OK" -f $tag)
Step 1 "Bump pom versions to $Version"
Update-PomVersion (Join-Path $repoRoot 'pom.xml') $Version
Update-PomVersion (Join-Path $repoRoot 'examples/pom.xml') $Version
Update-PomVersion (Join-Path $repoRoot 'benchmarks/pom.xml') $Version
Step 2 "Update CHANGELOG date for v$Version"
$changelog = Join-Path $repoRoot 'CHANGELOG.md'
if (Test-Path $changelog) {
$today = (Get-Date -Format 'yyyy-MM-dd')
$content = Get-Content $changelog -Raw
$regex = [regex]"## v$([regex]::Escape($Version)) — Planned"
$newHeader = "## v$Version — $today"
$newContent = $regex.Replace($content, $newHeader, 1)
if ($content -ne $newContent) {
if ($DryRun) {
Write-Host " [DRY RUN] CHANGELOG.md: 'v$Version — Planned' -> 'v$Version — $today'" -ForegroundColor Yellow
} else {
[System.IO.File]::WriteAllText($changelog, $newContent)
Note "CHANGELOG: v$Version — $today"
}
} else {
Note "CHANGELOG: no '## v$Version — Planned' header found. Skipping (already dated?)."
}
}
Step 3 "Switch ShowcaseMetadata GH_BASE to /blob/$tag"
Update-ShowcaseGhBase $tag | Out-Null
Step 4 "Regenerate docs/examples.json with $tag links"
Run-ShowcaseSync
if (-not $SkipVerify) {
Step 5 "Run mvnw verify (sanity check)"
if ($DryRun) {
Write-Host " [DRY RUN] $mvnw verify -pl ." -ForegroundColor Yellow
} else {
& $mvnw verify -pl . 2>&1 | ForEach-Object {
if ($_ -match 'Tests run:|BUILD SUCCESS|BUILD FAILURE|ERROR') {
Write-Host " $_" -ForegroundColor DarkGray
}
}
if ($LASTEXITCODE -ne 0) {
throw "mvnw verify failed."
}
Note "mvnw verify: green"
}
} else {
Step 5 "Skipped mvnw verify (-SkipVerify)"
}
Step 6 "Commit release"
$commitMsg = "Release v$Version"
if ($DryRun) {
Write-Host " [DRY RUN] git add pom.xml examples/pom.xml benchmarks/pom.xml CHANGELOG.md examples/src/main/java/com/demcha/examples/support/ShowcaseMetadata.java docs/examples.json" -ForegroundColor Yellow
Write-Host " [DRY RUN] git commit -m `"$commitMsg`"" -ForegroundColor Yellow
} else {
git add `
pom.xml `
examples/pom.xml `
benchmarks/pom.xml `
CHANGELOG.md `
examples/src/main/java/com/demcha/examples/support/ShowcaseMetadata.java `
docs/examples.json
git commit -m $commitMsg
Note "commit: $commitMsg"
}
Step 7 "Tag $tag"
if ($DryRun) {
Write-Host " [DRY RUN] git tag -a $tag -m `"Release $tag`"" -ForegroundColor Yellow
} else {
git tag -a $tag -m "Release $tag"
Note "tag: $tag"
}
if ($SkipPush) {
Step 8 "Skipped push (-SkipPush). Run manually:"
Write-Host " git push origin develop" -ForegroundColor Cyan
Write-Host " git push origin $tag" -ForegroundColor Cyan
} else {
Step 8 "Push develop and tag"
if ($DryRun) {
Write-Host " [DRY RUN] git push origin develop" -ForegroundColor Yellow
Write-Host " [DRY RUN] git push origin $tag" -ForegroundColor Yellow
} else {
git push origin develop
git push origin $tag
Note "pushed: develop + $tag"
}
}
Write-Host ""
Write-Host "Release $tag committed locally." -ForegroundColor Green
Write-Host ""
Write-Host "Next steps (manual):" -ForegroundColor Cyan
Write-Host " 1. Merge develop into main on GitHub (PR or fast-forward)." -ForegroundColor Cyan
Write-Host " This makes the deployed GitHub Pages site pick up $tag." -ForegroundColor Cyan
Write-Host " 2. Create a GitHub Release for $tag with the CHANGELOG section as body." -ForegroundColor Cyan
Write-Host " 3. Verify JitPack: https://jitpack.io/com/github/DemchaAV/GraphCompose/$tag/build.log" -ForegroundColor Cyan
Write-Host " 4. Flip showcase links back to develop:" -ForegroundColor Cyan
Write-Host " pwsh ./scripts/cut-release.ps1 -PostReleaseOnly" -ForegroundColor Cyan
} finally {
Pop-Location
}