lib/actions/releases/PublishReleaseAction/PublishReleaseAction.ps1
|
############################################################################# # PublishReleaseAction.ps1 - Publish a draft GitHub Release ############################################################################# class PublishReleaseAction : ReleaseRemediationAction { [int]$ReleaseId [Nullable[bool]]$MakeLatest = $null # Controls whether release should become latest ($true, $false, or $null to let GitHub decide) PublishReleaseAction([string]$tagName) : base("Publish release", $tagName) { $this.ReleaseId = 0 # Will be looked up if needed $this.Priority = 40 # Publish after creation } PublishReleaseAction([string]$tagName, [int]$releaseId) : base("Publish release", $tagName) { $this.ReleaseId = $releaseId $this.Priority = 40 # Publish after creation } [bool] Execute([RepositoryState]$state) { Write-Host "Auto-fix: Publish draft release for $($this.TagName)" $result = Publish-GitHubRelease -State $state -TagName $this.TagName -ReleaseId $this.ReleaseId -MakeLatest $this.MakeLatest if ($result.Success) { Write-Host "✓ Success: Published release for $($this.TagName)" return $true } else { # Check if this is an unfixable error (422 - tag used by immutable release) if ($this.IsUnfixableError($result)) { $suggestedIgnoreVersions = $this.GetSuggestedIgnoreVersions($state) $this.MarkAsUnfixable($state, "draft_release", "Release $($this.TagName) cannot be published because this tag was previously used by an immutable release that was deleted. Add $($this.TagName) to the ignore-versions list so floating versions and 'latest' fall back to the previous released version (new ignore-versions value: `"$suggestedIgnoreVersions`"), and/or publish a new patch (or minor) release so floating versions and 'latest' can advance to a version with a valid release.") } else { Write-Host "✗ Failed: Publish release for $($this.TagName)" } return $false } } [string[]] GetManualCommands([RepositoryState]$state) { # Check if the issue is unfixable - if so, return a copy/pasteable # ignore-versions YAML snippet instead of a CLI command if ($this.IsIssueUnfixable($state, "draft_release")) { return $this.GetIgnoreVersionsYamlSnippet($state) } $repoArg = "" if ($state.RepoOwner -and $state.RepoName) { $repoArg = " --repo $($state.RepoOwner)/$($state.RepoName)" } $latestArg = "" if ($null -ne $this.MakeLatest) { $latestArg = if ($this.MakeLatest) { " --latest" } else { " --latest=false" } } return @("gh release edit $($this.TagName)$repoArg --draft=false$latestArg") } } |