Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions .github/actions/Expose-TestData/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Expose-TestData
description: Exposes caller-provided Process-PSModule TestData as environment variables.
author: PSModule
branding:
icon: unlock
color: white

inputs:
TestData:
description: |
Optional single-line JSON object with 'secrets' and 'variables' maps. Entries are validated by
Import-TestData and exported to GITHUB_ENV for later steps in the same job.
required: false
default: ''

runs:
using: composite
steps:
- name: Expose caller-provided test data
shell: pwsh
env:
PSMODULE_TEST_DATA: ${{ inputs.TestData }}
run: |
Import-TestData
8 changes: 3 additions & 5 deletions .github/workflows/AfterAll-ModuleLocal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ jobs:
uses: ./_wf/.github/actions/Install-PSModuleHelpers

- name: Expose caller-provided test data
shell: pwsh
env:
PSMODULE_TEST_DATA: ${{ secrets.TestData }}
run: |
Import-TestData
uses: ./_wf/.github/actions/Expose-TestData
with:
TestData: ${{ secrets.TestData }}

- name: Run AfterAll Teardown Scripts
if: always()
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/BeforeAll-ModuleLocal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ jobs:
uses: ./_wf/.github/actions/Install-PSModuleHelpers

- name: Expose caller-provided test data
shell: pwsh
env:
PSMODULE_TEST_DATA: ${{ secrets.TestData }}
run: |
Import-TestData
uses: ./_wf/.github/actions/Expose-TestData
with:
TestData: ${{ secrets.TestData }}

- name: Run BeforeAll Setup Scripts
uses: PSModule/GitHub-Script@8083ec1f733f00357ee4d0db0c6056686e483bc0 # v1.9.0
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/Test-ModuleLocal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ jobs:
uses: ./_wf/.github/actions/Install-PSModuleHelpers

- name: Expose caller-provided test data
shell: pwsh
env:
PSMODULE_TEST_DATA: ${{ secrets.TestData }}
run: |
Import-TestData
uses: ./_wf/.github/actions/Expose-TestData
with:
TestData: ${{ secrets.TestData }}

- name: Import-Module
id: import-module
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ on:
$env:<name>. Values under "secrets" are masked in the logs; values under "variables" are not.
Build it from secrets.<name> / vars.<name> in the calling workflow (see the README). Keep it
on a single line so GitHub registers one mask for the whole value. Omit it when the module
needs no test data.
needs no test data. The same keys are exported before BeforeAll-ModuleLocal,
Test-ModuleLocal, and AfterAll-ModuleLocal run. If setup or teardown scripts see a missing
key, confirm the caller explicitly maps a TestData JSON value; secrets: inherit only passes
an already-created TestData secret and does not build JSON from individual secrets.
required: false
inputs:
SettingsPath:
Expand Down
2 changes: 2 additions & 0 deletions tests/srcTestRepo/tests/AfterAll.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Write-Warning "=== AFTERALL TEARDOWN SCRIPT EXECUTING ==="
Write-Warning "Tearing down test environment..."

. "$PSScriptRoot/TestData.Assertions.ps1"

# Example teardown tasks:
# - Clean up test infrastructure
# - Remove test data
Expand Down
2 changes: 2 additions & 0 deletions tests/srcTestRepo/tests/BeforeAll.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Write-Warning "=== BEFOREALL SETUP SCRIPT EXECUTING ==="
Write-Warning "Setting up test environment..."

. "$PSScriptRoot/TestData.Assertions.ps1"

# Example setup tasks:
# - Deploy test infrastructure
# - Download test data
Expand Down
16 changes: 16 additions & 0 deletions tests/srcTestRepo/tests/TestData.Assertions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$expectedTestData = @{
PSMODULE_TEST_SINGLELINE_SECRET = 'psmodule-public-nonsecret-test-fixture-single-line'
PSMODULE_TEST_VARIABLE = 'psmodule-public-nonsecret-test-variable'
}

foreach ($entry in $expectedTestData.GetEnumerator()) {
$actual = [System.Environment]::GetEnvironmentVariable($entry.Key)
if ([string]::IsNullOrEmpty($actual)) {
throw "TestData key '$($entry.Key)' is not available in the current module-local phase."
}
if ($actual -cne $entry.Value) {
throw "TestData key '$($entry.Key)' has an unexpected value in the current module-local phase."
}
}

Write-Warning 'TestData secret and variable fixtures are available in this module-local phase.'
2 changes: 2 additions & 0 deletions tests/srcWithManifestTestRepo/tests/AfterAll.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Write-Warning "=== AFTERALL TEARDOWN SCRIPT (Environments) EXECUTING ==="
Write-Warning "Tearing down test environment for Environments..."

. "$PSScriptRoot/TestData.Assertions.ps1"

# Example teardown tasks for Environments directory:
Write-Warning "Cleaning up Environments test environment..."

Expand Down
2 changes: 2 additions & 0 deletions tests/srcWithManifestTestRepo/tests/BeforeAll.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Write-Warning "=== BEFOREALL SETUP SCRIPT EXECUTING ==="
Write-Warning "Setting up test environment..."

. "$PSScriptRoot/TestData.Assertions.ps1"

# Example setup tasks for test environment:
Write-Warning "Initializing test environment..."

Expand Down
16 changes: 16 additions & 0 deletions tests/srcWithManifestTestRepo/tests/TestData.Assertions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$expectedTestData = @{
PSMODULE_TEST_SINGLELINE_SECRET = 'psmodule-public-nonsecret-test-fixture-single-line'
PSMODULE_TEST_VARIABLE = 'psmodule-public-nonsecret-test-variable'
}

foreach ($entry in $expectedTestData.GetEnumerator()) {
$actual = [System.Environment]::GetEnvironmentVariable($entry.Key)
if ([string]::IsNullOrEmpty($actual)) {
throw "TestData key '$($entry.Key)' is not available in the current module-local phase."
}
if ($actual -cne $entry.Value) {
throw "TestData key '$($entry.Key)' has an unexpected value in the current module-local phase."
}
}

Write-Warning 'TestData secret and variable fixtures are available in this module-local phase.'
Loading