Skip to content

Commit 4de61e0

Browse files
Harden release workflow review fixes
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 6aac86d commit 4de61e0

6 files changed

Lines changed: 33 additions & 7 deletions

File tree

.github/actions/Get-PSModuleSettings/src/main.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ LogGroup 'Calculate Job Run Conditions:' {
268268
-not [string]::IsNullOrWhiteSpace($pullRequest.merged_at)
269269
}
270270
$pullRequestIsClosed = $null -ne $pullRequest -and $pullRequest.State -eq 'closed'
271+
$isOpenOrUpdatedPR = $eventName -eq 'pull_request' -and
272+
-not $pullRequestIsClosed -and
273+
$pullRequestAction -in @('opened', 'reopened', 'synchronize', 'labeled', 'unlabeled')
271274
$targetBranch = if ($pullRequest) { $pullRequest.Base.Ref } elseif ($isPush) { $pushBranch } else { $workflowRef }
272275
$isTargetDefaultBranch = $targetBranch -eq $defaultBranch
273276
$pullRequestContext = if ($pullRequest) {

.github/actions/Release-PSModule/src/release.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
'PSUseDeclaredVarsMoreThanAssignments', 'commitSha',
4141
Justification = 'Variable is used in script blocks.'
4242
)]
43-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
44-
'PSUseDeclaredVarsMoreThanAssignments', 'commitMessage',
45-
Justification = 'Variable is used in script blocks.'
46-
)]
4743
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
4844
'PSUseDeclaredVarsMoreThanAssignments', 'releaseType',
4945
Justification = 'Variable is used in script blocks.'
@@ -112,6 +108,12 @@ LogGroup 'Load release context' {
112108
$prNumber = $pullRequest.Number
113109
$prHeadRef = $pullRequest.HeadRef
114110
$commitMessage = $githubEvent.head_commit.message
111+
if ([string]::IsNullOrWhiteSpace($commitMessage) -and -not [string]::IsNullOrWhiteSpace($commitSha)) {
112+
$commitMessage = git log -1 --format=%B $commitSha
113+
if ($LASTEXITCODE -ne 0) {
114+
throw "Failed to read commit message for [$commitSha]."
115+
}
116+
}
115117

116118
if ($prNumber) {
117119
Write-Host "Pull request: [#$prNumber]"

.github/actions/Release-PSModule/tests/Release-PSModule.WhatIf.Tests.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ AfterAll {
3636
[System.Environment]::SetEnvironmentVariable($name, $script:originalEnvironment[$name])
3737
}
3838
Remove-Item -Path function:global:gh -ErrorAction SilentlyContinue
39+
Remove-Item -Path function:global:git -ErrorAction SilentlyContinue
3940
}
4041

4142
Describe 'Release-PSModule WhatIf' {
@@ -140,4 +141,20 @@ Describe 'Release-PSModule WhatIf' {
140141
Get-Content -Path $script:githubOutputPath | Should -Contain 'ReleaseTag=v1.2.3'
141142
$releaseOutput | Should -Match '--target pushed-commit-sha'
142143
}
144+
145+
It 'uses the checked-out commit message for a manual dispatch' {
146+
$manifest = Get-Content -Path $manifestPath -Raw
147+
$manifest -replace "Prerelease = 'preview.1'", "Prerelease = ''" | Set-Content -Path $manifestPath
148+
@{} | ConvertTo-Json | Set-Content -Path $eventPath
149+
$env:PSMODULE_RELEASE_PSMODULE_INPUT_ReleaseTag = 'v1.2.3'
150+
$env:PSMODULE_RELEASE_PSMODULE_INPUT_CommitSha = 'dispatched-commit-sha'
151+
Set-Item -Path function:global:git -Value {
152+
$global:LASTEXITCODE = 0
153+
'Publish manual dispatch release'
154+
}
155+
156+
$releaseOutput = & $script:releaseScriptPath 6>&1 | Out-String
157+
158+
$releaseOutput | Should -Match 'Using the pushed commit message as release notes'
159+
}
143160
}

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ permissions:
7676
id-token: write # to verify the deployment originates from an appropriate source
7777

7878
concurrency:
79-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
79+
group: Process-PSModule-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
8080
cancel-in-progress: false
8181

8282
jobs:

docs/content/guides/calling-the-workflow.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Keep the `pull_request` trigger for CI, prereleases, and prerelease cleanup.
6464
The concurrency key keeps a pull request distinct from a default-branch push, so the close-event cleanup and the
6565
resulting stable release do not serialize as one run. Keep `cancel-in-progress: false`: a release-capable run mutates
6666
the PowerShell Gallery, GitHub Releases, and tags, so later runs must queue rather than interrupt it.
67+
The reusable workflow uses its own prefixed concurrency group, so it cannot queue behind the caller while the caller
68+
waits for it to finish.
6769

6870
## Passing test data
6971

docs/content/guides/versioning-and-releases.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ The label names are configurable through `Publish.Module.MajorLabels`, `MinorLab
4545
## Branch types
4646

4747
- **Main (stable)** — pushes publish stable releases. A prerelease label on an open pull request publishes a prerelease.
48-
- **Development** — optional prerelease branch (for example `dev`). Each push publishes a prerelease.
49-
- **Feature branch** — optional feature branch. A prerelease label publishes a prerelease for testing.
48+
- **Development** — optional prerelease branch (for example `dev`). Its open, prerelease-labelled pull request to the
49+
stable branch publishes previews when it is updated.
50+
- **Feature branch** — optional feature branch. Its open, prerelease-labelled pull request publishes a preview for
51+
testing.
5052

5153
Exactly one branch is authorized to publish stable releases, so consumers always have one unambiguous latest version.
5254

0 commit comments

Comments
 (0)