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
4 changes: 3 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ updates:
- dependencies
- github-actions
schedule:
interval: weekly
interval: daily
cooldown:
default-days: 7
4 changes: 3 additions & 1 deletion .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v6
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false

- name: Action-Test
uses: ./
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/Auto-Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Auto-Release
run-name: "Auto-Release - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"

on:
pull_request_target:
pull_request:
branches:
- main
types:
Expand All @@ -26,9 +26,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v6
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false

- name: Auto-Release
uses: PSModule/Auto-Release@v1
uses: PSModule/Auto-Release@eabd533035e2cb9822160f26f2eda584bd012356 # v1.9.5
with:
IncrementalPrerelease: false
6 changes: 4 additions & 2 deletions .github/workflows/Linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v6
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false

- name: Lint code base
uses: super-linter/super-linter@latest
uses: super-linter/super-linter@d5b0a2ab116623730dd094f15ddc1b6b25bf7b99 # v8.3.2
env:
GITHUB_TOKEN: ${{ github.token }}
VALIDATE_BIOME_FORMAT: false
VALIDATE_JSON_PRETTIER: false
VALIDATE_MARKDOWN_PRETTIER: false
VALIDATE_YAML_PRETTIER: false
17 changes: 16 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,24 @@ inputs:
description: The working directory where the script will run from.
required: false
default: '.'
UsePRTitleAsReleaseName:
description: When enabled, uses the pull request title as the name for the GitHub release. If not set, the version string is used.
required: false
default: 'false'
UsePRBodyAsReleaseNotes:
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.
required: false
default: 'true'
UsePRTitleAsNotesHeading:
description: When enabled along with UsePRBodyAsReleaseNotes, 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.
required: false
default: 'true'

runs:
using: composite
steps:
- name: Install-PSModuleHelpers
uses: PSModule/Install-PSModuleHelpers@v1
uses: PSModule/Install-PSModuleHelpers@d60d63e4be477d1ca0c67c6085101fb109bce8f1 # v1.0.6

- name: Run Publish-PSModule
shell: pwsh
Expand All @@ -81,4 +93,7 @@ runs:
PSMODULE_PUBLISH_PSMODULE_INPUT_PatchLabels: ${{ inputs.PatchLabels }}
PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }}
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes: ${{ inputs.UsePRBodyAsReleaseNotes }}
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }}
run: ${{ github.action_path }}/scripts/main.ps1
104 changes: 75 additions & 29 deletions scripts/helpers/Publish-PSModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,24 @@
$majorLabels = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_MajorLabels -split ',' | ForEach-Object { $_.Trim() }
$minorLabels = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_MinorLabels -split ',' | ForEach-Object { $_.Trim() }
$patchLabels = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_PatchLabels -split ',' | ForEach-Object { $_.Trim() }
$usePRBodyAsReleaseNotes = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes -eq 'true'
$usePRTitleAsReleaseName = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName -eq 'true'
$usePRTitleAsNotesHeading = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading -eq 'true'

[pscustomobject]@{
AutoCleanup = $autoCleanup
AutoPatching = $autoPatching
IncrementalPrerelease = $incrementalPrerelease
DatePrereleaseFormat = $datePrereleaseFormat
VersionPrefix = $versionPrefix
WhatIf = $whatIf
IgnoreLabels = $ignoreLabels
MajorLabels = $majorLabels
MinorLabels = $minorLabels
PatchLabels = $patchLabels
AutoCleanup = $autoCleanup
AutoPatching = $autoPatching
IncrementalPrerelease = $incrementalPrerelease
DatePrereleaseFormat = $datePrereleaseFormat
VersionPrefix = $versionPrefix
WhatIf = $whatIf
IgnoreLabels = $ignoreLabels
MajorLabels = $majorLabels
MinorLabels = $minorLabels
PatchLabels = $patchLabels
UsePRBodyAsReleaseNotes = $usePRBodyAsReleaseNotes
UsePRTitleAsReleaseName = $usePRTitleAsReleaseName
UsePRTitleAsNotesHeading = $usePRTitleAsNotesHeading
} | Format-List | Out-String
}

Expand All @@ -76,7 +82,7 @@

