|
48 | 48 | $majorLabels = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_MajorLabels -split ',' | ForEach-Object { $_.Trim() } |
49 | 49 | $minorLabels = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_MinorLabels -split ',' | ForEach-Object { $_.Trim() } |
50 | 50 | $patchLabels = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_PatchLabels -split ',' | ForEach-Object { $_.Trim() } |
| 51 | + $usePRBodyAsReleaseNotes = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes -eq 'true' |
| 52 | + $usePRTitleAsReleaseName = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName -eq 'true' |
| 53 | + $usePRTitleAsNotesHeading = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading -eq 'true' |
51 | 54 |
|
52 | 55 | [pscustomobject]@{ |
53 | | - AutoCleanup = $autoCleanup |
54 | | - AutoPatching = $autoPatching |
55 | | - IncrementalPrerelease = $incrementalPrerelease |
56 | | - DatePrereleaseFormat = $datePrereleaseFormat |
57 | | - VersionPrefix = $versionPrefix |
58 | | - WhatIf = $whatIf |
59 | | - IgnoreLabels = $ignoreLabels |
60 | | - MajorLabels = $majorLabels |
61 | | - MinorLabels = $minorLabels |
62 | | - PatchLabels = $patchLabels |
| 56 | + AutoCleanup = $autoCleanup |
| 57 | + AutoPatching = $autoPatching |
| 58 | + IncrementalPrerelease = $incrementalPrerelease |
| 59 | + DatePrereleaseFormat = $datePrereleaseFormat |
| 60 | + VersionPrefix = $versionPrefix |
| 61 | + WhatIf = $whatIf |
| 62 | + IgnoreLabels = $ignoreLabels |
| 63 | + MajorLabels = $majorLabels |
| 64 | + MinorLabels = $minorLabels |
| 65 | + PatchLabels = $patchLabels |
| 66 | + UsePRBodyAsReleaseNotes = $usePRBodyAsReleaseNotes |
| 67 | + UsePRTitleAsReleaseName = $usePRTitleAsReleaseName |
| 68 | + UsePRTitleAsNotesHeading = $usePRTitleAsNotesHeading |
63 | 69 | } | Format-List | Out-String |
64 | 70 | } |
65 | 71 |
|
|
76 | 82 |
|
77 | 83 | Set-GitHubLogGroup 'Event information - Details' { |
78 | 84 | $defaultBranchName = (gh repo view --json defaultBranchRef | ConvertFrom-Json | Select-Object -ExpandProperty defaultBranchRef).name |
79 | | - $isPullRequest = $githubEvent.PSObject.Properties.Name -Contains 'pull_request' |
| 85 | + $isPullRequest = $githubEvent.PSObject.Properties.Name -contains 'pull_request' |
80 | 86 | if (-not ($isPullRequest -or $whatIf)) { |
81 | 87 | Write-Warning '⚠️ A release should not be created in this context. Exiting.' |
82 | 88 | exit |
|
113 | 119 | Set-GitHubLogGroup 'Calculate release type' { |
114 | 120 | $createRelease = $isMerged -and $targetIsDefaultBranch |
115 | 121 | $closedPullRequest = $prIsClosed -and -not $isMerged |
116 | | - $createPrerelease = $labels -Contains 'prerelease' -and -not $createRelease -and -not $closedPullRequest |
| 122 | + $createPrerelease = $labels -contains 'prerelease' -and -not $createRelease -and -not $closedPullRequest |
117 | 123 | $prereleaseName = $prHeadRef -replace '[^a-zA-Z0-9]' |
118 | 124 |
|
119 | 125 | $ignoreRelease = ($labels | Where-Object { $ignoreLabels -contains $_ }).Count -gt 0 |
|
358 | 364 |
|
359 | 365 | Set-GitHubLogGroup 'New-GitHubRelease' { |
360 | 366 | Write-Output 'Create new GitHub release' |
| 367 | + $releaseCreateCommand = @('release', 'create', $newVersion.ToString()) |
| 368 | + $notesFilePath = $null |
| 369 | + |
| 370 | + # Add title parameter |
| 371 | + if ($usePRTitleAsReleaseName -and $pull_request.title) { |
| 372 | + $prTitle = $pull_request.title |
| 373 | + $releaseCreateCommand += @('--title', $prTitle) |
| 374 | + Write-Output "Using PR title as release name: [$prTitle]" |
| 375 | + } else { |
| 376 | + $releaseCreateCommand += @('--title', $newVersion.ToString()) |
| 377 | + } |
| 378 | + |
| 379 | + # Build release notes content. Uses temp file to avoid escaping issues with special characters. |
| 380 | + # Precedence rules for the three UsePR* parameters: |
| 381 | + # 1. UsePRTitleAsNotesHeading + UsePRBodyAsReleaseNotes: Creates "# Title (#PR)\n\nBody" format. |
| 382 | + # Requires both parameters enabled AND both PR title and body to be present. |
| 383 | + # 2. UsePRBodyAsReleaseNotes only: Uses PR body as-is for release notes. |
| 384 | + # Takes effect when heading option is disabled/missing title, but body is available. |
| 385 | + # 3. Fallback: Auto-generates notes via GitHub's --generate-notes when no PR content is used. |
| 386 | + if ($usePRTitleAsNotesHeading -and $usePRBodyAsReleaseNotes -and $pull_request.title -and $pull_request.body) { |
| 387 | + # Path 1: Full PR-based notes with title as H1 heading and PR number link |
| 388 | + $prTitle = $pull_request.title |
| 389 | + $prNumber = $pull_request.number |
| 390 | + $prBody = $pull_request.body |
| 391 | + $notes = "# $prTitle (#$prNumber)`n`n$prBody" |
| 392 | + $notesFilePath = [System.IO.Path]::GetTempFileName() |
| 393 | + Set-Content -Path $notesFilePath -Value $notes -Encoding utf8 |
| 394 | + $releaseCreateCommand += @('--notes-file', $notesFilePath) |
| 395 | + Write-Output 'Using PR title as H1 heading with link and body as release notes' |
| 396 | + } elseif ($usePRBodyAsReleaseNotes -and $pull_request.body) { |
| 397 | + # Path 2: PR body only - no heading, just the body content |
| 398 | + $prBody = $pull_request.body |
| 399 | + $notesFilePath = [System.IO.Path]::GetTempFileName() |
| 400 | + Set-Content -Path $notesFilePath -Value $prBody -Encoding utf8 |
| 401 | + $releaseCreateCommand += @('--notes-file', $notesFilePath) |
| 402 | + Write-Output 'Using PR body as release notes' |
| 403 | + } else { |
| 404 | + # Path 3: Fallback to GitHub's auto-generated release notes |
| 405 | + $releaseCreateCommand += @('--generate-notes') |
| 406 | + } |
| 407 | + |
| 408 | + # Add remaining parameters |
361 | 409 | if ($createPrerelease) { |
362 | | - if ($whatIf) { |
363 | | - Write-Output "WhatIf: gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease" |
364 | | - } else { |
365 | | - $releaseURL = gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease |
366 | | - if ($LASTEXITCODE -ne 0) { |
367 | | - Write-Error "Failed to create the release [$newVersion]." |
368 | | - exit $LASTEXITCODE |
369 | | - } |
370 | | - } |
| 410 | + $releaseCreateCommand += @('--target', $prHeadRef, '--prerelease') |
| 411 | + } |
| 412 | + |
| 413 | + if ($whatIf) { |
| 414 | + Write-Output "WhatIf: gh $($releaseCreateCommand -join ' ')" |
371 | 415 | } else { |
372 | | - if ($whatIf) { |
373 | | - Write-Output "WhatIf: gh release create $newVersion --title $newVersion --generate-notes" |
374 | | - } else { |
375 | | - $releaseURL = gh release create $newVersion --title $newVersion --generate-notes |
376 | | - if ($LASTEXITCODE -ne 0) { |
377 | | - Write-Error "Failed to create the release [$newVersion]." |
378 | | - exit $LASTEXITCODE |
379 | | - } |
| 416 | + $releaseURL = gh @releaseCreateCommand |
| 417 | + if ($LASTEXITCODE -ne 0) { |
| 418 | + Write-Error "Failed to create the release [$newVersion]." |
| 419 | + exit $LASTEXITCODE |
380 | 420 | } |
381 | 421 | } |
| 422 | + |
| 423 | + # Clean up temporary notes file if created |
| 424 | + if ($notesFilePath -and (Test-Path -Path $notesFilePath)) { |
| 425 | + Remove-Item -Path $notesFilePath -Force |
| 426 | + } |
| 427 | + |
382 | 428 | if ($whatIf) { |
383 | 429 | Write-Output 'WhatIf: gh pr comment $pull_request.number -b "The release [$newVersion] has been created."' |
384 | 430 | } else { |
|
0 commit comments