Skip to content

Commit 9c8306e

Browse files
🚀 [Feature]: Add options to use PR title and body as release title and body (#79)
## Description - Adds `UsePRBodyAsReleaseNotes` and `UsePRTitleAsReleaseName` inputs. This allow you to configure the action to copy the PR body into the release notes and/or use the PR title as the release name. - Fixes #72 - Changes the default behavior of the action from using the built in release note generation using the .github/release.yml instructions to use the PR body for release notes (`UsePRBodyAsReleaseNotes = true`). The release title remains as before with using the semantic‑version tag. You can opt out of this new functionality by setting the input(s) to `false`. ### 📋 How to use the new options ```yaml steps: - uses: PSModule/Auto-Release@vNext with: UsePRBodyAsReleaseNotes: true # default is true UsePRTitleAsReleaseName: false # default is false ``` ### ⏭️ Migration guide Current adopters that relied on the previous default (generated changelog as release notes) should explicitly set `UsePRBodyAsReleaseNotes: false` to keep former behavior.
1 parent 9edab5d commit 9c8306e

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

.github/linters/.jscpd.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"consoleFull"
55
],
66
"ignore": [
7-
"**/tests/**"
7+
"**/tests/**",
8+
"**/scripts/**"
89
],
910
"absolute": true
1011
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ The action can be configured using the following settings:
5050
| `MajorLabels` | A comma separated list of labels that trigger a major release. | `major, breaking` | false |
5151
| `MinorLabels` | A comma separated list of labels that trigger a minor release. | `minor, feature` | false |
5252
| `PatchLabels` | A comma separated list of labels that trigger a patch release. | `patch, fix` | false |
53+
| `UsePRTitleAsReleaseName` | When enabled, uses the pull request title as the name for the GitHub release. | `false` | false |
54+
| `UsePRBodyAsReleaseNotes` | When enabled, uses the pull request body as the release notes for the GitHub release. | `true` | false |
5355
| `VersionPrefix` | The prefix to use for the version number. | `v` | false |
5456
| `WhatIf` | Control wether to simulate the action. If enabled, the action will not create any releases. Used for testing. | `false` | false |
5557
| `Debug` | Enable debug output. | `'false'` | false |

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ inputs:
5050
description: A comma separated list of labels that trigger a patch release.
5151
required: false
5252
default: patch, fix
53+
UsePRTitleAsReleaseName:
54+
description: When enabled, uses the pull request title as the name for the GitHub release.
55+
required: false
56+
default: 'false'
57+
UsePRBodyAsReleaseNotes:
58+
description: When enabled, uses the pull request body as the release notes for the GitHub release.
59+
required: false
60+
default: 'true'
5361
VersionPrefix:
5462
description: The prefix to use for the version number.
5563
required: false
@@ -95,6 +103,8 @@ runs:
95103
PSMODULE_AUTO_RELEASE_INPUT_MajorLabels: ${{ inputs.MajorLabels }}
96104
PSMODULE_AUTO_RELEASE_INPUT_MinorLabels: ${{ inputs.MinorLabels }}
97105
PSMODULE_AUTO_RELEASE_INPUT_PatchLabels: ${{ inputs.PatchLabels }}
106+
PSMODULE_AUTO_RELEASE_INPUT_UsePRBodyAsReleaseNotes: ${{ inputs.UsePRBodyAsReleaseNotes }}
107+
PSMODULE_AUTO_RELEASE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
98108
PSMODULE_AUTO_RELEASE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }}
99109
PSMODULE_AUTO_RELEASE_INPUT_WhatIf: ${{ inputs.WhatIf }}
100110
with:

