Skip to content

Commit ce07e35

Browse files
Merge branch 'main' into dependabot/github_actions/github-actions-25c580fd63
2 parents 579fd96 + 5a11e8e commit ce07e35

35 files changed

Lines changed: 1261 additions & 265 deletions

.github/actions/Cleanup-PSModulePrereleases/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ inputs:
1111
description: GitHub release tag to retain during cleanup.
1212
required: false
1313
default: ''
14+
PullRequest:
15+
description: Normalized pull request context JSON from Get-PSModuleSettings.
16+
required: false
17+
default: ''
1418
WhatIf:
1519
description: If specified, the action will only log the changes it would make.
1620
required: false
@@ -33,5 +37,6 @@ runs:
3337
env:
3438
GH_TOKEN: ${{ env.GH_TOKEN }}
3539
PSMODULE_CLEANUP_PSMODULEPRERELEASES_INPUT_WhatIf: ${{ inputs.WhatIf }}
40+
PSMODULE_CLEANUP_PSMODULEPRERELEASES_INPUT_PullRequest: ${{ inputs.PullRequest }}
3641
PSMODULE_CLEANUP_PSMODULEPRERELEASES_CONTEXT_ReleaseTag: ${{ inputs.ReleaseTag }}
3742
run: ${{ github.action_path }}/src/cleanup.ps1

