Skip to content

Commit bec6182

Browse files
Address Copilot review: retry Install-GitHubApp (threads #3179013796), add -Confirm:false to org secret/variable cleanup (threads #3179013812, #3179013820), fix MSX/msx inconsistency in test instructions (thread #3179013826)
1 parent a84ae98 commit bec6182

4 files changed

Lines changed: 41 additions & 7 deletions

File tree

.github/instructions/tests.instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Secrets:
2222

2323
### APP_ENT — PSModule Enterprise App
2424

25-
Homed in `MSX`. ClientID: `Iv23lieHcDQDwVV3alK1`.
25+
Homed in `MSX` (enterprise slug: `msx`). ClientID: `Iv23lieHcDQDwVV3alK1`.
2626
Installed on [psmodule-test-org3](https://github.com/orgs/psmodule-test-org3) (enterprise org) with all permissions and push events.
2727

28-
Required enterprise-scoped permissions (configured on the app, homed in `msx`):
28+
Required enterprise-scoped permissions (configured on the app):
2929

3030
- `enterprise_organization_installations: write` — required by `Install-GitHubApp` on enterprise-owned organizations
3131
([docs](https://docs.github.com/rest/enterprise-admin/organization-installations#install-a-github-app-on-an-enterprise-owned-organization)).

tests/Organizations.Tests.ps1

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,24 @@ Describe 'Organizations' {
6262
if ($staleOrg -and $staleOrg.Name) {
6363
Write-Host "Stale org [$orgName] found from previous run attempt. Removing..."
6464
try {
65-
$null = Install-GitHubApp -Enterprise $owner -Organization $orgName `
66-
-ClientID $installationContext.ClientID -RepositorySelection 'all' -ErrorAction Stop
65+
# Retry Install-GitHubApp: the enterprise apps endpoint can return 404
66+
# for a short time after the org was originally created.
67+
$maxAttempts = 5
68+
$retryDelay = 3
69+
for ($retryAttempt = 1; $retryAttempt -le $maxAttempts; $retryAttempt++) {
70+
try {
71+
$null = Install-GitHubApp -Enterprise $owner -Organization $orgName `
72+
-ClientID $installationContext.ClientID -RepositorySelection 'all' -ErrorAction Stop
73+
break
74+
} catch {
75+
if ($retryAttempt -lt $maxAttempts) {
76+
Write-Host "Install-GitHubApp attempt $retryAttempt/$maxAttempts failed: $($_.Exception.Message). Retrying in ${retryDelay}s..."
77+
Start-Sleep -Seconds $retryDelay
78+
} else {
79+
throw
80+
}
81+
}
82+
}
6783
$cleanupOrgContext = Connect-GitHubApp -Organization $orgName -Context $context -PassThru -Silent
6884
Remove-GitHubOrganization -Name $orgName -Confirm:$false -Context $cleanupOrgContext
6985
Write-Host "Stale org [$orgName] removed."
@@ -178,7 +194,25 @@ Describe 'Organizations' {
178194
}
179195

180196
It 'Install-GitHubApp - Installs a GitHub App to an organization' -Skip:($OwnerType -ne 'enterprise') {
181-
$installation = Install-GitHubApp -Enterprise $owner -Organization $orgName -ClientID $installationContext.ClientID -RepositorySelection 'all'
197+
# Retry: the enterprise apps endpoint can return 404 transiently right after
198+
# New-GitHubOrganization, before the new org has propagated.
199+
$maxAttempts = 5
200+
$retryDelay = 3
201+
$installation = $null
202+
for ($retryAttempt = 1; $retryAttempt -le $maxAttempts; $retryAttempt++) {
203+
try {
204+
$installation = Install-GitHubApp -Enterprise $owner -Organization $orgName `
205+
-ClientID $installationContext.ClientID -RepositorySelection 'all' -ErrorAction Stop
206+
break
207+
} catch {
208+
if ($retryAttempt -lt $maxAttempts) {
209+
Write-Host "Install-GitHubApp attempt $retryAttempt/$maxAttempts failed: $($_.Exception.Message). Retrying in ${retryDelay}s..."
210+
Start-Sleep -Seconds $retryDelay
211+
} else {
212+
throw
213+
}
214+
}
215+
}
182216
LogGroup 'Installed App' {
183217
Write-Host ($installation | Select-Object * | Out-String)
184218
}

tests/Secrets.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Describe 'Secrets' {
9494
LogGroup 'Secrets to remove' {
9595
$orgSecrets = Get-GitHubSecret -Owner $owner | Where-Object { $_.Name -like "$secretName*" }
9696
Write-Host "$($orgSecrets | Format-List | Out-String)"
97-
$orgSecrets | Remove-GitHubSecret
97+
$orgSecrets | Remove-GitHubSecret -Confirm:$false
9898
}
9999
}
100100
}

tests/Variables.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Describe 'Variables' {
9494
LogGroup 'Variables to remove' {
9595
Write-Host "$($variablesToRemove | Format-List | Out-String)"
9696
}
97-
$variablesToRemove | Remove-GitHubVariable
97+
$variablesToRemove | Remove-GitHubVariable -Confirm:$false
9898
}
9999
}
100100
# Remove the test environment created on the per-test-file repository so it does

0 commit comments

Comments
 (0)