Set-GitHubLogGroup 'Event information - Details' {
$defaultBranchName = (gh repo view --json defaultBranchRef | ConvertFrom-Json | Select-Object -ExpandProperty defaultBranchRef).name
$isPullRequest = $githubEvent.PSObject.Properties.Name -Contains 'pull_request'
$isPullRequest = $githubEvent.PSObject.Properties.Name -contains 'pull_request'
if (-not ($isPullRequest -or $whatIf)) {
Write-Warning '⚠️ A release should not be created in this context. Exiting.'
exit
Expand Down Expand Up @@ -113,7 +119,7 @@
Set-GitHubLogGroup 'Calculate release type' {
$createRelease = $isMerged -and $targetIsDefaultBranch
$closedPullRequest = $prIsClosed -and -not $isMerged
$createPrerelease = $labels -Contains 'prerelease' -and -not $createRelease -and -not $closedPullRequest
$createPrerelease = $labels -contains 'prerelease' -and -not $createRelease -and -not $closedPullRequest
$prereleaseName = $prHeadRef -replace '[^a-zA-Z0-9]'

$ignoreRelease = ($labels | Where-Object { $ignoreLabels -contains $_ }).Count -gt 0
Expand Down Expand Up @@ -358,27 +364,67 @@

Set-GitHubLogGroup 'New-GitHubRelease' {
Write-Output 'Create new GitHub release'
$releaseCreateCommand = @('release', 'create', $newVersion.ToString())
$notesFilePath = $null

# Add title parameter
if ($usePRTitleAsReleaseName -and $pull_request.title) {
$prTitle = $pull_request.title
$releaseCreateCommand += @('--title', $prTitle)
Write-Output "Using PR title as release name: [$prTitle]"
} else {
$releaseCreateCommand += @('--title', $newVersion.ToString())
}

# Build release notes content. Uses temp file to avoid escaping issues with special characters.
# Precedence rules for the three UsePR* parameters:
# 1. UsePRTitleAsNotesHeading + UsePRBodyAsReleaseNotes: Creates "# Title (#PR)\n\nBody" format.
# Requires both parameters enabled AND both PR title and body to be present.
# 2. UsePRBodyAsReleaseNotes only: Uses PR body as-is for release notes.
# Takes effect when heading option is disabled/missing title, but body is available.
# 3. Fallback: Auto-generates notes via GitHub's --generate-notes when no PR content is used.
if ($usePRTitleAsNotesHeading -and $usePRBodyAsReleaseNotes -and $pull_request.title -and $pull_request.body) {
# Path 1: Full PR-based notes with title as H1 heading and PR number link
$prTitle = $pull_request.title
$prNumber = $pull_request.number
$prBody = $pull_request.body
$notes = "# $prTitle (#$prNumber)`n`n$prBody"
$notesFilePath = [System.IO.Path]::GetTempFileName()
Set-Content -Path $notesFilePath -Value $notes -Encoding utf8
$releaseCreateCommand += @('--notes-file', $notesFilePath)
Write-Output 'Using PR title as H1 heading with link and body as release notes'
} elseif ($usePRBodyAsReleaseNotes -and $pull_request.body) {
# Path 2: PR body only - no heading, just the body content
$prBody = $pull_request.body
$notesFilePath = [System.IO.Path]::GetTempFileName()
Set-Content -Path $notesFilePath -Value $prBody -Encoding utf8
$releaseCreateCommand += @('--notes-file', $notesFilePath)
Write-Output 'Using PR body as release notes'
} else {
# Path 3: Fallback to GitHub's auto-generated release notes
$releaseCreateCommand += @('--generate-notes')
}

# Add remaining parameters
if ($createPrerelease) {
if ($whatIf) {
Write-Output "WhatIf: gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease"
} else {
$releaseURL = gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create the release [$newVersion]."
exit $LASTEXITCODE
}
}
$releaseCreateCommand += @('--target', $prHeadRef, '--prerelease')
}

if ($whatIf) {
Write-Output "WhatIf: gh $($releaseCreateCommand -join ' ')"
} else {
if ($whatIf) {
Write-Output "WhatIf: gh release create $newVersion --title $newVersion --generate-notes"
} else {
$releaseURL = gh release create $newVersion --title $newVersion --generate-notes
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create the release [$newVersion]."
exit $LASTEXITCODE
}
$releaseURL = gh @releaseCreateCommand
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create the release [$newVersion]."
exit $LASTEXITCODE
}
}

# Clean up temporary notes file if created
if ($notesFilePath -and (Test-Path -Path $notesFilePath)) {
Remove-Item -Path $notesFilePath -Force
}

if ($whatIf) {
Write-Output 'WhatIf: gh pr comment $pull_request.number -b "The release [$newVersion] has been created."'
} else {
Expand Down
Loading