Skip to content

⚙️ [Maintenance]: Test infrastructure consolidated with shared repos and run-scoped cleanup#541

Merged
Marius Storhaug (MariusStorhaug) merged 46 commits intomainfrom
copilot/consolidate-test-setup-tasks
May 1, 2026
Merged

⚙️ [Maintenance]: Test infrastructure consolidated with shared repos and run-scoped cleanup#541
Marius Storhaug (MariusStorhaug) merged 46 commits intomainfrom
copilot/consolidate-test-setup-tasks

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 5, 2026

No changes to the module's public API or behavior. All changes are in tests/.

New: tests/BeforeAll.ps1 and tests/AfterAll.ps1

Two new global scripts run once before and after all parallel test jobs per workflow run.

BeforeAll.ps1 — for each auth case except GITHUB_TOKEN:

  • Guards against missing GITHUB_RUN_ID and Settings env vars (prevents unscoped wildcard cleanup from affecting concurrent runs)
  • Removes any repos matching Test-{OS}-{TokenType}-{RunID}* from a previous attempt of the same run (re-run safety)
  • Creates one primary shared repo per OS: Test-{OS}-{TokenType}-{RunID} — includes AddReadme, MIT license, and VisualStudio gitignore to satisfy release asset test requirements
  • Creates two extra repos (-2, -3) per OS for organization owners only — user owners never enter the SelectedRepository test contexts so the extras are not needed

AfterAll.ps1 — for each auth case except GITHUB_TOKEN:

  • Guards against missing GITHUB_RUN_ID and Settings env vars
  • Removes all repos matching Test-{OS}-{TokenType}-{RunID}*

New: tests/README.md

Documents the shared-repo pattern, naming conventions, and the per-file test structure for contributors.

Modified: test files that previously created their own repositories

The following files previously called New-GitHubRepository in their per-context BeforeAll and removed repos in their AfterAll. They now reference the shared repo via Get-GitHubRepository and contain no repo lifecycle code.

File Changes
Actions.Tests.ps1 [guid]::NewGuid()$env:GITHUB_RUN_ID; New-GitHubRepositoryGet-GitHubRepository; repo cleanup removed from BeforeAll/AfterAll
Environments.Tests.ps1 Same pattern
Releases.Tests.ps1 Same pattern
Secrets.Tests.ps1 Same pattern; $repo2/$repo3 only fetched for organization owners; stale-secret cleanup filter tightened from $secretPrefix* to $secretName* (run-scoped)
Variables.Tests.ps1 Same as Secrets

Modified: test files that keep their own repo lifecycle (CRUD tests)

Repositories.Tests.ps1 — still creates and deletes its own repos because that is what it tests. Change: [guid]::NewGuid()$env:GITHUB_RUN_ID; cleanup filter tightened from $repoPrefix* to $repoName* (run-scoped, prevents collateral deletion across concurrent runs).

Modified: naming alignment only

File Change
Teams.Tests.ps1 [guid]::NewGuid()$env:GITHUB_RUN_ID; cleanup filter tightened from $teamPrefix* to $teamName*
Organizations.Tests.ps1 Get-Random$env:GITHUB_RUN_ID; pre-test cleanup filter tightened from $orgPrefix* to $orgName*

Modified: top-level BeforeAll added

The following files had no top-level BeforeAll block. One was added to each to establish $testName, $os, and $id variables consistently with the rest of the test suite.

Apps.Tests.ps1, Artifacts.Tests.ps1, Permissions.Tests.ps1

Modified: top-level BeforeAll added + minor fixes

File Additional fixes
Emojis.Tests.ps1 Connect-GitHubApp moved from an inline if ($AuthType -eq 'APP') block into the context BeforeAll; dead placeholder if ($Type -eq 'GitHub Actions') {} removed
Enterprise.Tests.ps1 Placeholder # DEFAULTS ACROSS ALL TESTS comment removed; Describe 'Template' corrected to Describe 'Enterprise'
GitHub.Tests.ps1 Connect-GitHubApp in the Invoke-GitHubAPI context moved into context BeforeAll; inline if ($AuthType -eq 'APP') { It ... } converted to It ... -Skip:($AuthType -ne 'APP')
Users.Tests.ps1 if ($OwnerType -eq 'user') { It ... } converted to Context 'Authenticated user' -Skip:($OwnerType -ne 'user') { It ... }

Modified: tests/TEMPLATE.ps1

Rewritten to demonstrate the shared-repo pattern: Get-GitHubRepository instead of New-GitHubRepository, $id = $env:GITHUB_RUN_ID, -Skip:($OwnerType -in ('repository', 'enterprise')).

Repository creation budget

Source Creates per OS run
BeforeAll.ps1 — 3 org cases × 3 repos 9
BeforeAll.ps1 — 2 user cases × 1 repo 2
Repositories.Tests CRUD — 5 cases × ~7 ~35
All other test files 0
Total ~46

psmodule-user owner budget: 16/hr (was ~20/hr before this PR, now 4 under the secondary rate limit threshold).

Copilot AI and others added 4 commits January 5, 2026 23:04
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Copilot AI changed the title [WIP] Consolidate test setup and teardown tasks Add BeforeAll/AfterAll scripts for centralized test resource cleanup Jan 5, 2026
- Created TEMPLATE.ps1 for structuring tests with Pester.
- Implemented Teams.Tests.ps1 to test GitHub Teams API functionalities including team creation, retrieval, updating, and deletion.
- Developed Users.Tests.ps1 to validate user-related API calls, including user retrieval and updates.
- Added Variables.Tests.ps1 to test GitHub variable management across different scopes (organization, repository, environment).
- Included necessary suppressions for Pester warnings and established logging for better output visibility during test execution.
- Created TEMPLATE.ps1 for structuring Pester tests with common setup.
- Implemented Teams.Tests.ps1 to test GitHub Teams API functionalities including team creation, retrieval, updating, and deletion.
- Developed Users.Tests.ps1 to validate user-related API calls, including user retrieval and updates.
- Added Variables.Tests.ps1 to test GitHub repository and organization variable management, including creation, updating, and removal of variables.
@MariusStorhaug Marius Storhaug (MariusStorhaug) changed the title Add BeforeAll/AfterAll scripts for centralized test resource cleanup Fix: skip repo linting on merge to main Jan 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

No Significant Changes Detected

This PR does not contain changes to files that would trigger a new release:

Path Description
src/** Module source code
README.md Documentation

Build, test, and publish stages will be skipped for this PR.

If you believe this is incorrect, please verify that your changes are in the correct locations.

@MariusStorhaug Marius Storhaug (MariusStorhaug) changed the title Fix: skip repo linting on merge to main 🩹 [Patch]: Consolidate test setup/teardown tasks Feb 15, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Comment thread tests/AfterAll.ps1 Outdated
Comment thread tests/Secrets.Tests.ps1
Comment thread tests/Variables.Tests.ps1
Comment thread tests/BeforeAll.ps1 Outdated
… checks for shared repos

- BeforeAll.ps1/AfterAll.ps1: Use direct Get-GitHubRepository -Name lookups
  instead of listing all repos and filtering by wildcard. Reduces API call
  volume and avoids unnecessary pagination/rate-limit pressure.
- Secrets.Tests.ps1/Variables.Tests.ps1: Add null checks after
  Get-GitHubRepository calls to fail fast with actionable error messages
  when shared test repos are missing.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

No Significant Changes Detected

This PR does not contain changes to files that would trigger a new release:

Path Description
src/** Module source code
README.md Documentation

Build, test, and publish stages will be skipped for this PR.

If you believe this is incorrect, please verify that your changes are in the correct locations.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

All files and directories linted successfully

For more information, see the GitHub Actions workflow run

Powered by Super-linter

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Comment thread tests/README.md Outdated
Comment thread tests/README.md Outdated
Comment thread tests/README.md Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

No Significant Changes Detected

This PR does not contain changes to files that would trigger a new release:

Path Description
src/** Module source code
README.md Documentation

Build, test, and publish stages will be skipped for this PR.

If you believe this is incorrect, please verify that your changes are in the correct locations.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

All files and directories linted successfully

For more information, see the GitHub Actions workflow run

Powered by Super-linter

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Comment thread tests/Releases.Tests.ps1
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

No Significant Changes Detected

This PR does not contain changes to files that would trigger a new release:

Path Description
src/** Module source code
README.md Documentation

Build, test, and publish stages will be skipped for this PR.

If you believe this is incorrect, please verify that your changes are in the correct locations.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

All files and directories linted successfully

For more information, see the GitHub Actions workflow run

Powered by Super-linter

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Comment thread tests/BeforeAll.ps1 Outdated
Comment thread tests/AfterAll.ps1 Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

No Significant Changes Detected

This PR does not contain changes to files that would trigger a new release:

Path Description
src/** Module source code
README.md Documentation

Build, test, and publish stages will be skipped for this PR.

If you believe this is incorrect, please verify that your changes are in the correct locations.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

All files and directories linted successfully

For more information, see the GitHub Actions workflow run

Powered by Super-linter

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

@MariusStorhaug Marius Storhaug (MariusStorhaug) merged commit bf4d7fd into main May 1, 2026
31 checks passed
@MariusStorhaug Marius Storhaug (MariusStorhaug) deleted the copilot/consolidate-test-setup-tasks branch May 1, 2026 19:54
@github-project-automation github-project-automation Bot moved this from Todo to Done in GitHub PowerShell Module May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Consolidate test setup/teardown tasks

3 participants