Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
121 changes: 121 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,88 @@
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}

BeforeAll-ModuleLocal:
if: ${{ needs.Build-Module.result == 'success' && !cancelled() && needs.Get-Settings.outputs.ModuleTestSuites != '[]' }}
name: BeforeAll Setup
runs-on: ubuntu-latest
needs:
- Build-Module
- Get-Settings
outputs:
hasBeforeAll: ${{ steps.check-beforeall.outputs.hasBeforeAll }}
hasAfterAll: ${{ steps.check-afterall.outputs.hasAfterAll }}
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Check for BeforeAll/AfterAll scripts
id: check-beforeall
shell: bash
working-directory: ${{ inputs.WorkingDirectory }}
run: |
hasBeforeAll=false
hasAfterAll=false

# Check each test path for BeforeAll/AfterAll scripts
testSuites='${{ needs.Get-Settings.outputs.ModuleTestSuites }}'
echo "Test suites: $testSuites"

if echo "$testSuites" | jq -e '.[] | select(.TestPath)' > /dev/null 2>&1; then
for testPath in $(echo "$testSuites" | jq -r '.[].TestPath' | sort -u); do
echo "Checking test path: $testPath"
if [ -f "$testPath/BeforeAll.ps1" ]; then
echo "BeforeAll.ps1 found in $testPath"
hasBeforeAll=true
fi
if [ -f "$testPath/AfterAll.ps1" ]; then
echo "AfterAll.ps1 found in $testPath"
hasAfterAll=true
fi
done
fi

echo "hasBeforeAll=$hasBeforeAll" >> $GITHUB_OUTPUT
echo "hasAfterAll=$hasAfterAll" >> $GITHUB_OUTPUT

- name: Install-PSModuleHelpers
if: steps.check-beforeall.outputs.hasBeforeAll == 'true'
uses: PSModule/Install-PSModuleHelpers@v1

- name: Run BeforeAll scripts
if: steps.check-beforeall.outputs.hasBeforeAll == 'true'
shell: pwsh
working-directory: ${{ inputs.WorkingDirectory }}
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 }}
run: |
$testSuites = '${{ needs.Get-Settings.outputs.ModuleTestSuites }}' | ConvertFrom-Json
$processedPaths = @()

foreach ($suite in $testSuites) {
$testPath = $suite.TestPath
if ($testPath -and $testPath -notin $processedPaths) {
$beforeAllScript = Join-Path $testPath "BeforeAll.ps1"
if (Test-Path $beforeAllScript) {
Write-Host "Running BeforeAll setup script: $beforeAllScript"
& $beforeAllScript
$processedPaths += $testPath
}
}
}

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 @@ -201,6 +278,48 @@
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}

AfterAll-ModuleLocal:
if: ${{ always() && needs.BeforeAll-ModuleLocal.outputs.hasAfterAll == 'true' }}
name: AfterAll Teardown
runs-on: ubuntu-latest
needs:
- BeforeAll-ModuleLocal
- Test-ModuleLocal
steps:
- name: Checkout Code
uses: actions/checkout@v4

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

- name: Run AfterAll scripts
shell: pwsh
working-directory: ${{ inputs.WorkingDirectory }}
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 }}
run: |
$testSuites = '${{ needs.Get-Settings.outputs.ModuleTestSuites }}' | ConvertFrom-Json
$processedPaths = @()

foreach ($suite in $testSuites) {
$testPath = $suite.TestPath
if ($testPath -and $testPath -notin $processedPaths) {
$afterAllScript = Join-Path $testPath "AfterAll.ps1"
if (Test-Path $afterAllScript) {
Write-Host "Running AfterAll teardown script: $afterAllScript"
& $afterAllScript
$processedPaths += $testPath
}
}
}

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 @@ -209,6 +328,7 @@
- Lint-SourceCode
- Test-Module
- Test-ModuleLocal
- AfterAll-ModuleLocal
uses: ./.github/workflows/Get-TestResults.yml
secrets: inherit
with:
Expand All @@ -226,6 +346,7 @@
- Get-Settings
- Test-Module
- Test-ModuleLocal
- AfterAll-ModuleLocal
uses: ./.github/workflows/Get-CodeCoverage.yml
secrets: inherit
with:
Expand Down
12 changes: 12 additions & 0 deletions tests/srcTestRepo/tests/AfterAll.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Write-Host "=== AFTERALL TEARDOWN SCRIPT EXECUTING ==="
Write-Host "Tearing down test environment..."

# Example teardown tasks:
# - Clean up test infrastructure
# - Remove test data
# - Cleanup test environment
# - Drop test databases
# - Stop test services

Write-Host "Test environment teardown completed successfully!"
Write-Host "=== AFTERALL TEARDOWN SCRIPT COMPLETED ==="
12 changes: 12 additions & 0 deletions tests/srcTestRepo/tests/BeforeAll.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Write-Host "=== BEFOREALL SETUP SCRIPT EXECUTING ==="
Write-Host "Setting up test environment..."

# Example setup tasks:
# - Deploy test infrastructure
# - Download test data
# - Initialize test environment
# - Set up test databases
# - Configure test services

Write-Host "Test environment setup completed successfully!"
Write-Host "=== BEFOREALL SETUP SCRIPT COMPLETED ==="
8 changes: 8 additions & 0 deletions tests/srcWithManifestTestRepo/tests/MyTests/AfterAll.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Write-Host "=== AFTERALL TEARDOWN SCRIPT (MyTests) EXECUTING ==="
Write-Host "Tearing down test environment for MyTests..."

# Example teardown tasks for MyTests directory:
Write-Host "Cleaning up MyTests test environment..."

Write-Host "MyTests environment teardown completed successfully!"
Write-Host "=== AFTERALL TEARDOWN SCRIPT (MyTests) COMPLETED ==="
8 changes: 8 additions & 0 deletions tests/srcWithManifestTestRepo/tests/MyTests/BeforeAll.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Write-Host "=== BEFOREALL SETUP SCRIPT (MyTests) EXECUTING ==="
Write-Host "Setting up test environment for MyTests..."

# Example setup tasks for MyTests directory:
Write-Host "Initializing MyTests test environment..."

Write-Host "MyTests environment setup completed successfully!"
Write-Host "=== BEFOREALL SETUP SCRIPT (MyTests) COMPLETED ==="