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
@@ -227,7 +231,11 @@ function Resolve-ReleasePullRequest {
227231
228232 # Returns the pull requests GitHub associates with a commit. Takes the commit SHA.
229233 [Parameter (Mandatory )]
230- [scriptblock ] $GetAssociatedPullRequest
234+ [scriptblock ] $GetAssociatedPullRequest ,
235+
236+ # Returns published GitHub releases whose immutable tag points to the commit.
237+ [Parameter ()]
238+ [scriptblock ] $GetPublishedReleaseForCommit
231239 )
232240
233241 $isPush = $EventName -eq ' push'
@@ -245,6 +253,17 @@ function Resolve-ReleasePullRequest {
245253 - DefaultBranch $DefaultBranch `
246254 - CommitSha $CommitSha
247255
256+ if ($IsManualDispatchToDefaultBranch -and $null -ne $GetPublishedReleaseForCommit ) {
257+ $published = @ ((& $GetPublishedReleaseForCommit $CommitSha ) | Where-Object { $null -ne $_ })
258+ if ($published.Count -gt 0 ) {
259+ throw (
260+ " Commit [$CommitSha ] already has a GitHub release: [$ ( $published.tag_name -join ' , ' ) ]. " +
261+ ' Do not resolve another version bump for this dispatch. Verify that the original version/tag ' +
262+ ' is unclaimed or belongs to its original commit, then rerun the original failed publication job.'
263+ )
264+ }
265+ }
266+
248267 if ($pullRequest ) {
249268 Write-Host " Resolved pull request #$ ( $pullRequest.Number ) from commit [$CommitSha ]."
250269 return [pscustomobject ]@ { Resolved = $true ; PullRequest = $pullRequest }
@@ -266,7 +285,8 @@ function Resolve-ReleasePullRequest {
266285 ' The following merged pull request(s) are associated with it but none matches the commit ' +
267286 " being released: $ ( $discarded -join ' ; ' ) . " +
268287 ' Refusing to fall back to a patch bump, because a wrong version published to the ' +
269- ' PowerShell Gallery cannot be reclaimed. Rerun the original workflow for the intended merge commit. ' +
288+ ' PowerShell Gallery cannot be reclaimed. Verify that the original version/tag is unclaimed or belongs to ' +
289+ ' the original commit before rerunning its failed workflow job. ' +
270290 ' A default-branch dispatch can recover that commit only while it is still the branch tip.'
271291 )
272292 }
@@ -276,6 +296,72 @@ function Resolve-ReleasePullRequest {
276296 }
277297}
278298
299+ function Get-PSModuleReleaseForCommit {
300+ <#
301+ . SYNOPSIS
302+ Find published releases bound to an exact commit.
303+
304+ . DESCRIPTION
305+ Resolves each stable release's tag reference and peels annotated tag
306+ objects. A mutable target_commitish creation hint is not source proof.
307+ Unresolvable or cyclic tag data fails rather than inventing a new bump.
308+
309+ . EXAMPLE
310+ Get-PSModuleReleaseForCommit -CommitSha $sha -Release $releases `
311+ -GetTagReference $readRef -GetTagObject $readTag
312+
313+ Returns stable releases whose actual tag resolves to the supplied SHA.
314+
315+ . INPUTS
316+ None
317+
318+ You can't pipe objects to Get-PSModuleReleaseForCommit.
319+
320+ . OUTPUTS
321+ System.Management.Automation.PSCustomObject
322+
323+ A published release bound to the supplied commit.
324+ #>
325+ [CmdletBinding ()]
326+ [OutputType ([PSCustomObject ])]
327+ param (
328+ # The immutable source commit being considered for recovery.
329+ [Parameter (Mandatory )]
330+ [ValidateNotNullOrEmpty ()]
331+ [string ] $CommitSha ,
332+
333+ # Returns the object referenced by a release tag name.
334+ [Parameter (Mandatory )]
335+ [scriptblock ] $GetTagReference ,
336+
337+ # Returns the object targeted by an annotated-tag SHA.
338+ [Parameter (Mandatory )]
339+ [scriptblock ] $GetTagObject ,
340+
341+ # REST release records, including tag_name, prerelease, and draft.
342+ [Parameter ()]
343+ [object []] $Release
344+ )
345+
346+ foreach ($candidate in $Release ) {
347+ if ($null -eq $candidate -or $candidate.prerelease -or $candidate.draft ) {
348+ continue
349+ }
350+ if ([string ]::IsNullOrWhiteSpace($candidate.tag_name )) {
351+ throw ' Cannot determine release source: a release has no tag_name.'
352+ }
353+ $parameters = @ {
354+ Tag = $candidate.tag_name
355+ GetTagReference = $GetTagReference
356+ GetTagObject = $GetTagObject
357+ }
358+ $source = Resolve-PSModuleReleaseTagCommit @parameters
359+ if ($source -ceq $CommitSha ) {
360+ $candidate
361+ }
362+ }
363+ }
364+
279365function Get-FilesFromGitTree {
280366 <#
281367 . SYNOPSIS
0 commit comments