Skip to content

Commit 4bbdf43

Browse files
Expose test data through a shared module-local action
1 parent 33f7f5b commit 4bbdf43

12 files changed

Lines changed: 104 additions & 16 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Expose-TestData
2+
description: Exposes caller-provided Process-PSModule TestData as environment variables.
3+
author: PSModule
4+
branding:
5+
icon: unlock
6+
color: white
7+
8+
inputs:
9+
TestData:
10+
description: |
11+
Optional single-line JSON object with 'secrets' and 'variables' maps. Entries are validated by
12+
Import-TestData and exported to GITHUB_ENV for later steps in the same job.
13+
required: false
14+
default: ''
15+
16+
runs:
17+
using: composite
18+
steps:
19+
- name: Expose caller-provided test data
20+
shell: pwsh
21+
env:
22+
PSMODULE_TEST_DATA: ${{ inputs.TestData }}
23+
run: |
24+
Import-TestData

.github/workflows/AfterAll-ModuleLocal.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ jobs:
4343
uses: ./_wf/.github/actions/Install-PSModuleHelpers
4444

4545
- name: Expose caller-provided test data
46-
shell: pwsh
47-
env:
48-
PSMODULE_TEST_DATA: ${{ secrets.TestData }}
49-
run: |
50-
Import-TestData
46+
uses: ./_wf/.github/actions/Expose-TestData
47+
with:
48+
TestData: ${{ secrets.TestData }}
5149

5250
- name: Run AfterAll Teardown Scripts
5351
if: always()

.github/workflows/BeforeAll-ModuleLocal.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ jobs:
4343
uses: ./_wf/.github/actions/Install-PSModuleHelpers
4444

4545
- name: Expose caller-provided test data
46-
shell: pwsh
47-
env:
48-
PSMODULE_TEST_DATA: ${{ secrets.TestData }}
49-
run: |
50-
Import-TestData
46+
uses: ./_wf/.github/actions/Expose-TestData
47+
with:
48+
TestData: ${{ secrets.TestData }}
5149

5250
- name: Run BeforeAll Setup Scripts
5351
uses: PSModule/GitHub-Script@8083ec1f733f00357ee4d0db0c6056686e483bc0 # v1.9.0

.github/workflows/Test-ModuleLocal.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ jobs:
5454
uses: ./_wf/.github/actions/Install-PSModuleHelpers
5555

5656
- name: Expose caller-provided test data
57-
shell: pwsh
58-
env:
59-
PSMODULE_TEST_DATA: ${{ secrets.TestData }}
60-
run: |
61-
Import-TestData
57+
uses: ./_wf/.github/actions/Expose-TestData
58+
with:
59+
TestData: ${{ secrets.TestData }}
6260

6361
- name: Import-Module
6462
id: import-module

.github/workflows/workflow.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ on:
1515
$env:<name>. Values under "secrets" are masked in the logs; values under "variables" are not.
1616
Build it from secrets.<name> / vars.<name> in the calling workflow (see the README). Keep it
1717
on a single line so GitHub registers one mask for the whole value. Omit it when the module
18-
needs no test data.
18+
needs no test data. The same keys are exported before BeforeAll-ModuleLocal,
19+
Test-ModuleLocal, and AfterAll-ModuleLocal run. If setup or teardown scripts see a missing
20+
key, confirm the caller explicitly maps a TestData JSON value; secrets: inherit only passes
21+
an already-created TestData secret and does not build JSON from individual secrets.
1922
required: false
2023
inputs:
2124
SettingsPath:

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,30 @@ The full documentation lives on the MSX / Docs site:
99
📖 **[Process-PSModule documentation](https://msxorg.github.io/docs/Frameworks/Process-PSModule/)**
1010

1111
It covers getting started, the pipeline stages, usage, configuration, repository structure, and the principles behind the framework.
12+
13+
## TestData phase parity
14+
15+
Module-local setup, test, and teardown phases use the same `TestData` contract. Values under
16+
`secrets` are masked and values under `variables` are exported unmasked, and every key is available
17+
as `$env:<name>` in all three phases:
18+
19+
- `BeforeAll-ModuleLocal` (`tests/BeforeAll.ps1`)
20+
- `Test-ModuleLocal` (Pester module tests)
21+
- `AfterAll-ModuleLocal` (`tests/AfterAll.ps1`)
22+
23+
Pass `TestData` as a single-line JSON object from the calling workflow:
24+
25+
```yaml
26+
jobs:
27+
Process-PSModule:
28+
uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@v6
29+
secrets:
30+
APIKey: ${{ secrets.APIKey }}
31+
TestData: >-
32+
{ "secrets": { "TEST_TOKEN": "${{ secrets.TEST_TOKEN }}" },
33+
"variables": { "TEST_OWNER": ${{ toJSON(vars.TEST_OWNER) }} } }
34+
```
35+
36+
If a key is missing in setup or teardown, verify that the caller explicitly maps `TestData` as JSON.
37+
`secrets: inherit` only passes a repository or environment secret already named `TestData`; it does not
38+
automatically build the JSON object from individual secrets.

tests/srcTestRepo/tests/AfterAll.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Write-Warning "=== AFTERALL TEARDOWN SCRIPT EXECUTING ==="
22
Write-Warning "Tearing down test environment..."
33

4+
. "$PSScriptRoot/TestData.Assertions.ps1"
5+
46
# Example teardown tasks:
57
# - Clean up test infrastructure
68
# - Remove test data

tests/srcTestRepo/tests/BeforeAll.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Write-Warning "=== BEFOREALL SETUP SCRIPT EXECUTING ==="
22
Write-Warning "Setting up test environment..."
33

4+
. "$PSScriptRoot/TestData.Assertions.ps1"
5+
46
# Example setup tasks:
57
# - Deploy test infrastructure
68
# - Download test data
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$expectedTestData = @{
2+
PSMODULE_TEST_SINGLELINE_SECRET = 'psmodule-public-nonsecret-test-fixture-single-line'
3+
PSMODULE_TEST_VARIABLE = 'psmodule-public-nonsecret-test-variable'
4+
}
5+
6+
foreach ($entry in $expectedTestData.GetEnumerator()) {
7+
$actual = [System.Environment]::GetEnvironmentVariable($entry.Key)
8+
if ([string]::IsNullOrEmpty($actual)) {
9+
throw "TestData key '$($entry.Key)' is not available in the current module-local phase."
10+
}
11+
if ($actual -cne $entry.Value) {
12+
throw "TestData key '$($entry.Key)' has an unexpected value in the current module-local phase."
13+
}
14+
}
15+
16+
Write-Warning 'TestData secret and variable fixtures are available in this module-local phase.'

tests/srcWithManifestTestRepo/tests/AfterAll.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Write-Warning "=== AFTERALL TEARDOWN SCRIPT (Environments) EXECUTING ==="
22
Write-Warning "Tearing down test environment for Environments..."
33

4+
. "$PSScriptRoot/TestData.Assertions.ps1"
5+
46
# Example teardown tasks for Environments directory:
57
Write-Warning "Cleaning up Environments test environment..."
68

0 commit comments

Comments
 (0)