Skip to content

Commit 94bd43f

Browse files
Replace custom helper with idempotent Set-GitHubRepository calls
1 parent 99a47f3 commit 94bd43f

7 files changed

Lines changed: 52 additions & 174 deletions

File tree

tests/Actions.Tests.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ BeforeAll {
2222
if (-not $id) {
2323
throw 'GITHUB_RUN_ID is required for Actions tests because it is used to build repository-scoped names for OIDC operations.'
2424
}
25-
. "$PSScriptRoot/Data/SharedTestRepositories.ps1"
2625
}
2726

2827
Describe 'Actions' {
@@ -62,9 +61,16 @@ Describe 'Actions' {
6261
if ($OwnerType -in ('repository', 'enterprise')) {
6362
$repo = $null
6463
} else {
65-
# Declarative get-or-create so partial reruns (issue #590) can rebuild
66-
# the shared repository if AfterAll already tore it down.
67-
$repo = Initialize-SharedTestRepository -Owner $Owner -OwnerType $OwnerType -Name $repoName
64+
$repoParams = @{
65+
Name = $repoName
66+
AddReadme = $true
67+
License = 'mit'
68+
Gitignore = 'VisualStudio'
69+
}
70+
$repo = switch ($OwnerType) {
71+
'user' { Set-GitHubRepository @repoParams }
72+
'organization' { Set-GitHubRepository @repoParams -Organization $Owner }
73+
}
6874
Write-Host ($repo | Select-Object * | Out-String)
6975
}
7076
}

tests/BeforeAll.ps1

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ param()
33

44
LogGroup 'BeforeAll - Global Test Setup' {
55
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"
6-
. "$PSScriptRoot/Data/SharedTestRepositories.ps1"
76
$id = $env:GITHUB_RUN_ID
87
if (-not $id) {
98
throw 'GITHUB_RUN_ID environment variable is not set. Refusing to create or clean up test repositories with a non-deterministic name.'
@@ -68,15 +67,24 @@ LogGroup 'BeforeAll - Global Test Setup' {
6867
}
6968
}
7069

71-
# Provision the primary shared repository via the same idempotent helper that
72-
# leaf jobs use, so the happy-path BeforeAll and the partial-rerun self-heal
73-
# path (issue #590) follow the same code.
74-
Initialize-SharedTestRepository -Owner $Owner -OwnerType $OwnerType -Name $repoName | Out-Null
70+
# Provision the primary shared repository.
71+
$repoParams = @{
72+
Name = $repoName
73+
AddReadme = $true
74+
License = 'mit'
75+
Gitignore = 'VisualStudio'
76+
}
77+
switch ($OwnerType) {
78+
'user' { Set-GitHubRepository @repoParams }
79+
'organization' { Set-GitHubRepository @repoParams -Organization $Owner }
80+
}
7581

7682
# Provision extra repositories needed by Secrets/Variables SelectedRepository tests.
7783
# Only organization owners need them — those tests are skipped for user owners.
7884
if ($OwnerType -eq 'organization') {
79-
Initialize-SharedTestRepositoryExtras -Owner $Owner -BaseName $repoName | Out-Null
85+
foreach ($suffix in 2, 3) {
86+
Set-GitHubRepository -Organization $Owner -Name "$repoName-$suffix"
87+
}
8088
}
8189
}
8290
}

tests/Data/SharedTestRepositories.ps1

Lines changed: 0 additions & 140 deletions
This file was deleted.

tests/Environments.Tests.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ BeforeAll {
2626
if (-not $id) {
2727
throw 'GITHUB_RUN_ID is required for Environments tests.'
2828
}
29-
. "$PSScriptRoot/Data/SharedTestRepositories.ps1"
3029
}
3130

