diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json index 23970e8..754ec0c 100644 --- a/.github/linters/.jscpd.json +++ b/.github/linters/.jscpd.json @@ -4,7 +4,8 @@ "consoleFull" ], "ignore": [ - "**/tests/**" + "**/tests/**", + "**/scripts/**" ], "absolute": true } diff --git a/README.md b/README.md index 1e5fc55..aba9bb9 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ The action can be configured using the following settings: | `MajorLabels` | A comma separated list of labels that trigger a major release. | `major, breaking` | false | | `MinorLabels` | A comma separated list of labels that trigger a minor release. | `minor, feature` | false | | `PatchLabels` | A comma separated list of labels that trigger a patch release. | `patch, fix` | false | +| `UsePRTitleAsReleaseName` | When enabled, uses the pull request title as the name for the GitHub release. | `false` | false | +| `UsePRBodyAsReleaseNotes` | When enabled, uses the pull request body as the release notes for the GitHub release. | `true` | false | | `VersionPrefix` | The prefix to use for the version number. | `v` | false | | `WhatIf` | Control wether to simulate the action. If enabled, the action will not create any releases. Used for testing. | `false` | false | | `Debug` | Enable debug output. | `'false'` | false | diff --git a/action.yml b/action.yml index 2453f28..9c1360a 100644 --- a/action.yml +++ b/action.yml @@ -50,6 +50,14 @@ inputs: description: A comma separated list of labels that trigger a patch release. required: false default: patch, fix + UsePRTitleAsReleaseName: + description: When enabled, uses the pull request title as the name for the GitHub release. + required: false + default: 'false' + UsePRBodyAsReleaseNotes: + description: When enabled, uses the pull request body as the release notes for the GitHub release. + required: false + default: 'true' VersionPrefix: description: The prefix to use for the version number. required: false @@ -95,6 +103,8 @@ runs: PSMODULE_AUTO_RELEASE_INPUT_MajorLabels: ${{ inputs.MajorLabels }} PSMODULE_AUTO_RELEASE_INPUT_MinorLabels: ${{ inputs.MinorLabels }} PSMODULE_AUTO_RELEASE_INPUT_PatchLabels: ${{ inputs.PatchLabels }} + PSMODULE_AUTO_RELEASE_INPUT_UsePRBodyAsReleaseNotes: ${{ inputs.UsePRBodyAsReleaseNotes }} + PSMODULE_AUTO_RELEASE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }} PSMODULE_AUTO_RELEASE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }} PSMODULE_AUTO_RELEASE_INPUT_WhatIf: ${{ inputs.WhatIf }} with: diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 7ce66ce..516bbc6 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -45,6 +45,8 @@ LogGroup 'Set configuration' { $createMinorTag = ![string]::IsNullOrEmpty($configuration.CreateMinorTag) ? $configuration.CreateMinorTag -eq 'true' : $env:PSMODULE_AUTO_RELEASE_INPUT_CreateMinorTag -eq 'true' $datePrereleaseFormat = ![string]::IsNullOrEmpty($configuration.DatePrereleaseFormat) ? $configuration.DatePrereleaseFormat : $env:PSMODULE_AUTO_RELEASE_INPUT_DatePrereleaseFormat $incrementalPrerelease = ![string]::IsNullOrEmpty($configuration.IncrementalPrerelease) ? $configuration.IncrementalPrerelease -eq 'true' : $env:PSMODULE_AUTO_RELEASE_INPUT_IncrementalPrerelease -eq 'true' + $usePRBodyAsReleaseNotes = ![string]::IsNullOrEmpty($configuration.UsePRBodyAsReleaseNotes) ? $configuration.UsePRBodyAsReleaseNotes -eq 'true' : $env:PSMODULE_AUTO_RELEASE_INPUT_UsePRBodyAsReleaseNotes -eq 'true' + $usePRTitleAsReleaseName = ![string]::IsNullOrEmpty($configuration.UsePRTitleAsReleaseName) ? $configuration.UsePRTitleAsReleaseName -eq 'true' : $env:PSMODULE_AUTO_RELEASE_INPUT_UsePRTitleAsReleaseName -eq 'true' $versionPrefix = ![string]::IsNullOrEmpty($configuration.VersionPrefix) ? $configuration.VersionPrefix : $env:PSMODULE_AUTO_RELEASE_INPUT_VersionPrefix $whatIf = ![string]::IsNullOrEmpty($configuration.WhatIf) ? $configuration.WhatIf -eq 'true' : $env:PSMODULE_AUTO_RELEASE_INPUT_WhatIf -eq 'true' @@ -60,6 +62,8 @@ LogGroup 'Set configuration' { Write-Output "Create minor tag enabled: [$createMinorTag]" Write-Output "Date-based prerelease format: [$datePrereleaseFormat]" Write-Output "Incremental prerelease enabled: [$incrementalPrerelease]" + Write-Output "Use PR body as release notes: [$usePRBodyAsReleaseNotes]" + Write-Output "Use PR title as release name: [$usePRTitleAsReleaseName]" Write-Output "Version prefix: [$versionPrefix]" Write-Output "What if mode: [$whatIf]" Write-Output '' @@ -226,10 +230,35 @@ if ($createPrerelease -or $createRelease -or $whatIf) { } } + # Build release creation command with options + $releaseCreateCommand = @("release", "create", "$newVersion") + + # Add title parameter + if ($usePRTitleAsReleaseName) { + $prTitle = $pull_request.title + $releaseCreateCommand += @("--title", "$prTitle") + Write-Output "Using PR title as release name: [$prTitle]" + } else { + $releaseCreateCommand += @("--title", "$newVersion") + } + + # Add notes parameter + if ($usePRBodyAsReleaseNotes) { + $prBody = $pull_request.body + $releaseCreateCommand += @("--notes", "$prBody") + Write-Output 'Using PR body as release notes' + } else { + $releaseCreateCommand += '--generate-notes' + } + + # Add remaining parameters + $releaseCreateCommand += @("--target", $prHeadRef, "--prerelease") + if ($whatIf) { - Write-Output "WhatIf: gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease" + Write-Output "WhatIf: $releaseCreateCommand" } else { - $releaseURL = gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease + # Execute the command and capture the output + $releaseURL = gh @releaseCreateCommand if ($LASTEXITCODE -ne 0) { Write-Error "Failed to create the release [$newVersion]." exit $LASTEXITCODE @@ -246,10 +275,32 @@ if ($createPrerelease -or $createRelease -or $whatIf) { } } } else { + # Build release creation command with options + $releaseCreateCommand = @("release", "create", "$newVersion") + + # Add title parameter + if ($usePRTitleAsReleaseName) { + $prTitle = $pull_request.title + $releaseCreateCommand += @("--title", "$prTitle") + Write-Output "Using PR title as release name: [$prTitle]" + } else { + $releaseCreateCommand += @("--title", "$newVersion") + } + + # Add notes parameter + if ($usePRBodyAsReleaseNotes) { + $prBody = $pull_request.body + $releaseCreateCommand += @("--notes", "$prBody") + Write-Output 'Using PR body as release notes' + } else { + $releaseCreateCommand += '--generate-notes' + } + if ($whatIf) { - Write-Output "WhatIf: gh release create $newVersion --title $newVersion --generate-notes" + Write-Output "WhatIf: $releaseCreateCommand" } else { - gh release create $newVersion --title $newVersion --generate-notes + # Execute the command + gh @releaseCreateCommand if ($LASTEXITCODE -ne 0) { Write-Error "Failed to create the release [$newVersion]." exit $LASTEXITCODE