forked from Badgerati/Pode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
4,303 additions
and
3,921 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')] | ||
param ( | ||
[Parameter(Mandatory)] | ||
[string]$PodeVersion, | ||
|
||
[Parameter(Mandatory)] | ||
[string]$PreReleaseType, | ||
|
||
[Parameter()] | ||
[int[]]$ExcludePRs, | ||
|
||
[Parameter()] | ||
[switch]$Force | ||
) | ||
|
||
|
||
Add-BuildTask UpdateDevelop { | ||
git fetch upstream | ||
git checkout develop | ||
|
||
if (-not $Force) { | ||
$confirmation = Read-Host "⚠️ WARNING: This action will reset and force push 'develop' to match upstream. This is irreversible! Type 'y' to proceed or 'n' to cancel." | ||
} | ||
|
||
if ($confirmation -eq 'y' -or $Force) { | ||
git reset --hard upstream/develop | ||
git push origin develop --force | ||
} | ||
else { | ||
Write-Warning 'Skipping reset and force push.' | ||
} | ||
} | ||
|
||
|
||
Add-BuildTask CleanBranch Delete-ExistingBranch, Create-NewBranch, Create-VersionJson, Commit-VersionJson, {} | ||
|
||
|
||
Add-BuildTask Delete-ExistingBranch UpdateDevelop, { | ||
if (git branch --list $PreReleaseType) { | ||
git branch -D $PreReleaseType | ||
} | ||
} | ||
|
||
Add-BuildTask Create-NewBranch Delete-ExistingBranch, { | ||
git checkout -b $PreReleaseType origin/develop | ||
} | ||
|
||
Add-BuildTask Create-VersionJson Create-NewBranch, { | ||
$VersionData = @{ | ||
Version = $PodeVersion | ||
Prerelease = $PreReleaseType | ||
} | ConvertTo-Json -Depth 2 | ||
|
||
$VersionFilePath = "$PSScriptRoot\Version.json" | ||
Set-Content -Path $VersionFilePath -Value $VersionData | ||
} | ||
|
||
Add-BuildTask Commit-VersionJson Create-VersionJson, { | ||
git add $VersionFilePath | ||
git commit -m "Set Pode version to $PodeVersion-$PreReleaseType" | ||
} | ||
|
||
Add-BuildTask ProcessPRs Commit-VersionJson, { | ||
$prs = gh pr list --repo Badgerati/Pode --search 'draft:false' --json 'number,title,url,mergeStateStatus' | ConvertFrom-Json | ||
|
||
if ($ExcludePRs) { | ||
$prs = $prs | Where-Object { $_.number -notin $ExcludePRs } | ||
} | ||
|
||
foreach ($pr in $prs) { | ||
if ($pr.mergeStateStatus -ne 'CLEAN') { | ||
Write-Output "Skipping PR #$($pr.number): Merge state $($pr.mergeStateStatus)" | ||
continue | ||
} | ||
|
||
git fetch upstream pull/$($pr.number)/head:pr-$($pr.number) | ||
|
||
do { | ||
$mergeResult = git merge --squash pr-$($pr.number) 2>&1 | ||
Write-Output $mergeResult | ||
$mergeExitCode = $LASTEXITCODE | ||
if ($mergeExitCode -ne 0) { | ||
Write-Output "❌ Merge failed for PR #$($pr.number). Choose an option: (R)etry after fixing, (M)anually resolve, or (Q)uit the process." | ||
do { | ||
$choice = Read-Host | ||
if ($choice -eq 'q') { exit 1 } | ||
if ($choice -eq 'm') { Read-Host "🛠️ Resolve the issue manually, then press Enter to retry the merge."; $mergeExitCode = 0 } | ||
} until ('q', 'm', 'r' -contains $choice) | ||
} | ||
} | ||
while ($mergeExitCode -ne 0) | ||
|
||
# Run tests | ||
$testResultsPath = "$PSScriptRoot\testResults.xml" | ||
if (Test-Path $testResultsPath) { Remove-Item $testResultsPath } | ||
|
||
$testArgs = @(#'-NoExit', | ||
'-NoProfile', | ||
'-ExecutionPolicy', 'Bypass', | ||
'-Command', "`$Host.UI.RawUI.WindowTitle = '$customTitle'; Invoke-Build test" | ||
) | ||
|
||
do { | ||
$testProcess = Start-Process -FilePath 'pwsh.exe' -ArgumentList $testArgs -PassThru -WindowStyle Normal | ||
Write-Output "⏳ Running Pester tests for PR #$($pr.number)... Please wait." | ||
|
||
# Display a progress indicator while waiting for tests to complete | ||
while (!$testProcess.HasExited) { | ||
Start-Sleep -Seconds 10 | ||
Write-Host '.' -NoNewline | ||
} | ||
Write-Host '' # Move to a new line after completion | ||
|
||
# Abort if tests fail | ||
if ($testProcess.ExitCode -ne 0) { | ||
Write-Output "❌ Pester tests failed for PR #$prNumber (Exit Code: $($testProcess.ExitCode)). (R)etry running tests or (Q)uit the process?" | ||
do { | ||
$choice = Read-Host | ||
if ($choice -eq 'q') { exit 1 } | ||
if ($choice -eq 'r') { Read-Host "🔄 Tests failed. Resolve the issue and press Enter to retry." } | ||
} until ('q' , 'r' -contains $choice) | ||
} | ||
} until ($testProcess.ExitCode -eq 0) | ||
|
||
# Verify test results | ||
[xml]$testResults = Get-Content $testResultsPath | ||
if ([int]$testResults.'test-results'.failures -gt 0) { | ||
Write-Output "Tests failed for PR #$($pr.number). Aborting." | ||
exit 1 | ||
} | ||
|
||
# Commit the PR merge with a formatted message and check for errors | ||
Write-Output "Committing merge for PR #$prNumber..." | ||
do { | ||
git commit -m "PR $prNumber $prTitle $prUrl" | ||
$commitExitCode = $LASTEXITCODE | ||
if ($commitExitCode -ne 0) { | ||
Write-Output "Commit failed for PR #$($pr.number). (R)etry/(Q)uit?" | ||
$choice = Read-Host | ||
if ($choice -eq 'q') { exit 1 } | ||
else { Read-Host "🛠️ Fix the commit issue manually, then press Enter to retry the commit." } | ||
} | ||
else { | ||
Write-Output "✅ Commit successful for PR #$prNumber" | ||
} | ||
} | ||
while ($commitExitCode -ne 0) | ||
} | ||
|
||
Write-Output '✅ All PRs processed successfully!' | ||
} | ||
|
||
# Default task | ||
Add-BuildTask Default ProcessPRs |
Oops, something went wrong.