Skip to content

Commit 8fd4447

Browse files
Treat an empty GitHub release list as a valid starting state
A repository that has never released returns '[]' from 'gh release list', which deserializes to nothing and reached the version helpers as $null. Return an array instead and let the helpers bind an empty one. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent b11b310 commit 8fd4447

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

.github/actions/Resolve-PSModuleVersion/src/Resolve-PSModuleVersion.Helpers.psm1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ function Get-GitHubRelease {
298298
Write-Error 'Failed to list releases for the repo.'
299299
exit $LASTEXITCODE
300300
}
301-
$releases = $releasesJson | ConvertFrom-Json
301+
# A repository that has never released returns '[]', which deserializes to nothing. Wrap the
302+
# result so callers always receive an array, even for a module being bootstrapped.
303+
$releases = @($releasesJson | ConvertFrom-Json)
302304

303305
Write-Host '-------------------------------------------------'
304306
Write-Host ($releases | Select-Object -Property name, isPrerelease, isLatest, publishedAt |
@@ -327,6 +329,7 @@ function Get-LatestGitHubVersion {
327329
param(
328330
# The GitHub releases array to search.
329331
[Parameter(Mandatory)]
332+
[AllowEmptyCollection()]
330333
[array] $Releases
331334
)
332335

@@ -474,6 +477,7 @@ function Get-NextPrereleaseNumber {
474477

475478
# The GitHub releases list.
476479
[Parameter(Mandatory)]
480+
[AllowEmptyCollection()]
477481
[array] $Releases
478482
)
479483

@@ -551,6 +555,7 @@ function Get-NextModuleVersion {
551555

552556
# The GitHub releases list, used for incremental prerelease calculation.
553557
[Parameter(Mandatory)]
558+
[AllowEmptyCollection()]
554559
[array] $Releases
555560
)
556561

.github/actions/Resolve-PSModuleVersion/src/main.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $decision = if ($null -eq $pullRequest) {
2828
Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest
2929
}
3030

31-
$releases = Get-GitHubRelease
31+
$releases = @(Get-GitHubRelease)
3232
$ghVersion = Get-LatestGitHubVersion -Releases $releases
3333
$psGalleryVersion = Get-LatestPSGalleryVersion -ModuleName $actionInput.Name
3434
$latestVersion = Get-LatestPublishedVersion -GitHubVersion $ghVersion -PSGalleryVersion $psGalleryVersion

0 commit comments

Comments
 (0)