Skip to content

Commit 8b1a261

Browse files
🪲 [Fix]: TestData keys reach setup and teardown phases (#394)
TestData values now reach every module-local phase through the same export path. Setup scripts, module tests, and teardown scripts can rely on identical environment variable names for caller-provided secrets and variables, with secret masking preserved. - Fixes #386 ## Fixed: Setup and teardown scripts receive TestData keys `BeforeAll-ModuleLocal`, `Test-ModuleLocal`, and `AfterAll-ModuleLocal` now all call the same local `Expose-TestData` action after installing the shared helper module. This keeps TestData parsing, validation, masking, and `GITHUB_ENV` export behavior identical before each phase runs. Callers continue to use the existing `TestData` workflow secret; no interface change is required. ## Changed: TestData phase parity is documented The README now states that the same TestData keys are available in setup, test, and teardown phases, and includes troubleshooting guidance for callers that use `secrets: inherit` without explicitly creating a `TestData` JSON payload. ## Technical Details - Added `.github/actions/Expose-TestData/action.yml` as the single workflow step wrapper around `Import-TestData`. - Updated `BeforeAll-ModuleLocal.yml`, `Test-ModuleLocal.yml`, and `AfterAll-ModuleLocal.yml` to use the shared action. - Added fixture assertions to both workflow test repositories so `PSMODULE_TEST_SINGLELINE_SECRET` and `PSMODULE_TEST_VARIABLE` are checked in `BeforeAll.ps1`, Pester tests, and `AfterAll.ps1`. - Implementation plan progress: core shared export path, parity validation, setup/teardown regression coverage, and README guidance are complete. - Local validation: helper test scripts passed; setup/teardown fixture assertions passed for both test repositories; touched workflow files passed actionlint with the repository's known `job.workflow_repository`/`job.workflow_sha` context warnings ignored.
1 parent 33f7f5b commit 8b1a261

11 files changed

Lines changed: 77 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:

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

tests/srcWithManifestTestRepo/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 for test environment:
57
Write-Warning "Initializing test environment..."
68

0 commit comments

Comments
 (0)