Skip to content

Commit 7e38253

Browse files
🩹 [Patch]: Add options for using PR title and body as release name and notes in GitHub release
1 parent 2da4e21 commit 7e38253

3 files changed

Lines changed: 81 additions & 27 deletions

File tree

‎README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ The action can be configured using the following settings:
6565
| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | | `false` |
6666
| `Prerelease` | Allow prerelease versions if available. | `'false'` | `false` |
6767
| `WorkingDirectory` | The working directory where the script runs. | `'false'` | `'.'` |
68+
| `UsePRTitleAsReleaseName` | When enabled, uses the pull request title as the name for the GitHub release. If not set or the PR has no title, the version string is used. | `false` | false |
69+
| `UsePRBodyAsReleaseNotes` | When enabled, uses the pull request body as the release notes for the GitHub release. If not set or the PR has no body, the release notes are auto-generated. | `true` | false |
70+
| `UsePRTitleAsNotesHeading` | When enabled, the release notes will begin with the pull request title as a H1 heading followed by the pull request body, including a reference to the PR number. | `true` | false |
71+
72+
## Release Title and Notes Logic
73+
74+
- If `UsePRTitleAsReleaseName` is enabled and the pull request has a title, the release name will be set to the PR title. Otherwise, it defaults to the version string.
75+
- If `UsePRTitleAsNotesHeading` is enabled and the PR has both a title and body, the release notes will start with the PR title as a heading (with PR number), followed by the PR body.
76+
- If only `UsePRBodyAsReleaseNotes` is enabled and the PR has a body, the release notes will use the PR body.
77+
- If neither is enabled or the PR has no body, the release notes are auto-generated (`--generate-notes`).
78+
- The GitHub CLI command for creating the release is constructed stepwise, with `--title`, `--notes` (if provided), and `--generate-notes` as a fallback, matching the logic from Auto-Release.
79+
80+
The action outputs the calculated release name and body in the logs for visibility and testing.
6881

6982
## Example
7083

‎action.yml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ inputs:
7575
description: The working directory where the script will run from.
7676
required: false
7777
default: '.'
78+
UsePRTitleAsReleaseName:
79+
description: When enabled, uses the pull request title as the name for the GitHub release. If not set, the version string is used.
80+
required: false
81+
default: 'false'
82+
UsePRBodyAsReleaseNotes:
83+
description: When enabled, uses the pull request body as the release notes for the GitHub release. If not set, the release notes are auto-generated.
84+
required: false
85+
default: 'true'
86+
UsePRTitleAsNotesHeading:
87+
description: When enabled, the release notes will begin with the pull request title as a H1 heading followed by the pull request body. The title will reference the pull request number.
88+
required: false
89+
default: 'true'
7890

7991
runs:
8092
using: composite
@@ -99,6 +111,9 @@ runs:
99111
PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }}
100112
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
101113
PSMODULE_PUBLISH_PSMODULE_INPUT_WorkingDirectory: ${{ inputs.WorkingDirectory }}
114+
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes: ${{ inputs.UsePRBodyAsReleaseNotes }}
115+
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
116+
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }}
102117
with:
103118
Name: Publish-PSModule
104119
Debug: ${{ inputs.Debug }}

‎scripts/helpers/Publish-PSModule.ps1‎

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,24 @@
4545
$majorLabels = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_MajorLabels -split ',' | ForEach-Object { $_.Trim() }
4646
$minorLabels = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_MinorLabels -split ',' | ForEach-Object { $_.Trim() }
4747
$patchLabels = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_PatchLabels -split ',' | ForEach-Object { $_.Trim() }
48+
$usePRBodyAsReleaseNotes = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes -eq 'true'
49+
$usePRTitleAsReleaseName = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName -eq 'true'
50+
$usePRTitleAsNotesHeading = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading -eq 'true'
4851

4952
[pscustomobject]@{
50-
AutoCleanup = $autoCleanup
51-
AutoPatching = $autoPatching
52-
IncrementalPrerelease = $incrementalPrerelease
53-
DatePrereleaseFormat = $datePrereleaseFormat
54-
VersionPrefix = $versionPrefix
55-
WhatIf = $whatIf
56-
IgnoreLabels = $ignoreLabels
57-
MajorLabels = $majorLabels
58-
MinorLabels = $minorLabels
59-
PatchLabels = $patchLabels
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
63+
UsePRBodyAsReleaseNotes = $usePRBodyAsReleaseNotes
64+
UsePRTitleAsReleaseName = $usePRTitleAsReleaseName
65+
UsePRTitleAsNotesHeading = $usePRTitleAsNotesHeading
6066
} | Format-List | Out-String
6167
}
6268

@@ -355,25 +361,45 @@
355361

356362
LogGroup 'New-GitHubRelease' {
357363
Write-Output 'Create new GitHub release'
364+
$releaseCreateCommand = @('release', 'create', $newVersion.ToString())
365+
366+
# Add title parameter
367+
if ($usePRTitleAsReleaseName -and $pull_request.title) {
368+
$prTitle = $pull_request.title
369+
$releaseCreateCommand += @('--title', $prTitle)
370+
Write-Output "Using PR title as release name: [$prTitle]"
371+
} else {
372+
$releaseCreateCommand += @('--title', $newVersion.ToString())
373+
}
374+
375+
# Add notes parameter
376+
if ($usePRTitleAsNotesHeading -and $pull_request.title -and $pull_request.body) {
377+
$prTitle = $pull_request.title
378+
$prNumber = $pull_request.number
379+
$prBody = $pull_request.body
380+
$notes = "# $prTitle (#$prNumber)`n`n$prBody"
381+
$releaseCreateCommand += @('--notes', $notes)
382+
Write-Output 'Using PR title as H1 heading with link and body as release notes'
383+
} elseif ($usePRBodyAsReleaseNotes -and $pull_request.body) {
384+
$prBody = $pull_request.body
385+
$releaseCreateCommand += @('--notes', $prBody)
386+
Write-Output 'Using PR body as release notes'
387+
} else {
388+
$releaseCreateCommand += '--generate-notes'
389+
}
390+
391+
# Add remaining parameters
358392
if ($createPrerelease) {
359-
if ($whatIf) {
360-
Write-Output "WhatIf: gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease"
361-
} else {
362-
$releaseURL = gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease
363-
if ($LASTEXITCODE -ne 0) {
364-
Write-Error "Failed to create the release [$newVersion]."
365-
exit $LASTEXITCODE
366-
}
367-
}
393+
$releaseCreateCommand += @('--target', $prHeadRef, '--prerelease')
394+
}
395+
396+
if ($whatIf) {
397+
Write-Output "WhatIf: gh $($releaseCreateCommand -join ' ')"
368398
} else {
369-
if ($whatIf) {
370-
Write-Output "WhatIf: gh release create $newVersion --title $newVersion --generate-notes"
371-
} else {
372-
$releaseURL = gh release create $newVersion --title $newVersion --generate-notes
373-
if ($LASTEXITCODE -ne 0) {
374-
Write-Error "Failed to create the release [$newVersion]."
375-
exit $LASTEXITCODE
376-
}
399+
$releaseURL = gh @releaseCreateCommand
400+
if ($LASTEXITCODE -ne 0) {
401+
Write-Error "Failed to create the release [$newVersion]."
402+
exit $LASTEXITCODE
377403
}
378404
}
379405
if ($whatIf) {

0 commit comments

Comments
 (0)