Commit 9ed3715
Continue executing the script if queuing repo migrations fails (#842)
Closes #840
Fixes #781
- [x] Did you write/update appropriate tests
- [x] Release notes updated (if appropriate)
- [x] Appropriate logging output
- [x] Issue linked
- [x] Docs updated (or issue created)
- [x] New package licenses are added to `ThirdPartyNotices.txt` (if
applicable)
### Description
This PR makes a generated script by `ado2gh` and `gei` for parallel
migrations more resilient by not halting the entire script execution if
a repo migration fails in the queueing phase. This change only applies
to scripts generated to perform migrations in parallel. Also I tired to
keep the changes as minimal and simple as possible since one of our main
goals is to keep the script easy to understand and modify by users.
### Before/After Script Samples
<details><summary>ADO2GH Before</summary>
<p>
```powershell
#!/usr/bin/env pwsh
# =========== Created with CLI version 1.0.0.0 ===========
function Exec {
param (
[scriptblock]$ScriptBlock
)
& @ScriptBlock
if ($lastexitcode -ne 0) {
exit $lastexitcode
}
}
function ExecAndGetMigrationID {
param (
[scriptblock]$ScriptBlock
)
$MigrationID = Exec $ScriptBlock | ForEach-Object {
Write-Host $_
$_
} | Select-String -Pattern "\(ID: (.+)\)" | ForEach-Object { $_.matches.groups[1] }
return $MigrationID
}
function ExecBatch {
param (
[scriptblock[]]$ScriptBlocks
)
$Global:LastBatchFailures = 0
foreach ($ScriptBlock in $ScriptBlocks)
{
& @ScriptBlock
if ($lastexitcode -ne 0) {
$Global:LastBatchFailures++
}
}
}
$Succeeded = 0
$Failed = 0
$RepoMigrations = [ordered]@{}
# =========== Queueing migration for Organization: adoorg ===========
# === Queueing repo migrations for Team Project: adoorg/BarProject ===
$MigrationID = ExecAndGetMigrationID { gh ado2gh migrate-repo --ado-org "adoorg" --ado-team-project "BarProject" --ado-repo "BarProject" --github-org "GitHubOrg" --github-repo "BarProject-BarProject" }
$RepoMigrations["adoorg/BarProject-BarProject"] = $MigrationID
$MigrationID = ExecAndGetMigrationID { gh ado2gh migrate-repo --ado-org "adoorg" --ado-team-project "BarProject" --ado-repo "DragonRepo" --github-org "GitHubOrg" --github-repo "BarProject-DragonRepo" }
$RepoMigrations["adoorg/BarProject-DragonRepo"] = $MigrationID
# =========== Waiting for all migrations to finish for Organization: adoorg ===========
# === Waiting for repo migration to finish for Team Project: BarProject and Repo: BarProject. Will then complete the below post migration steps. ===
$CanExecuteBatch = $true
if ($null -ne $RepoMigrations["adoorg/BarProject-BarProject"]) {
gh ado2gh wait-for-migration --migration-id $RepoMigrations["adoorg/BarProject-BarProject"]
$CanExecuteBatch = ($lastexitcode -eq 0)
}
if ($CanExecuteBatch) {
$Succeeded++
} else {
$Failed++
}
# === Waiting for repo migration to finish for Team Project: BarProject and Repo: DragonRepo. Will then complete the below post migration steps. ===
$CanExecuteBatch = $true
if ($null -ne $RepoMigrations["adoorg/BarProject-DragonRepo"]) {
gh ado2gh wait-for-migration --migration-id $RepoMigrations["adoorg/BarProject-DragonRepo"]
$CanExecuteBatch = ($lastexitcode -eq 0)
}
if ($CanExecuteBatch) {
$Succeeded++
} else {
$Failed++
}
Write-Host =============== Summary ===============
Write-Host Total number of successful migrations: $Succeeded
Write-Host Total number of failed migrations: $Failed
if ($Failed -ne 0) {
exit 1
}
```
</p>
</details>
<details><summary>ADO2GH After</summary>
<p>
```powershell
#!/usr/bin/env pwsh
# =========== Created with CLI version 1.0.0.0 ===========
function Exec {
param (
[scriptblock]$ScriptBlock
)
& @ScriptBlock
if ($lastexitcode -ne 0) {
exit $lastexitcode
}
}
function ExecAndGetMigrationID {
param (
[scriptblock]$ScriptBlock
)
$MigrationID = & @ScriptBlock | ForEach-Object {
Write-Host $_
$_
} | Select-String -Pattern "\(ID: (.+)\)" | ForEach-Object { $_.matches.groups[1] }
return $MigrationID
}
function ExecBatch {
param (
[scriptblock[]]$ScriptBlocks
)
$Global:LastBatchFailures = 0
foreach ($ScriptBlock in $ScriptBlocks)
{
& @ScriptBlock
if ($lastexitcode -ne 0) {
$Global:LastBatchFailures++
}
}
}
$Succeeded = 0
$Failed = 0
$RepoMigrations = [ordered]@{}
# =========== Queueing migration for Organization: adoorg ===========
# === Queueing repo migrations for Team Project: adoorg/BarProject ===
$MigrationID = ExecAndGetMigrationID { gh ado2gh migrate-repo --ado-org "adoorg" --ado-team-project "BarProject" --ado-repo "BarProject" --github-org "GitHubOrg" --github-repo "BarProject-BarProject" }
$RepoMigrations["adoorg/BarProject-BarProject"] = $MigrationID
$MigrationID = ExecAndGetMigrationID { gh ado2gh migrate-repo --ado-org "adoorg" --ado-team-project "BarProject" --ado-repo "DragonRepo" --github-org "GitHubOrg" --github-repo "BarProject-DragonRepo" }
$RepoMigrations["adoorg/BarProject-DragonRepo"] = $MigrationID
# =========== Waiting for all migrations to finish for Organization: adoorg ===========
# === Waiting for repo migration to finish for Team Project: BarProject and Repo: BarProject. Will then complete the below post migration steps. ===
$CanExecuteBatch = $false
if ($null -ne $RepoMigrations["adoorg/BarProject-BarProject"]) {
gh ado2gh wait-for-migration --migration-id $RepoMigrations["adoorg/BarProject-BarProject"]
$CanExecuteBatch = ($lastexitcode -eq 0)
}
if ($CanExecuteBatch) {
$Succeeded++
} else {
$Failed++
}
# === Waiting for repo migration to finish for Team Project: BarProject and Repo: DragonRepo. Will then complete the below post migration steps. ===
$CanExecuteBatch = $false
if ($null -ne $RepoMigrations["adoorg/BarProject-DragonRepo"]) {
gh ado2gh wait-for-migration --migration-id $RepoMigrations["adoorg/BarProject-DragonRepo"]
$CanExecuteBatch = ($lastexitcode -eq 0)
}
if ($CanExecuteBatch) {
$Succeeded++
} else {
$Failed++
}
Write-Host =============== Summary ===============
Write-Host Total number of successful migrations: $Succeeded
Write-Host Total number of failed migrations: $Failed
if ($Failed -ne 0) {
exit 1
}
```
</p>
</details>
----
<details><summary>GEI Before</summary>
<p>
```powershell
#!/usr/bin/env pwsh
# =========== Created with CLI version 1.0.0.0 ===========
function Exec {
param (
[scriptblock]$ScriptBlock
)
& @ScriptBlock
if ($lastexitcode -ne 0) {
exit $lastexitcode
}
}
function ExecAndGetMigrationID {
param (
[scriptblock]$ScriptBlock
)
$MigrationID = Exec $ScriptBlock | ForEach-Object {
Write-Host $_
$_
} | Select-String -Pattern "\(ID: (.+)\)" | ForEach-Object { $_.matches.groups[1] }
return $MigrationID
}
$Succeeded = 0
$Failed = 0
$RepoMigrations = [ordered]@{}
# =========== Organization: github-source-org ===========
# === Queuing repo migrations ===
$MigrationID = ExecAndGetMigrationID { gh gei migrate-repo --github-source-org "github-source-org" --source-repo "repo-1" --github-target-org "github-target-org" --target-repo "repo-1" --ghes-api-url "https://myghes.com/api/v3" }
$RepoMigrations["repo-1"] = $MigrationID
$MigrationID = ExecAndGetMigrationID { gh gei migrate-repo --github-source-org "github-source-org" --source-repo "repo-2" --github-target-org "github-target-org" --target-repo "repo-2" --ghes-api-url "https://myghes.com/api/v3" }
$RepoMigrations["repo-2"] = $MigrationID
# =========== Waiting for all migrations to finish for Organization: github-source-org ===========
gh gei wait-for-migration --migration-id $RepoMigrations["repo-1"]
if ($lastexitcode -eq 0) { $Succeeded++ } else { $Failed++ }
gh gei wait-for-migration --migration-id $RepoMigrations["repo-2"]
if ($lastexitcode -eq 0) { $Succeeded++ } else { $Failed++ }
Write-Host =============== Summary ===============
Write-Host Total number of successful migrations: $Succeeded
Write-Host Total number of failed migrations: $Failed
if ($Failed -ne 0) {
exit 1
}
```
</p>
</details>
<details><summary>GEI After</summary>
<p>
#### yes, even hidden code blocks!
```powershell
#!/usr/bin/env pwsh
# =========== Created with CLI version 1.0.0.0 ===========
function ExecAndGetMigrationID {
param (
[scriptblock]$ScriptBlock
)
$MigrationID = & @ScriptBlock | ForEach-Object {
Write-Host $_
$_
} | Select-String -Pattern "\(ID: (.+)\)" | ForEach-Object { $_.matches.groups[1] }
return $MigrationID
}
$Succeeded = 0
$Failed = 0
$RepoMigrations = [ordered]@{}
# =========== Organization: github-source-org ===========
# === Queuing repo migrations ===
$MigrationID = ExecAndGetMigrationID { gh gei migrate-repo --github-source-org "github-source-org" --source-repo "repo-1" --github-target-org "github-target-org" --target-repo "repo-1" --ghes-api-url "https://myghes.com/api/v3" }
$RepoMigrations["repo-1"] = $MigrationID
$MigrationID = ExecAndGetMigrationID { gh gei migrate-repo --github-source-org "github-source-org" --source-repo "repo-2" --github-target-org "github-target-org" --target-repo "repo-2" --ghes-api-url "https://myghes.com/api/v3" }
$RepoMigrations["repo-2"] = $MigrationID
# =========== Waiting for all migrations to finish for Organization: github-source-org ===========
if ($RepoMigrations["repo-1"]) { gh gei wait-for-migration --migration-id $RepoMigrations["repo-1"] }
if ($RepoMigrations["repo-1"] -and $lastexitcode -eq 0) { $Succeeded++ } else { $Failed++ }
if ($RepoMigrations["repo-2"]) { gh gei wait-for-migration --migration-id $RepoMigrations["repo-2"] }
if ($RepoMigrations["repo-2"] -and $lastexitcode -eq 0) { $Succeeded++ } else { $Failed++ }
Write-Host =============== Summary ===============
Write-Host Total number of successful migrations: $Succeeded
Write-Host Total number of failed migrations: $Failed
if ($Failed -ne 0) {
exit 1
}
```
</p>
</details>
---------
Co-authored-by: Tim Rogers <timrogers@github.com>1 parent 5d9ddd5 commit 9ed3715
File tree
5 files changed
+58
-129
lines changed- src
- OctoshiftCLI.Tests
- ado2gh/Handlers
- gei/Handlers
- ado2gh/Handlers
- gei/Handlers
5 files changed
+58
-129
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
Lines changed: 15 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
599 | | - | |
| 599 | + | |
600 | 600 | | |
601 | 601 | | |
602 | 602 | | |
| |||
631 | 631 | | |
632 | 632 | | |
633 | 633 | | |
634 | | - | |
| 634 | + | |
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
| |||
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
696 | | - | |
| 696 | + | |
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
| |||
728 | 728 | | |
729 | 729 | | |
730 | 730 | | |
731 | | - | |
| 731 | + | |
732 | 732 | | |
733 | 733 | | |
734 | 734 | | |
| |||
821 | 821 | | |
822 | 822 | | |
823 | 823 | | |
824 | | - | |
| 824 | + | |
825 | 825 | | |
826 | 826 | | |
827 | 827 | | |
| |||
864 | 864 | | |
865 | 865 | | |
866 | 866 | | |
867 | | - | |
| 867 | + | |
868 | 868 | | |
869 | 869 | | |
870 | 870 | | |
| |||
885 | 885 | | |
886 | 886 | | |
887 | 887 | | |
888 | | - | |
| 888 | + | |
889 | 889 | | |
890 | 890 | | |
891 | 891 | | |
| |||
962 | 962 | | |
963 | 963 | | |
964 | 964 | | |
965 | | - | |
| 965 | + | |
966 | 966 | | |
967 | 967 | | |
968 | 968 | | |
| |||
1002 | 1002 | | |
1003 | 1003 | | |
1004 | 1004 | | |
1005 | | - | |
| 1005 | + | |
1006 | 1006 | | |
1007 | 1007 | | |
1008 | 1008 | | |
| |||
1059 | 1059 | | |
1060 | 1060 | | |
1061 | 1061 | | |
1062 | | - | |
| 1062 | + | |
1063 | 1063 | | |
1064 | 1064 | | |
1065 | 1065 | | |
| |||
1104 | 1104 | | |
1105 | 1105 | | |
1106 | 1106 | | |
1107 | | - | |
| 1107 | + | |
1108 | 1108 | | |
1109 | 1109 | | |
1110 | 1110 | | |
| |||
1148 | 1148 | | |
1149 | 1149 | | |
1150 | 1150 | | |
1151 | | - | |
| 1151 | + | |
1152 | 1152 | | |
1153 | 1153 | | |
1154 | 1154 | | |
| |||
1187 | 1187 | | |
1188 | 1188 | | |
1189 | 1189 | | |
1190 | | - | |
| 1190 | + | |
1191 | 1191 | | |
1192 | 1192 | | |
1193 | 1193 | | |
| |||
1229 | 1229 | | |
1230 | 1230 | | |
1231 | 1231 | | |
1232 | | - | |
| 1232 | + | |
1233 | 1233 | | |
1234 | 1234 | | |
1235 | 1235 | | |
| |||
1277 | 1277 | | |
1278 | 1278 | | |
1279 | 1279 | | |
1280 | | - | |
| 1280 | + | |
1281 | 1281 | | |
1282 | 1282 | | |
1283 | 1283 | | |
| |||
0 commit comments