-
Notifications
You must be signed in to change notification settings - Fork 0
π[Feature]: Add support for running setup and teardown scripts during tests with integrated matrix processing #177
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0aa2dfc
Initial plan
Copilot 4d3f4ff
Add BeforeAll and AfterAll job support for Test-ModuleLocal workflows
Copilot 9eeb8c7
Add additional test BeforeAll/AfterAll scripts for comprehensive testing
Copilot 2a30035
Add documentation for BeforeAll/AfterAll setup and teardown scripts
Copilot 2027a0b
Rework BeforeAll/AfterAll to use PowerShell-based steps
Copilot 92d0958
Update documentation for PowerShell-based BeforeAll/AfterAll implemenβ¦
Copilot fdfea9e
Merge branch 'main' into copilot/fix-169
MariusStorhaug 7b69fe7
Implement separate BeforeAll/AfterAll jobs with conditional execution
Copilot 87ac2eb
Update documentation to reflect separate BeforeAll/AfterAll job archiβ¦
Copilot f6fef54
Move BeforeAll/AfterAll jobs into Test-ModuleLocal workflow and removβ¦
Copilot 3e25e4c
Move matrix strategy into Test-ModuleLocal workflow and update callinβ¦
Copilot 0ffc613
feat: Add PowerShell scripts for setup and agent context management
MariusStorhaug c9151a8
feat: Update constitution and implementation plan with expanded guidaβ¦
MariusStorhaug 849ff31
chore: Update constitution version reference in plan template to v1.1.2
MariusStorhaug bfee666
chore: Update plan template to reference Constitution v1.3.0
MariusStorhaug e5077eb
feat: Update constitution to reflect new repository structure and autβ¦
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
| 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 " - $_" } | ||
| } | ||
| } | ||
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,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 " - $_" } | ||
| } | ||
| } | ||
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.
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.