Skip to content

Commit 5f5d9e9

Browse files
committed
chore: auto-version New-Release.ps1 (patch bump from highest tag) & README docs update
1 parent d6586be commit 5f5d9e9

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

New-Release.ps1

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
Automates creating a new extension release: prepends release notes to CHANGELOG.md, commits, tags, and creates GitHub release.
44
55
.DESCRIPTION
6-
New-Release.ps1 updates CHANGELOG.md by inserting a new version section right after the Unreleased header, commits the change, creates an annotated tag following v<Major>.<Minor>.<Build>[.<Revision>] pattern, and invokes `gh release create` with the provided notes.
7-
8-
.PARAMETER Version
9-
System.Version representing the new version. Tag format derives from all numeric components present.
6+
New-Release.ps1 updates CHANGELOG.md by inserting a new version section right after the Unreleased header, commits the change, determines the next semantic version automatically by inspecting existing git tags (pattern: v<Major>.<Minor>.<Build>[.<Revision>]), creates an annotated tag, and invokes `gh release create` with the provided notes.
107
118
.PARAMETER ReleaseNotes
12-
String containing markdown release notes (can include multiline text). This will be used both for CHANGELOG entry body and GitHub release notes.
9+
Markdown release notes (multiline supported) used for CHANGELOG body and GitHub release.
1310
1411
.PARAMETER Date
1512
Optional override for release date (YYYY-MM-DD). Defaults to current UTC date.
@@ -21,17 +18,16 @@ If set, does not push commit/tag to origin.
2118
If set, shows the changes that would be made without applying them.
2219
2320
.EXAMPLE
24-
./New-Release.ps1 -Version 0.0.17 -ReleaseNotes "**Added:** New feature X\n**Fixed:** Bug Y"
21+
./New-Release.ps1 -ReleaseNotes "**Added:** Feature X`n**Fixed:** Bug Y"
2522
2623
.EXAMPLE
27-
./New-Release.ps1 -Version 1.2.3.4 -ReleaseNotes (Get-Content RELEASE_NOTES_1.2.3.md -Raw)
24+
$notes = @'\n**Added:** Dashboard refresh\n**Changed:** Improved docs\n'@; ./New-Release.ps1 -ReleaseNotes $notes
2825
2926
.NOTES
30-
Requires `gh` CLI authenticated for release creation; if missing, script will warn and skip release step.
27+
Requires `gh` CLI authenticated for release creation; if missing, script will warn and skip release step. Version auto-increment strategy: bump patch (Build component). If no existing tags are found, starts at 0.0.1.
3128
#>
3229
[CmdletBinding(SupportsShouldProcess=$true)]
3330
param(
34-
[Parameter(Mandatory=$true)][Version]$Version,
3531
[Parameter(Mandatory=$true)][string]$ReleaseNotes,
3632
[string]$Date = (Get-Date -AsUTC -Format 'yyyy-MM-dd'),
3733
[switch]$SkipGitPush,
@@ -48,7 +44,27 @@ function Get-TagName {
4844
return 'v' + ($parts -join '.')
4945
}
5046

51-
function Insert-ChangelogEntry {
47+
function Get-NextVersion {
48+
# Gather existing tags matching v* and parse into System.Version
49+
if (-not (Get-Command git -ErrorAction SilentlyContinue)) { throw 'git CLI not available' }
50+
$rawTags = (& git tag --list 'v*') 2>$null
51+
$versions = @()
52+
foreach ($t in $rawTags) {
53+
$trim = $t.Trim()
54+
if ($trim -match '^v(\d+(?:\.\d+){0,3})$') {
55+
$verString = $Matches[1]
56+
try { $versions += [Version]$verString } catch { }
57+
}
58+
}
59+
if (-not $versions -or $versions.Count -eq 0) {
60+
return [Version]'0.0.1'
61+
}
62+
$current = $versions | Sort-Object -Descending | Select-Object -First 1
63+
$buildComponent = if ($current.Build -ge 0) { $current.Build + 1 } else { 1 }
64+
return [Version]::new($current.Major, $current.Minor, $buildComponent)
65+
}
66+
67+
function Add-ChangelogEntry {
5268
param(
5369
[string]$Path,
5470
[Version]$V,
@@ -58,18 +74,18 @@ function Insert-ChangelogEntry {
5874
if (-not (Test-Path $Path)) { throw "CHANGELOG file not found: $Path" }
5975
$content = Get-Content $Path -Raw
6076
$header = "## [$($V.ToString())] - $Date" + [Environment]::NewLine + [Environment]::NewLine + $Notes.Trim() + [Environment]::NewLine + [Environment]::NewLine
61-
# Insert after first occurrence of Unreleased section
6277
$pattern = "## \[Unreleased\]";
6378
if ($content -notmatch $pattern) { throw 'Unreleased section marker not found in CHANGELOG.md' }
6479
$updated = $content -replace $pattern, ($pattern + [Environment]::NewLine + [Environment]::NewLine + $header)
6580
return $updated
6681
}
6782

83+
$Version = Get-NextVersion
6884
$tag = Get-TagName -V $Version
69-
Write-Host "[info] Target version: $Version (tag: $tag)" -ForegroundColor Cyan
85+
Write-Host "[info] Auto-detected next version: $Version (tag: $tag)" -ForegroundColor Cyan
7086

7187
$changelogPath = Join-Path $PSScriptRoot 'CHANGELOG.md'
72-
$newContent = Insert-ChangelogEntry -Path $changelogPath -V $Version -Notes $ReleaseNotes -Date $Date
88+
$newContent = Add-ChangelogEntry -Path $changelogPath -V $Version -Notes $ReleaseNotes -Date $Date
7389

7490
if ($DryRun) {
7591
Write-Host "[dry-run] CHANGELOG preview:" -ForegroundColor Yellow

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,21 @@ Release flow – push tag & create a GitHub release to trigger publish workflow.
201201

202202
### Automated Release Script
203203

204-
You can automate steps 4–9 with the PowerShell helper `New-Release.ps1`:
204+
You can automate steps 4–9 with the PowerShell helper `New-Release.ps1` (auto-increments version):
205205

206206
```powershell
207-
./New-Release.ps1 -Version 0.0.17 -ReleaseNotes "**Added:** Feature X`n**Fixed:** Issue Y"
207+
./New-Release.ps1 -ReleaseNotes "**Added:** Feature X`n**Fixed:** Issue Y"
208208
```
209209

210210
Parameters:
211211

212-
- `-Version` (System.Version) – New semantic version (e.g., 0.0.17 or 1.2.3.4). Tag generated as `v<Major>.<Minor>.<Build>[.<Revision>]`.
213212
- `-ReleaseNotes` (string) – Markdown body inserted into CHANGELOG and used for GitHub release notes.
214213
- `-Date` (optional) – Override date; defaults to current UTC.
215214
- `-SkipGitPush` – Create commit + tag locally but do not push.
216215
- `-DryRun` – Show planned changes without applying.
217216

217+
Auto versioning: Script scans existing tags (`git tag --list 'v*'`), parses semantic versions, selects the highest, then increments the patch (Build) component. If no tags exist it starts at `0.0.1`.
218+
218219
Behavior:
219220

220221
1. Prepends a new `## [Version] - Date` section after `## [Unreleased]` in `CHANGELOG.md`.
@@ -231,7 +232,7 @@ $notes = @'
231232
**Changed:** Improved variable filtering docs
232233
**Fixed:** Race condition in session start
233234
'@
234-
./New-Release.ps1 -Version 0.0.18 -ReleaseNotes $notes
235+
./New-Release.ps1 -ReleaseNotes $notes
235236
```
236237

237238
## 🗒️ Changelog

0 commit comments

Comments
 (0)