<# .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.. 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