2e00b8df83
Releases are X.Y.Z from git tags vX.Y.Z; builds between releases are X.Y.Z.N, N commits after the last release (git describe, 1-3 digit majors only, so the calendar-era tags never count); with no release tag reachable a build is 0.0.0.<commits>. Every version is 3-4 numeric fields, refused when it does not fit an MSI ProductVersion or has a calendar-era major. scripts/Get-Version.ps1 computes it (Get-UnifiedVersion.ps1 stays as the old entry point). scripts/Get-NextRelease.ps1 runs semantic-release in dry-run mode (pinned in build/release, conventionalcommits preset, main only) for the version a release publishes, or for nothing when the commits since the last release call for none. Directory.Build.props stamps four-field assembly/file versions and InformationalVersion X.Y.Z[.N]+<short commit>; a build not handed a version reads it from git (build/Version.targets), otherwise 0.0.0.0. BREAKING CHANGE: versions are no longer yyyy.MM.dd.HHmm. The first release after the seed tag v0.1.0 is 1.0.0, which every comparison orders after every calendar-era version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
3.8 KiB
PowerShell
94 lines
3.8 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
The version a release run publishes: semantic-release's next version from the
|
|
conventional commits since the last release tag (a dry run, build/release),
|
|
or nothing when no release is due.
|
|
|
|
.DESCRIPTION
|
|
fix/perf since the last release bump the patch, feat the minor, a
|
|
"BREAKING CHANGE:" footer (or "type!:") the major; only docs, tests, chores,
|
|
refactors... release nothing, and this returns nothing. A commit that is
|
|
already a release (a re-run after a failed upload) returns that release's
|
|
version again, with no notes: the release exists.
|
|
|
|
Refuses when no release tag v<major>.<minor>.<patch> is reachable (the seed tag
|
|
must be present: a full clone with tags), when the branch is not main, and for
|
|
calendar-era versions (major 2000 or more).
|
|
|
|
Installs build/release's pinned packages with npm ci when they are missing.
|
|
|
|
.PARAMETER NotesPath
|
|
Where the release notes (Markdown) are written; removed when there are none.
|
|
|
|
.OUTPUTS
|
|
Nothing, or an object with Version (1.1.0), Tag (v1.1.0), LastVersion, Type
|
|
(major, minor, patch, or rerun) and Notes (the notes file, or $null).
|
|
|
|
.EXAMPLE
|
|
$next = ./scripts/Get-NextRelease.ps1 -NotesPath artifacts/release-notes.md
|
|
if ($next) { ./scripts/Package-Agent.ps1 -Version $next.Version }
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$NotesPath,
|
|
[string]$Root = (Split-Path -Parent $PSScriptRoot)
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
Set-StrictMode -Version 3.0
|
|
|
|
$tool = Join-Path (Split-Path -Parent $PSScriptRoot) 'build/release'
|
|
if (-not (Test-Path -LiteralPath (Join-Path $tool 'node_modules/semantic-release'))) {
|
|
# From inside the folder: npm ci needs the lockfile beside it.
|
|
Push-Location -LiteralPath $tool
|
|
try {
|
|
& npm ci --no-audit --no-fund | Out-Host
|
|
if ($LASTEXITCODE -ne 0) { throw "npm ci in build/release failed ($LASTEXITCODE)." }
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|
|
}
|
|
|
|
$out = Join-Path ([System.IO.Path]::GetTempPath()) "executer-next-release-$([guid]::NewGuid().ToString('N')).json"
|
|
try {
|
|
# semantic-release's report goes to stderr (the console); the result is the file.
|
|
& node (Join-Path $tool 'next-release.mjs') $out $Root | Out-Host
|
|
$exit = $LASTEXITCODE
|
|
$next = if (Test-Path -LiteralPath $out) { Get-Content -Raw -LiteralPath $out | ConvertFrom-Json } else { $null }
|
|
if ($exit -ne 0 -or -not $next -or $next.PSObject.Properties['error']) {
|
|
$reason = if ($next -and $next.PSObject.Properties['error']) { $next.error } else { "exit code $exit; see above" }
|
|
throw "Computing the next release failed: $reason"
|
|
}
|
|
}
|
|
finally {
|
|
Remove-Item -LiteralPath $out -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
if ($NotesPath) { Remove-Item -LiteralPath $NotesPath -ErrorAction SilentlyContinue }
|
|
|
|
if ($next.version) {
|
|
$notes = $null
|
|
if ($NotesPath) {
|
|
New-Item -ItemType Directory -Force -Path (Split-Path -Parent ([System.IO.Path]::GetFullPath($NotesPath))) | Out-Null
|
|
[System.IO.File]::WriteAllText($NotesPath, "$($next.notes)`n", [System.Text.UTF8Encoding]::new($false))
|
|
$notes = $NotesPath
|
|
}
|
|
$result = [pscustomobject]@{ Version = $next.version; Tag = $next.gitTag; LastVersion = $next.lastVersion; Type = $next.type; Notes = $notes }
|
|
}
|
|
else {
|
|
$own = @(& git -C $Root tag --points-at HEAD | Where-Object { $_ -match '^v\d{1,3}\.\d+\.\d+$' })
|
|
if ($own.Count -eq 0) {
|
|
Write-Host "Nothing to release: no fix, feat or breaking change since $($next.lastVersion)."
|
|
return
|
|
}
|
|
$version = $own[0].Substring(1)
|
|
$result = [pscustomobject]@{ Version = $version; Tag = $own[0]; LastVersion = $version; Type = 'rerun'; Notes = $null }
|
|
}
|
|
|
|
# The same limits every build version meets (major/minor up to 255, the rest up to 65535, no calendar era).
|
|
$null = & (Join-Path $PSScriptRoot 'Get-Version.ps1') -Version $result.Version
|
|
|
|
Write-Host "Release $($result.Version) ($($result.Type), after $($result.LastVersion))"
|
|
$result
|