Add ServicingPipeline.ps1, a script I use to service Terminal (#12789)

This script takes pull requests from a project board, cherry-picks them,
and updates the project board. It also yells at you if there are
conflicts to resolve, and generally tries to keep track of everything.
It is quite cool.
This commit is contained in:
Dustin L. Howett 2022-03-30 17:12:00 -05:00 committed by GitHub
parent 4e61be9cd7
commit a24d419b7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 128 additions and 0 deletions

View File

@ -76,6 +76,7 @@ SUMS$
^src/tools/texttests/fira\.txt$ ^src/tools/texttests/fira\.txt$
^src/tools/U8U16Test/(?:fr|ru|zh)\.txt$ ^src/tools/U8U16Test/(?:fr|ru|zh)\.txt$
^src/types/ut_types/UtilsTests.cpp$ ^src/types/ut_types/UtilsTests.cpp$
^tools/ReleaseEngineering/ServicingPipeline.ps1$
^\.github/actions/spelling/ ^\.github/actions/spelling/
^\.gitignore$ ^\.gitignore$
^\XamlStyler.json$ ^\XamlStyler.json$

View File

@ -0,0 +1,127 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
#Requires -Version 7
#Requires -Modules PSGitHub
[CmdletBinding()]
Param(
[string]$Version,
[string]$SourceBranch = "origin/main",
[switch]$GpgSign = $False
)
Function Prompt() {
"PSCR {0}> " -f $PWD.Path
}
Function Enter-ConflictResolutionShell($entry) {
$Global:Abort = $False
$Global:Skip = $False
$Global:Reject = $False
Push-Location -StackName:"ServicingStack" -Path:$PWD > $Null
Write-Host (@"
`e[31;1;7mCONFLICT RESOLUTION REQUIRED`e[m
`e[1mCommit `e[m: `e[1;93m{0}`e[m
`e[1mSubject`e[m: `e[1;93m{1}`e[m
"@ -f ($_.CommitID, $_.Subject))
& git status --short
Write-Host (@"
`e[1mCommands`e[m
`e[1;96mdone `e[m Complete conflict resolution and commit
`e[1;96mskip `e[m Skip this commit
`e[1;96mabort `e[m Stop everything
`e[1;96mreject`e[m Skip and `e[31mremove this commit from servicing consideration`e[m
"@)
$Host.EnterNestedPrompt()
Pop-Location -StackName:"ServicingStack" > $Null
}
Function Done() {
$Host.ExitNestedPrompt()
}
Function Abort() {
$Global:Abort = $True
$Host.ExitNestedPrompt()
}
Function Skip() {
$Global:Skip = $True
$Host.ExitNestedPrompt()
}
Function Reject() {
$Global:Skip = $True
$Global:Reject = $True
$Host.ExitNestedPrompt()
}
$Script:TodoColumnName = "To Cherry Pick"
$Script:DoneColumnName = "Cherry Picked"
$Script:RejectColumnName = "Rejected"
# Propagate default values into all PSGitHub cmdlets
$PSDefaultParameterValues['*GitHub*:Owner'] = "microsoft"
$PSDefaultParameterValues['*GitHub*:RepositoryName'] = "terminal"
$Project = Get-GithubProject -Name "$Version Servicing Pipeline"
$AllColumns = Get-GithubProjectColumn -ProjectId $Project.id
$ToPickColumn = $AllColumns | ? Name -Eq $script:TodoColumnName
$DoneColumn = $AllColumns | ? Name -Eq $script:DoneColumnName
$RejectColumn = $AllColumns | ? Name -Eq $script:RejectColumnName
$Cards = Get-GithubProjectCard -ColumnId $ToPickColumn.id
& git fetch --all 2>&1 | Out-Null
$Entries = @(& git log $SourceBranch --grep "(#\($($Cards.Number -Join "\|")\))" "--pretty=format:%H%x1C%s" |
ConvertFrom-CSV -Delimiter "`u{001C}" -Header CommitID,Subject)
[Array]::Reverse($Entries)
$PickArgs = @()
If ($GpgSign) {
$PickArgs += , "-S"
}
$CommitPRRegex = [Regex]"\(#(\d+)\)$"
$Entries | ForEach-Object {
Write-Host "`e[96m`e[1;7mPICK`e[22;27m $($_.CommitID): $($_.Subject)`e[m"
$PR = $CommitPRRegex.Match($_.Subject).Groups[1].Value
$Card = $Cards | ? Number -Eq $PR
$null = & git cherry-pick -x $_.CommitID 2>&1
$Err = ""
While ($True) {
If ($LASTEXITCODE -ne 0) {
$Err
Enter-ConflictResolutionShell $_
If ($Global:Abort) {
& git cherry-pick --abort
Write-Host -ForegroundColor "Red" "YOU'RE ON YOUR OWN"
Exit
}
If ($Global:Reject) {
Move-GithubProjectCard -CardId $Card.id -ColumnId $RejectColumn.id
# Fall through to Skip
}
If ($Global:Skip) {
& git cherry-pick --skip
Break
}
$Err = & git cherry-pick --continue --no-edit
} Else {
& git commit @PickArgs --amend --no-edit --trailer "Service-Card-Id:$($Card.Id)" --trailer "Service-Version:$Version" | Out-Null
Write-Host "`e[92;1;7m OK `e[m"
Move-GithubProjectCard -CardId $Card.id -ColumnId $DoneColumn.id
Break
}
}
}