@@ -74,15 +74,14 @@ Describe 'Organizations' {
7474 }
7575 }
7676
77- # Check each expected org name; collect any that exist and differ from current org
77+ # Check each expected org name; collect any that currently exist.
78+ # Include the current attempt name as well so reruns of the same
79+ # GITHUB_RUN_ATTEMPT remain idempotent.
7880 $staleOrgs = @ ()
7981 foreach ($candidateName in $orgNamesToCheck ) {
80- if ($candidateName -ne $orgName ) {
81- # Skip the current org we're about to create
82- $candidateOrg = Get-GitHubOrganization - Name $candidateName - ErrorAction SilentlyContinue
83- if ($candidateOrg -and $candidateOrg.Name ) {
84- $staleOrgs += $candidateOrg
85- }
82+ $candidateOrg = Get-GitHubOrganization - Name $candidateName - ErrorAction SilentlyContinue
83+ if ($candidateOrg -and $candidateOrg.Name ) {
84+ $staleOrgs += $candidateOrg
8685 }
8786 }
8887
@@ -100,8 +99,13 @@ Describe 'Organizations' {
10099 - ClientID $installationContext.ClientID - RepositorySelection ' all' - ErrorAction Stop
101100 break
102101 } catch {
102+ $message = $_.Exception.Message
103+ if ($message -match ' already\s+installed' ) {
104+ Write-Host " App is already installed on stale org [$ ( $staleOrg.Name ) ]; continuing with org-level cleanup context."
105+ break
106+ }
103107 if ($retryAttempt -lt $maxAttempts ) {
104- Write-Host " Install-GitHubApp attempt $retryAttempt /$maxAttempts failed: $ ( $_ .Exception.Message ) . Retrying in ${retryDelay} s..."
108+ Write-Host " Install-GitHubApp attempt $retryAttempt /$maxAttempts failed: $message . Retrying in ${retryDelay} s..."
105109 Start-Sleep - Seconds $retryDelay
106110 } else {
107111 throw
0 commit comments