-
Notifications
You must be signed in to change notification settings - Fork 8
⚙️ [Maintenance]: Test infrastructure consolidated with shared repos and run-scoped cleanup #541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Marius Storhaug (MariusStorhaug)
merged 46 commits into
main
from
copilot/consolidate-test-setup-tasks
May 1, 2026
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
84d99ad
Initial plan
Copilot 581213b
Add BeforeAll.ps1 and AfterAll.ps1 for global test setup/teardown
Copilot e68238d
Add documentation for test setup/teardown scripts
Copilot 5a69d8e
Fix hashtable splatting syntax in BeforeAll.ps1 and AfterAll.ps1
Copilot 8ec4641
Add context logging for better debugging visibility
Copilot 268c05c
Refactor: Move app authentication to BeforeAll blocks
MariusStorhaug 333143d
Reset the tests and clear the AfterAll and BeforeAll files.
MariusStorhaug 8867fe7
Add initial Pester tests for GitHub API interactions
MariusStorhaug 6869f4a
Add Pester tests for GitHub API interactions
MariusStorhaug 9e41346
Refactor: Add structure to Variables and Secrets setup log groups
MariusStorhaug f899e1e
Refactor: Enhance logging for repository setup in BeforeAll script
MariusStorhaug 82d0a10
Refactor: Standardize context output formatting in repository setup
MariusStorhaug eda2347
Refactor: Remove redundant parameter from Connect-GitHubAccount call …
MariusStorhaug 801b90a
Refactor: Skip setup for existing repositories using GITHUB_TOKEN
MariusStorhaug 286ca3b
Refactor: Consolidate repository setup and environment initialization…
MariusStorhaug e70369c
Refactor: Remove unused variables and streamline repository setup in …
MariusStorhaug d3c5531
Merge branch 'main' of https://github.com/PSModule/GitHub into copilo…
MariusStorhaug 32c55fe
Merge branch 'main' of https://github.com/PSModule/GitHub into copilo…
MariusStorhaug 959366e
Move lightweight/medium test files back to tests/ and fix issues
MariusStorhaug 29865ad
Move test files back to tmp/ for incremental migration
MariusStorhaug 9c977a1
Add Enterprise tests to validate GitHubEnterprise properties and beha…
MariusStorhaug 1e15271
Add 'API' tag to PSData in manifest.psd1
MariusStorhaug 7d34687
Consolidate test setup configuration and update README formatting
MariusStorhaug 5264066
Fix formatting in README-SETUP-TEARDOWN.md by removing extra whitespace
MariusStorhaug aba5a4e
Remove Enterprise.Tests.ps1 file to streamline test suite
MariusStorhaug 1cab02e
Fix parameter name in Get-GitHubRepository call for clarity
MariusStorhaug ea974f7
Refactor test setup and teardown scripts to derive OS names from sett…
MariusStorhaug bc0a72f
Refactor test setup scripts to improve clarity and streamline reposit…
MariusStorhaug 27ac6d3
Enhance test documentation and cleanup scripts for improved clarity a…
MariusStorhaug bdac052
Migrate all test files to shared repo pattern with run-scoped cleanup
MariusStorhaug a093666
Merge remote-tracking branch 'origin/main' into copilot/consolidate-t…
MariusStorhaug 24da735
Merge branch 'main' into copilot/consolidate-test-setup-tasks
MariusStorhaug 59a03ee
Merge branch 'main' of https://github.com/PSModule/GitHub into copilo…
MariusStorhaug ca70b97
✨ [Refactor]: Consolidate test setup across multiple test files
MariusStorhaug 4e9bf57
✨ [Refactor]: Add environment variable checks for GITHUB_RUN_ID and S…
MariusStorhaug 1300fb4
✨ [Refactor]: Simplify repository creation and logging for user and o…
MariusStorhaug 36c0e05
Fix MD060 table alignment in tests/README.md (two data rows 1 char sh…
MariusStorhaug 322329f
Fix review feedback: run-scoped team names, lowercase license keyword…
MariusStorhaug 5d9c711
Fix formatting in README.md: add missing line breaks for better reada…
MariusStorhaug 1eea360
Add GITHUB_RUN_ID guards to test files; fix /app endpoint context; co…
MariusStorhaug 1ddb2ad
Fix misleading throw message in Variables.Tests.ps1 guard (Skipping -…
MariusStorhaug d271e09
Add GITHUB_RUN_ID guards to Actions/Environments/Releases tests; add …
MariusStorhaug bd17f82
Replace list+filter repo cleanup with deterministic lookups; add null…
MariusStorhaug 2865f38
Fix README.md: use 'mit' keyword, clarify org-only extras, document d…
MariusStorhaug e3e9c0d
Guard shared repo null-check for repository/enterprise owner types in…
MariusStorhaug af4a749
Validate $osNames from Settings JSON in BeforeAll/AfterAll (review th…
MariusStorhaug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| [CmdletBinding()] | ||
| param() | ||
|
|
||
| LogGroup 'AfterAll - Global Test Teardown' { | ||
| $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" | ||
|
|
||
| $id = $env:GITHUB_RUN_ID | ||
| if (-not $id) { | ||
| throw 'GITHUB_RUN_ID environment variable is not set. Refusing to clean up test repositories with an unscoped wildcard (would impact concurrent runs).' | ||
| } | ||
| if (-not $env:Settings) { | ||
| throw 'Settings environment variable is not set. Process-PSModule must populate it with the test suite configuration.' | ||
| } | ||
| $prefix = 'Test' | ||
|
|
||
| # Derive the list of OS names from the Settings JSON provided by Process-PSModule. | ||
| try { | ||
| $settings = $env:Settings | ConvertFrom-Json | ||
| } catch { | ||
| throw "Settings environment variable contains invalid JSON. Expected TestSuites.Module.OSName to be present. $_" | ||
| } | ||
|
|
||
| $osNames = @($settings.TestSuites.Module.OSName | Sort-Object -Unique) | ||
| if (-not $osNames) { | ||
| throw 'Settings JSON must include at least one non-empty TestSuites.Module.OSName value.' | ||
| } | ||
| $invalidOsNames = @($osNames | Where-Object { -not $_ -or -not $_.ToString().Trim() }) | ||
| if ($invalidOsNames.Count -gt 0) { | ||
| throw 'Settings JSON contains one or more null or empty TestSuites.Module.OSName values.' | ||
| } | ||
| Write-Host "Cleaning up test repositories for OSes: $($osNames -join ', ')" | ||
|
|
||
| foreach ($authCase in $authCases) { | ||
| $authCase.GetEnumerator() | ForEach-Object { Set-Variable -Name $_.Key -Value $_.Value } | ||
|
|
||
| if ($TokenType -eq 'GITHUB_TOKEN') { | ||
| Write-Host "Skipping teardown for $AuthType-$TokenType (uses existing repository)" | ||
| continue | ||
| } | ||
|
|
||
| LogGroup "Teardown - $AuthType-$TokenType" { | ||
| $context = Connect-GitHubAccount @connectParams -PassThru -Silent | ||
| if ($AuthType -eq 'APP') { | ||
| $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent | ||
| } | ||
| Write-Host ($context | Format-List | Out-String) | ||
|
|
||
| foreach ($os in $osNames) { | ||
| $repoPrefix = "$prefix-$os-$TokenType" | ||
| $repoName = "$repoPrefix-$id" | ||
|
|
||
| LogGroup "Repository cleanup - $AuthType-$TokenType - $os" { | ||
| # Use deterministic name lookups instead of listing all repos to reduce API calls. | ||
| $cleanupRepoNames = @($repoName) | ||
| if ($OwnerType -eq 'organization') { | ||
| $cleanupRepoNames += "$repoName-2", "$repoName-3" | ||
| } | ||
|
|
||
| foreach ($cleanupRepoName in $cleanupRepoNames) { | ||
| switch ($OwnerType) { | ||
| 'user' { | ||
| Get-GitHubRepository -Name $cleanupRepoName -ErrorAction SilentlyContinue | | ||
| Remove-GitHubRepository -Confirm:$false | ||
| } | ||
| 'organization' { | ||
| Get-GitHubRepository -Owner $Owner -Name $cleanupRepoName -ErrorAction SilentlyContinue | | ||
| Remove-GitHubRepository -Confirm:$false | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| [CmdletBinding()] | ||
| param() | ||
|
|
||
| LogGroup 'BeforeAll - Global Test Setup' { | ||
| $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" | ||
| $id = $env:GITHUB_RUN_ID | ||
| if (-not $id) { | ||
| throw 'GITHUB_RUN_ID environment variable is not set. Refusing to create or clean up test repositories with a non-deterministic name.' | ||
| } | ||
| if (-not $env:Settings) { | ||
| throw 'Settings environment variable is not set. Process-PSModule must populate it with the test suite configuration.' | ||
| } | ||
|
|
||
| # Derive the list of OS names from the Settings JSON provided by Process-PSModule. | ||
| try { | ||
| $settings = $env:Settings | ConvertFrom-Json | ||
| } catch { | ||
| throw "Settings environment variable does not contain valid JSON. Process-PSModule must populate it with a valid test suite configuration. $_" | ||
| } | ||
|
|
||
| $osNames = @($settings.TestSuites.Module.OSName | Sort-Object -Unique) | ||
| if (-not $osNames) { | ||
| throw 'Settings JSON must contain TestSuites.Module.OSName with at least one OS name.' | ||
| } | ||
| $invalidOsNames = @($osNames | Where-Object { -not $_ -or -not $_.ToString().Trim() }) | ||
| if ($invalidOsNames.Count -gt 0) { | ||
| throw 'Settings JSON contains one or more null or empty values in TestSuites.Module.OSName.' | ||
| } | ||
| Write-Host "Creating test repositories for OSes: $($osNames -join ', ')" | ||
|
|
||
| foreach ($authCase in $authCases) { | ||
| $authCase.GetEnumerator() | ForEach-Object { Set-Variable -Name $_.Key -Value $_.Value } | ||
|
|
||
| if ($TokenType -eq 'GITHUB_TOKEN') { | ||
| Write-Host "Skipping setup for $AuthType-$TokenType (uses existing repository)" | ||
| continue | ||
| } | ||
|
|
||
| $context = Connect-GitHubAccount @connectParams -PassThru -Silent | ||
| if ($AuthType -eq 'APP') { | ||
| $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent | ||
| } | ||
| Write-Host ($context | Format-List | Out-String) | ||
|
|
||
| foreach ($os in $osNames) { | ||
| $repoPrefix = "Test-$os-$TokenType" | ||
| $repoName = "$repoPrefix-$id" | ||
|
|
||
| LogGroup "Repository setup - $AuthType-$TokenType - $os" { | ||
| # Clean up repos from a previous attempt of the same run (re-runs). | ||
| # Use deterministic name lookups instead of listing all repos to reduce API calls. | ||
| $cleanupRepoNames = @($repoName) | ||
| if ($OwnerType -eq 'organization') { | ||
| $cleanupRepoNames += "$repoName-2", "$repoName-3" | ||
| } | ||
|
|
||
| foreach ($cleanupRepoName in $cleanupRepoNames) { | ||
| switch ($OwnerType) { | ||
| 'user' { | ||
| Get-GitHubRepository -Name $cleanupRepoName -ErrorAction SilentlyContinue | | ||
| Remove-GitHubRepository -Confirm:$false | ||
| } | ||
| 'organization' { | ||
| Get-GitHubRepository -Owner $Owner -Name $cleanupRepoName -ErrorAction SilentlyContinue | | ||
| Remove-GitHubRepository -Confirm:$false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # Create the primary shared repository (with readme, license, gitignore for release tests). | ||
| $repoParams = @{ | ||
| Name = $repoName | ||
| AddReadme = $true | ||
| License = 'mit' | ||
| Gitignore = 'VisualStudio' | ||
| } | ||
| switch ($OwnerType) { | ||
| 'user' { | ||
| New-GitHubRepository @repoParams | ||
| } | ||
| 'organization' { | ||
| New-GitHubRepository @repoParams -Organization $Owner | ||
| } | ||
| } | ||
|
|
||
| # Create extra repositories needed by Secrets/Variables SelectedRepository tests. | ||
| # Only organization owners need them — those tests are skipped for user owners. | ||
| if ($OwnerType -eq 'organization') { | ||
| foreach ($suffix in 2, 3) { | ||
| $extraName = "$repoName-$suffix" | ||
| New-GitHubRepository -Organization $Owner -Name $extraName | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.