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
88 changes: 88 additions & 0 deletions .github/scripts/Invoke-ReleaseFixture.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#Requires -Version 7.4

<#
.SYNOPSIS
Resolve a candidate or drive one case in the release fixture repository.

.DESCRIPTION
Run only in the producer's main-branch dispatch workflow. Read GH_TOKEN from the current step.

.EXAMPLE
./Invoke-ReleaseFixture.ps1 -Mode Resolve -PullRequest '109'
#>
[CmdletBinding(SupportsShouldProcess)]
param(
# Resolve a producer SHA, start a fixture case, or verify a merged fixture case.
[Parameter(Mandatory)]
[ValidateSet('Resolve', 'Start', 'Verify')]
[string] $Mode,

# Producer pull request number in Resolve mode or fixture pull request number in Verify mode.
[Parameter()]
[AllowEmptyString()]
[string] $PullRequest,

# Scenario name in Start mode.
[Parameter()]
[string] $Scenario,

# Resolved producer SHA in Start mode.
[Parameter()]
[string] $Candidate
)

$ErrorActionPreference = 'Stop'

if ($env:GITHUB_EVENT_NAME -cne 'workflow_dispatch' -or $env:GITHUB_REPOSITORY -cne 'PSModule/Release-GHRepository' -or
$env:GITHUB_REF -cne 'refs/heads/main') {
throw 'Run this driver only from a manual dispatch on PSModule/Release-GHRepository main.'
}
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'ReleaseFixture.psm1')

switch ($Mode) {
'Resolve' {
$sha = Resolve-ReleaseFixtureCandidate -PullRequest $PullRequest
Add-Content -LiteralPath $env:GITHUB_OUTPUT -Value "sha=$sha" -Encoding utf8
Write-Information -MessageData "Candidate commit: $sha" -InformationAction Continue
return
}
'Start' {
$caseId = "$env:GITHUB_RUN_ID-$env:GITHUB_RUN_ATTEMPT"
if (-not $PSCmdlet.ShouldProcess("Fixture case $caseId", 'Start')) {
return
}
$case = Start-ReleaseFixtureCase -Scenario $Scenario -Candidate $Candidate -CaseId $caseId -Confirm:$false
Add-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Value @(
"Fixture pull request: [#$($case.number)]($($case.url))"
''
"Case: $($case.caseId) | Scenario: $($case.scenario) | Candidate: $($case.candidate) | Head: $($case.head)"
''
)
Write-Information -MessageData "Opened $($case.url)" -InformationAction Continue
if ($case.scenario -ceq 'missing-decision') {
Add-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Value 'Close this pull request without merging.' -Encoding utf8
}
Add-ReleaseFixtureLabel -Case $case -Confirm:$false
$runType = 'Open pull request'
}
'Verify' {
$case = Get-MergedReleaseFixtureCase -PullRequest $PullRequest
Add-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Value @(
"Fixture pull request: [#$($case.number)]($($case.url))"
''
"Case: $($case.caseId) | Scenario: $($case.scenario) | Candidate: $($case.candidate) | Squash SHA: $($case.source)"
''
)
$runType = 'Final push'
}
}

$report = Wait-ReleaseFixtureReport -Case $case
Add-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Value @(
"${runType} run: [$($report.run)]($($report.run))"
''
)
if ($null -ne $report.tag) {
Add-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Value "Tag: $($report.tag)" -Encoding utf8
}
Write-Information -MessageData "Verified $($case.event) evidence: $($report.run)" -InformationAction Continue
Loading
Loading