From e6a599d2da69802536f60f17a32014f8ee58befa Mon Sep 17 00:00:00 2001 From: Lyon Till Date: Tue, 28 Jul 2020 17:48:55 +0100 Subject: [PATCH 1/6] Add auto merge retry logic --- src/public/Invoke-AzOpsGitPull.ps1 | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/public/Invoke-AzOpsGitPull.ps1 b/src/public/Invoke-AzOpsGitPull.ps1 index 2a2fd810..dd5be152 100644 --- a/src/public/Invoke-AzOpsGitPull.ps1 +++ b/src/public/Invoke-AzOpsGitPull.ps1 @@ -135,12 +135,29 @@ function Invoke-AzOpsGitPull { $response = Invoke-RestMethod -Method "Get" @params Write-AzOpsLog -Level Information -Topic "gh" -Message "Merging new pull request" - try { - Start-AzOpsNativeExecution { - gh pr merge $response[0].number --squash --delete-branch -R $global:GitHubRepository - } | Out-Host + $attempt = 1 + $retryCount = 3 + $unmerged = $false + do { + try { + Start-AzOpsNativeExecution { + gh pr merge $response[0].number --squash --delete-branch -R $global:GitHubRepository + } | Out-Host + $unmerged = $false + } + catch { + if ($attempt -gt $retryCount) { + $unmerged = $true + } + else { + Start-Sleep -Seconds 5 + $attempt = $attempt + 1 + } + } } - catch { + while ($merged) + + if ($unmerged -eq $true) { $params = @{ Headers = @{ "Authorization" = ("Bearer " + $global:GitHubToken) From ee802ff18ee8b8f7acd91d18db70971a87c2bd5a Mon Sep 17 00:00:00 2001 From: Lyon Till Date: Tue, 28 Jul 2020 18:20:06 +0100 Subject: [PATCH 2/6] Local development --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index d886332b..44c3281e 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: required: true runs: using: "docker" - image: "docker://mscet/azops:main" + image: "docker://ljtill/azops:latest" branding: icon: "sunrise" color: "green" From c2535224ff1004fd273c32331176af46e68b18d3 Mon Sep 17 00:00:00 2001 From: Lyon Till Date: Tue, 28 Jul 2020 19:32:34 +0100 Subject: [PATCH 3/6] Fix variable name --- src/public/Invoke-AzOpsGitPull.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/public/Invoke-AzOpsGitPull.ps1 b/src/public/Invoke-AzOpsGitPull.ps1 index dd5be152..0a4b8e25 100644 --- a/src/public/Invoke-AzOpsGitPull.ps1 +++ b/src/public/Invoke-AzOpsGitPull.ps1 @@ -155,7 +155,7 @@ function Invoke-AzOpsGitPull { } } } - while ($merged) + while ($unmerged) if ($unmerged -eq $true) { $params = @{ From 97f7d34e79002c45dd891495760317f4ede3837e Mon Sep 17 00:00:00 2001 From: Lyon Till Date: Tue, 28 Jul 2020 20:01:34 +0100 Subject: [PATCH 4/6] Add warning message --- src/public/Invoke-AzOpsGitPull.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/public/Invoke-AzOpsGitPull.ps1 b/src/public/Invoke-AzOpsGitPull.ps1 index 0a4b8e25..50e8c96a 100644 --- a/src/public/Invoke-AzOpsGitPull.ps1 +++ b/src/public/Invoke-AzOpsGitPull.ps1 @@ -150,6 +150,7 @@ function Invoke-AzOpsGitPull { $unmerged = $true } else { + Write-AzOpsLog -Level Warning -Topic "gh" -Message "Retrying pull request merge" Start-Sleep -Seconds 5 $attempt = $attempt + 1 } From e3234fc820257ea9bf9d4a22eb2a96e972654fd1 Mon Sep 17 00:00:00 2001 From: Lyon Till Date: Tue, 28 Jul 2020 21:26:49 +0100 Subject: [PATCH 5/6] Fix variable value --- src/public/Invoke-AzOpsGitPull.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/public/Invoke-AzOpsGitPull.ps1 b/src/public/Invoke-AzOpsGitPull.ps1 index 50e8c96a..a570d603 100644 --- a/src/public/Invoke-AzOpsGitPull.ps1 +++ b/src/public/Invoke-AzOpsGitPull.ps1 @@ -137,7 +137,7 @@ function Invoke-AzOpsGitPull { Write-AzOpsLog -Level Information -Topic "gh" -Message "Merging new pull request" $attempt = 1 $retryCount = 3 - $unmerged = $false + $unmerged = $true do { try { Start-AzOpsNativeExecution { From bc9f35cf6ae1f749d4684e17456284498cd8bece Mon Sep 17 00:00:00 2001 From: Lyon Till Date: Wed, 29 Jul 2020 11:55:05 +0100 Subject: [PATCH 6/6] Revert local development --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 44c3281e..d886332b 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: required: true runs: using: "docker" - image: "docker://ljtill/azops:latest" + image: "docker://mscet/azops:main" branding: icon: "sunrise" color: "green"