1+ Import-Module - Name (
2+ Join-Path - Path $PSScriptRoot - ChildPath ' ..' - AdditionalChildPath ' ..' , ' Release-PSModule' , ' src' , ' Release-PSModule.Helpers.psm1'
3+ ) - Force
4+
15function Resolve-WorkflowEventRouting {
26 <#
37 . SYNOPSIS
@@ -308,7 +312,11 @@ function Resolve-ReleasePullRequest {
308312
309313 # Returns the pull requests GitHub associates with a commit. Takes the commit SHA.
310314 [Parameter (Mandatory )]
311- [scriptblock ] $GetAssociatedPullRequest
315+ [scriptblock ] $GetAssociatedPullRequest ,
316+
317+ # Returns published GitHub releases whose immutable tag points to the commit.
318+ [Parameter ()]
319+ [scriptblock ] $GetPublishedReleaseForCommit
312320 )
313321
314322 $isPush = $EventName -eq ' push'
@@ -326,6 +334,17 @@ function Resolve-ReleasePullRequest {
326334 - DefaultBranch $DefaultBranch `
327335 - CommitSha $CommitSha
328336
337+ if ($IsManualDispatchToDefaultBranch -and $null -ne $GetPublishedReleaseForCommit ) {
338+ $published = @ ((& $GetPublishedReleaseForCommit $CommitSha ) | Where-Object { $null -ne $_ })
339+ if ($published.Count -gt 0 ) {
340+ throw (
341+ " Commit [$CommitSha ] already has a GitHub release: [$ ( $published.tag_name -join ' , ' ) ]. " +
342+ ' Do not resolve another version bump for this dispatch. Verify that the original version/tag ' +
343+ ' is unclaimed or belongs to its original commit, then rerun the original failed publication job.'
344+ )
345+ }
346+ }
347+
329348 if ($pullRequest ) {
330349 Write-Host " Resolved pull request #$ ( $pullRequest.Number ) from commit [$CommitSha ]."
331350 return [pscustomobject ]@ { Resolved = $true ; PullRequest = $pullRequest }
@@ -347,7 +366,8 @@ function Resolve-ReleasePullRequest {
347366 ' The following merged pull request(s) are associated with it but none matches the commit ' +
348367 " being released: $ ( $discarded -join ' ; ' ) . " +
349368 ' Refusing to discard the release intent and apply DefaultBump, because a wrong version published to the ' +
350- ' PowerShell Gallery cannot be reclaimed. Rerun the original workflow for the intended merge commit. ' +
369+ ' PowerShell Gallery cannot be reclaimed. Verify that the original version/tag is unclaimed or belongs to ' +
370+ ' the original commit before rerunning its failed workflow job. ' +
351371 ' A default-branch dispatch can recover that commit only while it is still the branch tip.'
352372 )
353373 }
@@ -357,6 +377,72 @@ function Resolve-ReleasePullRequest {
357377 }
358378}
359379
380+ function Get-PSModuleReleaseForCommit {
381+ <#
382+ . SYNOPSIS
383+ Find published releases bound to an exact commit.
384+
385+ . DESCRIPTION
386+ Resolves each stable release's tag reference and peels annotated tag
387+ objects. A mutable target_commitish creation hint is not source proof.
388+ Unresolvable or cyclic tag data fails rather than inventing a new bump.
389+
390+ . EXAMPLE
391+ Get-PSModuleReleaseForCommit -CommitSha $sha -Release $releases `
392+ -GetTagReference $readRef -GetTagObject $readTag
393+
394+ Returns stable releases whose actual tag resolves to the supplied SHA.
395+
396+ . INPUTS
397+ None
398+
399+ You can't pipe objects to Get-PSModuleReleaseForCommit.
400+
401+ . OUTPUTS
402+ System.Management.Automation.PSCustomObject
403+
404+ A published release bound to the supplied commit.
405+ #>
406+ [CmdletBinding ()]
407+ [OutputType ([PSCustomObject ])]
408+ param (
409+ # The immutable source commit being considered for recovery.
410+ [Parameter (Mandatory )]
411+ [ValidateNotNullOrEmpty ()]
412+ [string ] $CommitSha ,
413+
414+ # Returns the object referenced by a release tag name.
415+ [Parameter (Mandatory )]
416+ [scriptblock ] $GetTagReference ,
417+
418+ # Returns the object targeted by an annotated-tag SHA.
419+ [Parameter (Mandatory )]
420+ [scriptblock ] $GetTagObject ,
421+
422+ # REST release records, including tag_name, prerelease, and draft.
423+ [Parameter ()]
424+ [object []] $Release
425+ )
426+
427+ foreach ($candidate in $Release ) {
428+ if ($null -eq $candidate -or $candidate.prerelease -or $candidate.draft ) {
429+ continue
430+ }
431+ if ([string ]::IsNullOrWhiteSpace($candidate.tag_name )) {
432+ throw ' Cannot determine release source: a release has no tag_name.'
433+ }
434+ $parameters = @ {
435+ Tag = $candidate.tag_name
436+ GetTagReference = $GetTagReference
437+ GetTagObject = $GetTagObject
438+ }
439+ $source = Resolve-PSModuleReleaseTagCommit @parameters
440+ if ($source -ceq $CommitSha ) {
441+ $candidate
442+ }
443+ }
444+ }
445+
360446function Get-FilesFromGitTree {
361447 <#
362448 . SYNOPSIS
0 commit comments