3231
Describe 'Environments' {
@@ -52,9 +51,16 @@ Describe 'Environments' {
5251
if ($OwnerType -in ('repository', 'enterprise')) {
5352
$repo = $null
5453
} else {
55-
# Declarative get-or-create so partial reruns (issue #590) can rebuild
56-
# the shared repository if AfterAll already tore it down.
57-
$repo = Initialize-SharedTestRepository -Owner $Owner -OwnerType $OwnerType -Name $repoName
54+
$repoParams = @{
55+
Name = $repoName
56+
AddReadme = $true
57+
License = 'mit'
58+
Gitignore = 'VisualStudio'
59+
}
60+
$repo = switch ($OwnerType) {
61+
'user' { Set-GitHubRepository @repoParams }
62+
'organization' { Set-GitHubRepository @repoParams -Organization $Owner }
63+
}
5864
}
5965
Write-Host ($repo | Select-Object * | Out-String)
6066
}

tests/Releases.Tests.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ BeforeAll {
2626
if (-not $id) {
2727
throw 'GITHUB_RUN_ID must be set for run-scoped release tests.'
2828
}
29-
. "$PSScriptRoot/Data/SharedTestRepositories.ps1"
3029
}
3130

3231
Describe 'Releases' {
@@ -51,9 +50,16 @@ Describe 'Releases' {
5150
if ($OwnerType -in ('repository', 'enterprise')) {
5251
$repo = $null
5352
} else {
54-
# Declarative get-or-create so partial reruns (issue #590) can rebuild
55-
# the shared repository if AfterAll already tore it down.
56-
$repo = Initialize-SharedTestRepository -Owner $Owner -OwnerType $OwnerType -Name $repoName
53+
$repoParams = @{
54+
Name = $repoName
55+
AddReadme = $true
56+
License = 'mit'
57+
Gitignore = 'VisualStudio'
58+
}
59+
$repo = switch ($OwnerType) {
60+
'user' { Set-GitHubRepository @repoParams }
61+
'organization' { Set-GitHubRepository @repoParams -Organization $Owner }
62+
}
5763
}
5864
Write-Host ($repo | Select-Object * | Out-String)
5965
}

tests/Secrets.Tests.ps1

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ BeforeAll {
2626
if (-not $id) {
2727
throw 'GITHUB_RUN_ID is required for Secrets tests because secret cleanup uses run-scoped wildcard names.'
2828
}
29-
. "$PSScriptRoot/Data/SharedTestRepositories.ps1"
3029
}
3130

3231
Describe 'Secrets' {
@@ -53,16 +52,13 @@ Describe 'Secrets' {
5352

5453
switch ($OwnerType) {
5554
'user' {
56-
# Declarative get-or-create so partial reruns (issue #590) can rebuild
57-
# the shared repository if AfterAll already tore it down.
58-
$repo = Initialize-SharedTestRepository -Owner $Owner -OwnerType 'user' -Name $repoName
55+
$repo = Set-GitHubRepository -Name $repoName -AddReadme -License 'mit' -Gitignore 'VisualStudio'
5956
}
6057
'organization' {
6158
Get-GitHubSecret -Owner $Owner | Where-Object { $_.Name -like "$secretName*" } | Remove-GitHubSecret -Confirm:$false
62-
$repo = Initialize-SharedTestRepository -Owner $Owner -OwnerType 'organization' -Name $repoName
63-
$extras = Initialize-SharedTestRepositoryExtras -Owner $Owner -BaseName $repoName
64-
$repo2 = $extras[0]
65-
$repo3 = $extras[1]
59+
$repo = Set-GitHubRepository -Organization $Owner -Name $repoName -AddReadme -License 'mit' -Gitignore 'VisualStudio'
60+
$repo2 = Set-GitHubRepository -Organization $Owner -Name "$repoName-2"
61+
$repo3 = Set-GitHubRepository -Organization $Owner -Name "$repoName-3"
6662
LogGroup "Org secret - [$orgSecretName]" {
6763
$params = @{
6864
Owner = $owner

tests/Variables.Tests.ps1

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ BeforeAll {
2626
if (-not $id) {
2727
throw 'GITHUB_RUN_ID is not set. Variables tests refuse to run without a scoped run ID to avoid deleting variables from other runs.'
2828
}
29-
. "$PSScriptRoot/Data/SharedTestRepositories.ps1"
3029
}
3130

3231
Describe 'Variables' {
@@ -53,16 +52,13 @@ Describe 'Variables' {
5352

5453
switch ($OwnerType) {
5554
'user' {
56-
# Declarative get-or-create so partial reruns (issue #590) can rebuild
57-
# the shared repository if AfterAll already tore it down.
58-
$repo = Initialize-SharedTestRepository -Owner $Owner -OwnerType 'user' -Name $repoName
55+
$repo = Set-GitHubRepository -Name $repoName -AddReadme -License 'mit' -Gitignore 'VisualStudio'
5956
}
6057
'organization' {
6158
Get-GitHubVariable -Owner $Owner | Where-Object { $_.Name -like "$variableName*" } | Remove-GitHubVariable -Confirm:$false
62-
$repo = Initialize-SharedTestRepository -Owner $Owner -OwnerType 'organization' -Name $repoName
63-
$extras = Initialize-SharedTestRepositoryExtras -Owner $Owner -BaseName $repoName
64-
$repo2 = $extras[0]
65-
$repo3 = $extras[1]
59+
$repo = Set-GitHubRepository -Organization $Owner -Name $repoName -AddReadme -License 'mit' -Gitignore 'VisualStudio'
60+
$repo2 = Set-GitHubRepository -Organization $Owner -Name "$repoName-2"
61+
$repo3 = Set-GitHubRepository -Organization $Owner -Name "$repoName-3"
6662
LogGroup "Org variable - [$orgVariableName]" {
6763
$params = @{
6864
Owner = $owner

0 commit comments

Comments
 (0)