Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/linters/.jscpd.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"consoleFull"
],
"ignore": [
"**/tests/**"
"**/tests/**",
"**/scripts/**"
],
"absolute": true
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
59 changes: 55 additions & 4 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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 ''
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading