Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
0aa2dfc
Initial plan
Copilot Jul 4, 2025
4d3f4ff
Add BeforeAll and AfterAll job support for Test-ModuleLocal workflows
Copilot Jul 4, 2025
9eeb8c7
Add additional test BeforeAll/AfterAll scripts for comprehensive testing
Copilot Jul 4, 2025
2a30035
Add documentation for BeforeAll/AfterAll setup and teardown scripts
Copilot Jul 4, 2025
2027a0b
Rework BeforeAll/AfterAll to use PowerShell-based steps
Copilot Jul 6, 2025
92d0958
Update documentation for PowerShell-based BeforeAll/AfterAll implemen…
Copilot Jul 6, 2025
fdfea9e
Merge branch 'main' into copilot/fix-169
MariusStorhaug Sep 11, 2025
7b69fe7
Implement separate BeforeAll/AfterAll jobs with conditional execution
Copilot Sep 11, 2025
87ac2eb
Update documentation to reflect separate BeforeAll/AfterAll job archi…
Copilot Sep 11, 2025
f6fef54
Move BeforeAll/AfterAll jobs into Test-ModuleLocal workflow and remov…
Copilot Oct 1, 2025
3e25e4c
Move matrix strategy into Test-ModuleLocal workflow and update callin…
Copilot Oct 1, 2025
0ffc613
feat: Add PowerShell scripts for setup and agent context management
MariusStorhaug Oct 1, 2025
c9151a8
feat: Update constitution and implementation plan with expanded guida…
MariusStorhaug Oct 1, 2025
849ff31
chore: Update constitution version reference in plan template to v1.1.2
MariusStorhaug Oct 1, 2025
bfee666
chore: Update plan template to reference Constitution v1.3.0
MariusStorhaug Oct 1, 2025
e5077eb
feat: Update constitution to reflect new repository structure and aut…
MariusStorhaug Oct 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions .github/workflows/AfterAll-ModuleLocal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: AfterAll-ModuleLocal

on:
workflow_call:
secrets:
TEST_APP_ENT_CLIENT_ID:
description: The client ID of an Enterprise GitHub App for running tests.
required: false
TEST_APP_ENT_PRIVATE_KEY:
description: The private key of an Enterprise GitHub App for running tests.
required: false
TEST_APP_ORG_CLIENT_ID:
description: The client ID of an Organization GitHub App for running tests.
required: false
TEST_APP_ORG_PRIVATE_KEY:
description: The private key of an Organization GitHub App for running tests.
required: false
TEST_USER_ORG_FG_PAT:
description: The fine-grained personal access token with org access for running tests.
required: false
TEST_USER_USER_FG_PAT:
description: The fine-grained personal access token with user account access for running tests.
required: false
TEST_USER_PAT:
description: The classic personal access token for running tests.
required: false
inputs:
Name:
type: string
description: The name of the module to process. Scripts default to the repository name if nothing is specified.
required: false
Debug:
type: boolean
description: Enable debug output.
required: false
default: false
Verbose:
type: boolean
description: Enable verbose output.
required: false
default: false
Version:
type: string
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
required: false
default: ''
Prerelease:
type: boolean
description: Whether to use a prerelease version of the 'GitHub' module.
required: false
default: false
WorkingDirectory:
type: string
description: The working directory where the script will run from.
required: false
default: '.'

permissions:
contents: read # to checkout the repo

jobs:
AfterAll-ModuleLocal:
name: AfterAll-ModuleLocal
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v5

- name: Install-PSModuleHelpers
uses: PSModule/Install-PSModuleHelpers@v1

- name: Run AfterAll Teardown Scripts
if: always()
uses: PSModule/GitHub-Script@v1
env:
TEST_APP_ENT_CLIENT_ID: ${{ secrets.TEST_APP_ENT_CLIENT_ID }}
TEST_APP_ENT_PRIVATE_KEY: ${{ secrets.TEST_APP_ENT_PRIVATE_KEY }}
TEST_APP_ORG_CLIENT_ID: ${{ secrets.TEST_APP_ORG_CLIENT_ID }}
TEST_APP_ORG_PRIVATE_KEY: ${{ secrets.TEST_APP_ORG_PRIVATE_KEY }}
TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }}
TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }}
TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }}
GITHUB_TOKEN: ${{ github.token }}
with:
Name: AfterAll-ModuleLocal
ShowInfo: false
ShowOutput: true
Debug: ${{ inputs.Debug }}
Prerelease: ${{ inputs.Prerelease }}
Verbose: ${{ inputs.Verbose }}
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}
Script: |
LogGroup "Running AfterAll Teardown Scripts" {
function Find-TestDirectories {
param ([string]$Path)

$directories = @()
$childDirs = Get-ChildItem -Path $Path -Directory

foreach ($dir in $childDirs) {
$directories += $dir.FullName
$directories += Find-TestDirectories -Path $dir.FullName
}

return $directories
}

# Locate the tests directory.
$testsPath = Resolve-Path 'tests' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Path
if (-not $testsPath) {
Write-Warning 'No tests directory found'
exit 0
}
Write-Host "Tests found at [$testsPath]"

$allTestFolders = @($testsPath) + (Find-TestDirectories -Path $testsPath)
$processedDirectories = @()

foreach ($folder in $allTestFolders) {
$afterAllScript = Join-Path $folder "AfterAll.ps1"

if (Test-Path $afterAllScript -PathType Leaf) {
# Get unique directory path to avoid duplicate execution
$uniqueDirectory = Resolve-Path $folder -Relative
if ($processedDirectories -notcontains $uniqueDirectory) {
$processedDirectories += $uniqueDirectory

Write-Host "Running AfterAll teardown script: $afterAllScript"
try {
Push-Location $folder
& $afterAllScript
Write-Host "AfterAll script completed successfully: $afterAllScript"
}
catch {
Write-Warning "AfterAll script failed: $afterAllScript - $_"
# Don't throw for teardown scripts to ensure other cleanup scripts can run
}
finally {
Pop-Location
}
}
}
}

if ($processedDirectories.Count -eq 0) {
Write-Host "No AfterAll.ps1 scripts found in test directories"
} else {
Write-Host "Processed AfterAll scripts in $($processedDirectories.Count) directories:"
$processedDirectories | ForEach-Object { Write-Host " - $_" }
}
}
151 changes: 151 additions & 0 deletions .github/workflows/BeforeAll-ModuleLocal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
name: BeforeAll-ModuleLocal

on:
workflow_call:
secrets:
TEST_APP_ENT_CLIENT_ID:
description: The client ID of an Enterprise GitHub App for running tests.
required: false
TEST_APP_ENT_PRIVATE_KEY:
description: The private key of an Enterprise GitHub App for running tests.
required: false
TEST_APP_ORG_CLIENT_ID:
description: The client ID of an Organization GitHub App for running tests.
required: false
TEST_APP_ORG_PRIVATE_KEY:
description: The private key of an Organization GitHub App for running tests.
required: false
TEST_USER_ORG_FG_PAT:
description: The fine-grained personal access token with org access for running tests.
required: false
TEST_USER_USER_FG_PAT:
description: The fine-grained personal access token with user account access for running tests.
required: false
TEST_USER_PAT:
description: The classic personal access token for running tests.
required: false
inputs:
Name:
type: string
description: The name of the module to process. Scripts default to the repository name if nothing is specified.
required: false
Debug:
type: boolean
description: Enable debug output.
required: false
default: false
Verbose:
type: boolean
description: Enable verbose output.
required: false
default: false
Version:
type: string
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
required: false
default: ''
Prerelease:
type: boolean
description: Whether to use a prerelease version of the 'GitHub' module.
required: false
default: false
WorkingDirectory:
type: string
description: The working directory where the script will run from.
required: false
default: '.'

permissions:
contents: read # to checkout the repo

jobs:
BeforeAll-ModuleLocal:
name: BeforeAll-ModuleLocal
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v5

- name: Install-PSModuleHelpers
uses: PSModule/Install-PSModuleHelpers@v1

- name: Run BeforeAll Setup Scripts
uses: PSModule/GitHub-Script@v1
env:
TEST_APP_ENT_CLIENT_ID: ${{ secrets.TEST_APP_ENT_CLIENT_ID }}
TEST_APP_ENT_PRIVATE_KEY: ${{ secrets.TEST_APP_ENT_PRIVATE_KEY }}
TEST_APP_ORG_CLIENT_ID: ${{ secrets.TEST_APP_ORG_CLIENT_ID }}
TEST_APP_ORG_PRIVATE_KEY: ${{ secrets.TEST_APP_ORG_PRIVATE_KEY }}
TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }}
TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }}
TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }}
GITHUB_TOKEN: ${{ github.token }}
with:
Name: BeforeAll-ModuleLocal
ShowInfo: false
ShowOutput: true
Debug: ${{ inputs.Debug }}
Prerelease: ${{ inputs.Prerelease }}
Verbose: ${{ inputs.Verbose }}
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}
Script: |
LogGroup "Running BeforeAll Setup Scripts" {
function Find-TestDirectories {
param ([string]$Path)

$directories = @()
$childDirs = Get-ChildItem -Path $Path -Directory

foreach ($dir in $childDirs) {
$directories += $dir.FullName
$directories += Find-TestDirectories -Path $dir.FullName
}

return $directories
}

# Locate the tests directory.
$testsPath = Resolve-Path 'tests' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Path
if (-not $testsPath) {
Write-Warning 'No tests directory found'
exit 0
}
Write-Host "Tests found at [$testsPath]"

$allTestFolders = @($testsPath) + (Find-TestDirectories -Path $testsPath)
$processedDirectories = @()

foreach ($folder in $allTestFolders) {
$beforeAllScript = Join-Path $folder "BeforeAll.ps1"

if (Test-Path $beforeAllScript -PathType Leaf) {
# Get unique directory path to avoid duplicate execution
$uniqueDirectory = Resolve-Path $folder -Relative
if ($processedDirectories -notcontains $uniqueDirectory) {
$processedDirectories += $uniqueDirectory

Write-Host "Running BeforeAll setup script: $beforeAllScript"
try {
Push-Location $folder
& $beforeAllScript
Write-Host "BeforeAll script completed successfully: $beforeAllScript"
}
catch {
Write-Error "BeforeAll script failed: $beforeAllScript - $_"
throw
}
finally {
Pop-Location
}
}
}
}

if ($processedDirectories.Count -eq 0) {
Write-Host "No BeforeAll.ps1 scripts found in test directories"
} else {
Write-Host "Processed BeforeAll scripts in $($processedDirectories.Count) directories:"
$processedDirectories | ForEach-Object { Write-Host " - $_" }
}
}
33 changes: 33 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,27 @@ jobs:
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}

BeforeAll-ModuleLocal:
if: ${{ needs.Build-Module.result == 'success' && !cancelled() && needs.Get-Settings.outputs.ModuleTestSuites != '[]' }}
needs:
- Build-Module
- Get-Settings
uses: ./.github/workflows/BeforeAll-ModuleLocal.yml
secrets: inherit
with:
Name: ${{ fromJson(needs.Get-Settings.outputs.Settings).Name }}
Debug: ${{ inputs.Debug }}
Prerelease: ${{ inputs.Prerelease }}
Verbose: ${{ inputs.Verbose }}
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}

Test-ModuleLocal:
if: ${{ needs.Build-Module.result == 'success' && !cancelled() && needs.Get-Settings.outputs.ModuleTestSuites != '[]' }}
needs:
- Build-Module
- Get-Settings
- BeforeAll-ModuleLocal
strategy:
fail-fast: false
matrix:
Expand All @@ -199,6 +215,21 @@ jobs:
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}

AfterAll-ModuleLocal:
if: ${{ always() && !cancelled() && needs.Get-Settings.outputs.ModuleTestSuites != '[]' }}
needs:
- Get-Settings
- Test-ModuleLocal
uses: ./.github/workflows/AfterAll-ModuleLocal.yml
secrets: inherit
with:
Name: ${{ fromJson(needs.Get-Settings.outputs.Settings).Name }}
Debug: ${{ inputs.Debug }}
Prerelease: ${{ inputs.Prerelease }}
Verbose: ${{ inputs.Verbose }}
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}

Get-TestResults:
if: needs.Get-Settings.result == 'success' && !fromJson(needs.Get-Settings.outputs.Settings).Test.TestResults.Skip && (needs.Get-Settings.outputs.SourceCodeTestSuites != '[]' || needs.Get-Settings.outputs.PSModuleTestSuites != '[]' || needs.Get-Settings.outputs.ModuleTestSuites != '[]') && (always() && !cancelled())
needs:
Expand All @@ -207,6 +238,7 @@ jobs:
- Lint-SourceCode
- Test-Module
- Test-ModuleLocal
- AfterAll-ModuleLocal
uses: ./.github/workflows/Get-TestResults.yml
secrets: inherit
with:
Expand All @@ -224,6 +256,7 @@ jobs:
- Get-Settings
- Test-Module
- Test-ModuleLocal
- AfterAll-ModuleLocal
uses: ./.github/workflows/Get-CodeCoverage.yml
secrets: inherit
with:
Expand Down
Loading