From c017ec988aa6e254885ff18e2f9a6874ced6dde6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Jan 2026 02:42:32 +0100 Subject: [PATCH 1/6] Add target branch detection for default branch comparison --- scripts/main.ps1 | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 05e6189..47013da 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -231,11 +231,37 @@ LogGroup 'Calculate Job Run Conditions:' { $false } + # Get target branch (the branch the PR is merging into) + $targetBranch = if ($null -ne $pullRequest -and $null -ne $pullRequest.Base.Ref) { + $pullRequest.Base.Ref + } else { + $null + } + + # Get default branch from repository info + $defaultBranch = if ($null -ne $eventData.Repository.DefaultBranch) { + $eventData.Repository.DefaultBranch + } elseif ($null -ne $eventData.Repository.default_branch) { + $eventData.Repository.default_branch + } else { + $env:GITHUB_DEFAULT_BRANCH + } + + # Check if target branch is the default branch + $isTargetDefaultBranch = if ($null -ne $targetBranch -and $null -ne $defaultBranch) { + $targetBranch -eq $defaultBranch + } else { + $false + } + Write-Host 'GitHub event inputs:' [pscustomobject]@{ GITHUB_EVENT_NAME = $env:GITHUB_EVENT_NAME GITHUB_EVENT_ACTION = $pullRequestAction GITHUB_EVENT_PULL_REQUEST_MERGED = $pullRequestIsMerged + TargetBranch = $targetBranch + DefaultBranch = $defaultBranch + IsTargetDefaultBranch = $isTargetDefaultBranch } | Format-List | Out-String $isPR = $env:GITHUB_EVENT_NAME -eq 'pull_request' @@ -267,13 +293,14 @@ LogGroup 'Calculate Job Run Conditions:' { } [pscustomobject]@{ - isPR = $isPR - isOpenOrUpdatedPR = $isOpenOrUpdatedPR - isAbandonedPR = $isAbandonedPR - isMergedPR = $isMergedPR - isNotAbandonedPR = $isNotAbandonedPR - shouldPrerelease = $shouldPrerelease - ReleaseType = $releaseType + isPR = $isPR + isOpenOrUpdatedPR = $isOpenOrUpdatedPR + isAbandonedPR = $isAbandonedPR + isMergedPR = $isMergedPR + isNotAbandonedPR = $isNotAbandonedPR + isTargetDefaultBranch = $isTargetDefaultBranch + shouldPrerelease = $shouldPrerelease + ReleaseType = $releaseType } | Format-List | Out-String } From 0cf689b4f45451c47587238135f0816d23c5f919 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Jan 2026 02:47:31 +0100 Subject: [PATCH 2/6] Only create Release when PR merges to default branch --- scripts/main.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 47013da..2e36948 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -280,10 +280,13 @@ LogGroup 'Calculate Job Run Conditions:' { # Determine ReleaseType - single source of truth for what Publish-PSModule should do # Values: 'Release', 'Prerelease', 'Cleanup', 'None' + # Release only happens when PR is merged into the default branch $releaseType = if (-not $isPR) { 'None' - } elseif ($isMergedPR) { + } elseif ($isMergedPR -and $isTargetDefaultBranch) { 'Release' + } elseif ($isMergedPR -and -not $isTargetDefaultBranch) { + 'None' # Merged to non-default branch - no release } elseif ($isAbandonedPR) { 'Cleanup' } elseif ($shouldPrerelease) { From 2714999c0c353f72177986fd301bd167c650828e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Jan 2026 02:54:06 +0100 Subject: [PATCH 3/6] Refactor job run condition calculations for improved clarity and efficiency --- scripts/main.ps1 | 62 +++++++----------------------------------------- 1 file changed, 8 insertions(+), 54 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 2e36948..6f60909 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -195,64 +195,18 @@ $settings | Add-Member -MemberType NoteProperty -Name WorkingDirectory -Value $w # Calculate job run conditions LogGroup 'Calculate Job Run Conditions:' { - # Common conditions - $eventData = $null - try { - $eventData = Get-GitHubEventData -ErrorAction Stop - } catch { - if (-not [string]::IsNullOrEmpty($env:GITHUB_EVENT_PATH) -and (Test-Path -Path $env:GITHUB_EVENT_PATH)) { - $eventData = Get-Content -Path $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json - } - } + $eventData = Get-GitHubEventData -ErrorAction Stop LogGroup 'GitHub Event Data' { - if ($null -ne $eventData) { - Write-Host ($eventData | ConvertTo-Json -Depth 10 | Out-String) - } else { - Write-Host 'No event data available.' - } + $eventData | ConvertTo-Json -Depth 10 | Out-String } - $pullRequestAction = if ($null -ne $eventData.Action) { - $eventData.Action - } else { - $env:GITHUB_EVENT_ACTION - } - - $pullRequest = if ($null -ne $eventData.PullRequest) { - $eventData.PullRequest - } else { - $null - } - - $pullRequestIsMerged = if ($null -ne $pullRequest -and $null -ne $pullRequest.Merged) { - [bool]$pullRequest.Merged - } else { - $false - } - - # Get target branch (the branch the PR is merging into) - $targetBranch = if ($null -ne $pullRequest -and $null -ne $pullRequest.Base.Ref) { - $pullRequest.Base.Ref - } else { - $null - } - - # Get default branch from repository info - $defaultBranch = if ($null -ne $eventData.Repository.DefaultBranch) { - $eventData.Repository.DefaultBranch - } elseif ($null -ne $eventData.Repository.default_branch) { - $eventData.Repository.default_branch - } else { - $env:GITHUB_DEFAULT_BRANCH - } - - # Check if target branch is the default branch - $isTargetDefaultBranch = if ($null -ne $targetBranch -and $null -ne $defaultBranch) { - $targetBranch -eq $defaultBranch - } else { - $false - } + $pullRequestAction = $eventData.Action + $pullRequest = $eventData.PullRequest + $pullRequestIsMerged = $pullRequest.Merged + $targetBranch = $pullRequest.Base.Ref + $defaultBranch = $eventData.Repository.default_branch + $isTargetDefaultBranch = $targetBranch -eq $defaultBranch Write-Host 'GitHub event inputs:' [pscustomobject]@{ From d207d5976160040e79846e34919172d40ca5ea73 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Jan 2026 03:02:05 +0100 Subject: [PATCH 4/6] Only publish site when merging to default branch --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 6f60909..1b04145 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -451,7 +451,7 @@ LogGroup 'Calculate Job Run Conditions:' { ReleaseType = $releaseType # 'Release', 'Prerelease', 'Cleanup', or 'None' BuildDocs = $isNotAbandonedPR -and (-not $settings.Build.Docs.Skip) BuildSite = $isNotAbandonedPR -and (-not $settings.Build.Site.Skip) - PublishSite = $isMergedPR + PublishSite = $isMergedPR -and $isTargetDefaultBranch } $settings | Add-Member -MemberType NoteProperty -Name Run -Value $run From e58792548d82353056c469ceb6dc4b745f700566 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Jan 2026 03:11:15 +0100 Subject: [PATCH 5/6] Add newline at the end of README.md for better formatting --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0c23b4d..e66b3a0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # Get-PSModuleSettings This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). + From 0850528df72ecdc7e48e642a03a6d9fbb7f6754e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Jan 2026 03:12:57 +0100 Subject: [PATCH 6/6] Remove trailing newline from README.md for cleaner formatting --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index e66b3a0..0c23b4d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ # Get-PSModuleSettings This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). -