.github/actions/Cleanup-PSModulePrereleases/src/cleanup.ps1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ Import-Module -Name 'PSModule' -Force
99
LogGroup 'Load inputs' {
1010
$whatIf = $env:PSMODULE_CLEANUP_PSMODULEPRERELEASES_INPUT_WhatIf -eq 'true'
1111

12-
$githubEventJson = Get-Content -Raw $env:GITHUB_EVENT_PATH
13-
$githubEvent = $githubEventJson | ConvertFrom-Json
14-
$pull_request = $githubEvent.pull_request
15-
if (-not $pull_request) {
16-
throw 'GitHub event does not contain pull_request data. This script must be run from a pull_request event.'
12+
$pullRequestJson = $env:PSMODULE_CLEANUP_PSMODULEPRERELEASES_INPUT_PullRequest
13+
$prHeadRef = if (-not [string]::IsNullOrWhiteSpace($pullRequestJson) -and $pullRequestJson -ne 'null') {
14+
($pullRequestJson | ConvertFrom-Json).HeadRef
15+
} else {
16+
$githubEventJson = Get-Content -Raw $env:GITHUB_EVENT_PATH
17+
$githubEvent = $githubEventJson | ConvertFrom-Json
18+
$githubEvent.pull_request.head.ref
19+
}
20+
21+
if ([string]::IsNullOrWhiteSpace($prHeadRef)) {
22+
Write-Host '::notice::No pull request head ref is available. Nothing to cleanup.'
23+
exit 0
1724
}
18-
$prHeadRef = $pull_request.head.ref
1925
$prereleaseName = $prHeadRef -replace '[^a-zA-Z0-9]'
2026

2127
if ([string]::IsNullOrWhiteSpace($prereleaseName)) {
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
function Resolve-WorkflowEventRouting {
2+
<#
3+
.SYNOPSIS
4+
Resolves release and execution routing from normalized GitHub event state.
5+
#>
6+
[CmdletBinding()]
7+
[OutputType([PSCustomObject])]
8+
param(
9+
[Parameter(Mandatory)]
10+
[string] $EventName,
11+
12+
[Parameter()]
13+
[string] $EventAction,
14+
15+
[Parameter()]
16+
[bool] $PullRequestIsMerged,
17+
18+
[Parameter()]
19+
[bool] $PullRequestIsClosed,
20+
21+
[Parameter()]
22+
[bool] $IsTargetDefaultBranch,
23+
24+
[Parameter()]
25+
[bool] $IsPushToDefaultBranch,
26+
27+
[Parameter()]
28+
[bool] $IsManualDispatchToDefaultBranch,
29+
30+
[Parameter()]
31+
[bool] $HasImportantChanges,
32+
33+
[Parameter()]
34+
[bool] $HasPrereleaseLabel
35+
)
36+
37+
$isPR = $EventName -eq 'pull_request'
38+
$isPush = $EventName -eq 'push'
39+
$isManualDispatch = $EventName -eq 'workflow_dispatch'
40+
$isActivePR = $isPR -and -not $PullRequestIsClosed
41+
$isOpenOrUpdatedPR = $isActivePR -and $EventAction -in @('opened', 'reopened', 'synchronize', 'labeled', 'unlabeled')
42+
$isOpenOrLabeledPR = $isActivePR -and $EventAction -in @('opened', 'reopened', 'synchronize', 'labeled')
43+
$isClosedPR = $isPR -and $EventAction -eq 'closed'
44+
$isAbandonedPR = $isClosedPR -and -not $PullRequestIsMerged
45+
$isMergedPR = $isClosedPR -and $PullRequestIsMerged
46+
$shouldPrerelease = $isOpenOrLabeledPR -and $HasPrereleaseLabel -and $HasImportantChanges
47+
$shouldRelease = (
48+
($IsPushToDefaultBranch -or $IsManualDispatchToDefaultBranch) -and
49+
$HasImportantChanges
50+
)
51+
52+
[pscustomobject]@{
53+
IsPR = $isPR
54+
IsPush = $isPush
55+
IsManualDispatch = $isManualDispatch
56+
IsOpenOrUpdatedPR = $isOpenOrUpdatedPR
57+
IsOpenOrLabeledPR = $isOpenOrLabeledPR
58+
IsClosedPR = $isClosedPR
59+
IsAbandonedPR = $isAbandonedPR
60+
IsMergedPR = $isMergedPR
61+
IsTargetDefaultBranch = $IsTargetDefaultBranch
62+
IsPushToDefaultBranch = $IsPushToDefaultBranch
63+
IsManualDispatchToDefaultBranch = $IsManualDispatchToDefaultBranch
64+
ShouldPrerelease = $shouldPrerelease
65+
ReleaseType = if ($shouldRelease) {
66+
'Release'
67+
} elseif ($shouldPrerelease) {
68+
'Prerelease'
69+
} else {
70+
'None'
71+
}
72+
ShouldRunBuildTest = (
73+
-not $isClosedPR -and
74+
((-not $isPR) -or (-not $PullRequestIsClosed)) -and
75+
$HasImportantChanges
76+
)
77+
ShouldCleanupEvent = $isClosedPR
78+
ShouldRunCleanup = $isClosedPR -or $shouldRelease
79+
}
80+
}
81+
82+
function Select-PullRequestForPush {
83+
<#
84+
.SYNOPSIS
85+
Selects the merged default-branch pull request associated with a pushed commit.
86+
#>
87+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
88+
Justification = 'Parameter is used inside a Sort-Object script block.')]
89+
[CmdletBinding()]
90+
[OutputType([PSCustomObject])]
91+
param(
92+
[Parameter()]
93+
[object[]] $PullRequest,
94+
95+
[Parameter(Mandatory)]
96+
[string] $DefaultBranch,
97+
98+
[Parameter(Mandatory)]
99+
[string] $CommitSha
100+
)
101+
102+
$PullRequest |
103+
Where-Object {
104+
$_.Base.Ref -eq $DefaultBranch -and
105+
-not [string]::IsNullOrWhiteSpace($_.merged_at) -and
106+
$_.merge_commit_sha -eq $CommitSha
107+
} |
108+
Sort-Object -Property @{ Expression = { $_.merged_at }; Descending = $true } |
109+
Select-Object -First 1
110+
}
111+
112+
function Get-FilesFromGitTree {
113+
<#
114+
.SYNOPSIS
115+
Returns the files contained in a complete Git tree response.
116+
#>
117+
[CmdletBinding()]
118+
[OutputType([string])]
119+
param(
120+
[Parameter(Mandatory)]
121+
[PSCustomObject] $Tree
122+
)
123+
124+
if ($Tree.truncated) {
125+
throw 'Cannot determine changed files because the Git tree response was truncated.'
126+
}
127+
128+
$Tree.tree |
129+
Where-Object { $_.type -eq 'blob' } |
130+
Select-Object -ExpandProperty path
131+
}
132+
133+
function Get-FilesFromGitHubComparison {
134+
<#
135+
.SYNOPSIS
136+
Returns files from a complete GitHub compare response.
137+
#>
138+
[CmdletBinding()]
139+
[OutputType([string])]
140+
param(
141+
[Parameter(Mandatory)]
142+
[PSCustomObject] $Comparison
143+
)
144+
145+
$files = @($Comparison.files | Where-Object { $null -ne $_ })
146+
if ($files.Count -ge 300) {
147+
throw 'Cannot determine changed files because the GitHub compare response reached its 300-file limit.'
148+
}
149+
150+
$files | Select-Object -ExpandProperty filename
151+
}

.github/actions/Get-PSModuleSettings/src/Settings.schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@
196196
"description": "The type of release to create: Release (stable), Prerelease, or None."
197197
}
198198
}
199+
},
200+
"Site": {
201+
"type": "object",
202+
"description": "Documentation site publish configuration",
203+
"properties": {
204+
"Skip": {
205+
"type": "boolean",
206+
"description": "Skip publishing the generated documentation site"
207+
}
208+
}
199209
}
200210
}
201211
},

0 commit comments

Comments
 (0)