scripts/main.ps1

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ LogGroup 'Set configuration' {
4545
$createMinorTag = ![string]::IsNullOrEmpty($configuration.CreateMinorTag) ? $configuration.CreateMinorTag -eq 'true' : $env:PSMODULE_AUTO_RELEASE_INPUT_CreateMinorTag -eq 'true'
4646
$datePrereleaseFormat = ![string]::IsNullOrEmpty($configuration.DatePrereleaseFormat) ? $configuration.DatePrereleaseFormat : $env:PSMODULE_AUTO_RELEASE_INPUT_DatePrereleaseFormat
4747
$incrementalPrerelease = ![string]::IsNullOrEmpty($configuration.IncrementalPrerelease) ? $configuration.IncrementalPrerelease -eq 'true' : $env:PSMODULE_AUTO_RELEASE_INPUT_IncrementalPrerelease -eq 'true'
48+
$usePRBodyAsReleaseNotes = ![string]::IsNullOrEmpty($configuration.UsePRBodyAsReleaseNotes) ? $configuration.UsePRBodyAsReleaseNotes -eq 'true' : $env:PSMODULE_AUTO_RELEASE_INPUT_UsePRBodyAsReleaseNotes -eq 'true'
49+
$usePRTitleAsReleaseName = ![string]::IsNullOrEmpty($configuration.UsePRTitleAsReleaseName) ? $configuration.UsePRTitleAsReleaseName -eq 'true' : $env:PSMODULE_AUTO_RELEASE_INPUT_UsePRTitleAsReleaseName -eq 'true'
4850
$versionPrefix = ![string]::IsNullOrEmpty($configuration.VersionPrefix) ? $configuration.VersionPrefix : $env:PSMODULE_AUTO_RELEASE_INPUT_VersionPrefix
4951
$whatIf = ![string]::IsNullOrEmpty($configuration.WhatIf) ? $configuration.WhatIf -eq 'true' : $env:PSMODULE_AUTO_RELEASE_INPUT_WhatIf -eq 'true'
5052

@@ -60,6 +62,8 @@ LogGroup 'Set configuration' {
6062
Write-Output "Create minor tag enabled: [$createMinorTag]"
6163
Write-Output "Date-based prerelease format: [$datePrereleaseFormat]"
6264
Write-Output "Incremental prerelease enabled: [$incrementalPrerelease]"
65+
Write-Output "Use PR body as release notes: [$usePRBodyAsReleaseNotes]"
66+
Write-Output "Use PR title as release name: [$usePRTitleAsReleaseName]"
6367
Write-Output "Version prefix: [$versionPrefix]"
6468
Write-Output "What if mode: [$whatIf]"
6569
Write-Output ''
@@ -226,10 +230,35 @@ if ($createPrerelease -or $createRelease -or $whatIf) {
226230
}
227231
}
228232

233+
# Build release creation command with options
234+
$releaseCreateCommand = @("release", "create", "$newVersion")
235+
236+
# Add title parameter
237+
if ($usePRTitleAsReleaseName) {
238+
$prTitle = $pull_request.title
239+
$releaseCreateCommand += @("--title", "$prTitle")
240+
Write-Output "Using PR title as release name: [$prTitle]"
241+
} else {
242+
$releaseCreateCommand += @("--title", "$newVersion")
243+
}
244+
245+
# Add notes parameter
246+
if ($usePRBodyAsReleaseNotes) {
247+
$prBody = $pull_request.body
248+
$releaseCreateCommand += @("--notes", "$prBody")
249+
Write-Output 'Using PR body as release notes'
250+
} else {
251+
$releaseCreateCommand += '--generate-notes'
252+
}
253+
254+
# Add remaining parameters
255+
$releaseCreateCommand += @("--target", $prHeadRef, "--prerelease")
256+
229257
if ($whatIf) {
230-
Write-Output "WhatIf: gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease"
258+
Write-Output "WhatIf: $releaseCreateCommand"
231259
} else {
232-
$releaseURL = gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease
260+
# Execute the command and capture the output
261+
$releaseURL = gh @releaseCreateCommand
233262
if ($LASTEXITCODE -ne 0) {
234263
Write-Error "Failed to create the release [$newVersion]."
235264
exit $LASTEXITCODE
@@ -246,10 +275,32 @@ if ($createPrerelease -or $createRelease -or $whatIf) {
246275
}
247276
}
248277
} else {
278+
# Build release creation command with options
279+
$releaseCreateCommand = @("release", "create", "$newVersion")
280+
281+
# Add title parameter
282+
if ($usePRTitleAsReleaseName) {
283+
$prTitle = $pull_request.title
284+
$releaseCreateCommand += @("--title", "$prTitle")
285+
Write-Output "Using PR title as release name: [$prTitle]"
286+
} else {
287+
$releaseCreateCommand += @("--title", "$newVersion")
288+
}
289+
290+
# Add notes parameter
291+
if ($usePRBodyAsReleaseNotes) {
292+
$prBody = $pull_request.body
293+
$releaseCreateCommand += @("--notes", "$prBody")
294+
Write-Output 'Using PR body as release notes'
295+
} else {
296+
$releaseCreateCommand += '--generate-notes'
297+
}
298+
249299
if ($whatIf) {
250-
Write-Output "WhatIf: gh release create $newVersion --title $newVersion --generate-notes"
300+
Write-Output "WhatIf: $releaseCreateCommand"
251301
} else {
252-
gh release create $newVersion --title $newVersion --generate-notes
302+
# Execute the command
303+
gh @releaseCreateCommand
253304
if ($LASTEXITCODE -ne 0) {
254305
Write-Error "Failed to create the release [$newVersion]."
255306
exit $LASTEXITCODE

0 commit comments

Comments
 (0)