🚀 [Feature]: Import-TestData is available from the shared Helpers module (#20)
The shared Helpers module now provides an Import-TestData command, so every repo that installs the helpers gets it automatically — the same way Install-PSModule is already provided. It reads the PSMODULE_TEST_DATA environment variable (a single-line JSON object with optional secrets and variables maps) and exposes each entry as an environment variable for the remaining steps in the same job, masking secret values in the logs.
- Part of PSModule/Process-PSModule#378
New: Import-TestData in the Helpers module
Test data no longer has to be wired up per repo. Previously this logic lived in a caller-shipped ./.github/scripts/Expose-TestData.ps1 that every consumer had to carry, and most never did (Template-PSModule, Confluence, …), so the Test/BeforeAll/AfterAll-ModuleLocal workflows failed with script not found. Shipping the logic in the installed Helpers module means every consumer gets it for free.
Call it from any step after the helpers are installed:
- name: Expose caller-provided test data
shell: pwsh
env:
PSMODULE_TEST_DATA: ${{ secrets.TestData }}
run: Import-TestDataBehavior:
secretsvalues are masked in the logs via::add-mask::;variablesvalues are not.- Keys are validated: they must be legal environment-variable names, must not override reserved or GitHub-provided variables, must not be duplicated across the two maps, and values must be scalar.
- When no data is provided it is a no-op.
- Outside GitHub Actions (no
GITHUB_ENV) it fails fast with a clear message instead of a generic parameter-binding error.
Technical Details
src/Helpers/Helpers.psm1: adds theImport-TestDatafunction. Its validators (Assert-EnvironmentName,Assert-Map,Get-EnvironmentValue,Add-EnvFromMap) are nested inside it so they stay private — the manifest has noFunctionsToExport, so every top-level function is exported and nesting avoids leaking generic helper names. NamedImport-TestData(notExpose-…) because module functions must use an approved verb (PSUseApprovedVerbsis enforced by super-linter across the ecosystem).- Values are written to
GITHUB_ENVusing heredoc syntax, and the writes are terminating (-ErrorAction Stop) even when the caller'sErrorActionPreferenceisContinue. tests/Import-TestData.Tests.ps1: new standalone test covering masking,GITHUB_ENVheredoc output, the no-op path, missingGITHUB_ENV, an unwritableGITHUB_ENVpath, and every validation error (invalid JSON, unexpected top-level key, invalid env name, reserved override, duplicate across maps, non-scalar value)..github/workflows/Action-Test.yml: runs the new test alongside the existingInstall-PSModuleregression test.- Validation: PSScriptAnalyzer clean with the repo settings; the module imports without an unapproved-verb warning;
Import-TestDatais exported while the validators stay private; the existing regression test still passes. - Release chain: release Install-PSModuleHelpers with
Import-TestData→ pinProcess-PSModuleto that version → Template-PSModule bumps.