🚀 [Feature]: Import-TestData is available from the shared Helpers module#20
Merged
Merged
Conversation
Exposes caller-provided TestData (the PSMODULE_TEST_DATA JSON blob with optional 'secrets' and 'variables' maps) as environment variables for later steps: 'secrets' values are masked via ::add-mask::, 'variables' are not. Ships the logic in the installed Helpers module so every consumer gets it, instead of a caller-shipped .github/scripts/Expose-TestData.ps1.
Copilot started reviewing on behalf of
Marius Storhaug (MariusStorhaug)
July 10, 2026 20:15
View session
There was a problem hiding this comment.
Pull request overview
This PR adds an Import-TestData function to the shared Helpers PowerShell module so GitHub Actions workflows can provide a JSON payload via PSMODULE_TEST_DATA, have it validated, and then exported to subsequent job steps through GITHUB_ENV (with secrets masked via ::add-mask::).
Changes:
- Added
Import-TestDatacmdlet that parsesPSMODULE_TEST_DATAas JSON and supportssecrets+variablessections. - Implemented validation for allowed top-level keys, env-var-safe names, reserved name/prefix protections, scalar-only values, and duplicate key prevention across maps.
- Implemented
GITHUB_ENVheredoc writing and per-line masking for secret values.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…e GITHUB_ENV Addresses Copilot review threads: switch the four Write-Output calls (no-op notice, ::add-mask::, and the two 'Exposed N ...' status lines) to Write-Host so they go to the information stream instead of the success/pipeline stream. This keeps the secret embedded in ::add-mask:: out of the function's return value and prevents status text from interfering with callers using Import-TestData in an expression context. Module already carries a module-level PSAvoidUsingWriteHost suppression, so no new suppression is needed. Also validate GITHUB_ENV up front and throw a clear message instead of letting Add-Content fail with a generic parameter-binding error when run outside GitHub Actions. Adds tests/Import-TestData.Tests.ps1 (wired into Action-Test.yml) to close the coverage gap: asserts nothing reaches the success stream, masking still happens on the information stream, the no-op path is silent, and the GITHUB_ENV guard fires.
Copilot started reviewing on behalf of
Marius Storhaug (MariusStorhaug)
July 10, 2026 21:10
View session
super-linter enforces PSScriptAnalyzer's PSAvoidLongLines (max 150), which is not in the default local ruleset; shorten the ::add-mask:: assertion message.
Copilot started reviewing on behalf of
Marius Storhaug (MariusStorhaug)
July 10, 2026 21:14
View session
…dator tests
Fixes a real bug in Add-EnvFromMap: the loop variable \ clobbered the case-insensitive \ parameter, so Get-EnvironmentValue received the entry key (e.g. MY_SECRET) instead of the section name (secrets/variables), producing misleading 'TestData.<key>' error messages. Renamed the loop variable to \ so \ keeps the section name.
Makes the no-op path silent by default (Write-Verbose instead of Write-Host) so unconditionally calling Import-TestData in workflows adds no log noise when no data is provided.
Tests: initialise the GITHUB_ENV fixture with -Encoding utf8 to match Add-Content, and add representative validation failure-case assertions (invalid JSON, unknown top-level key, invalid/reserved env-var names, duplicate keys across maps). The non-scalar case asserts the error names the section ('TestData.secrets'), which is a regression guard for the clobber bug above.
Copilot started reviewing on behalf of
Marius Storhaug (MariusStorhaug)
July 10, 2026 21:24
View session
… Stop Add-Content emits non-terminating errors by default, so a failed write to GITHUB_ENV (e.g. an unwritable path) could let the function continue and even log 'Exposed ...' while nothing was written. Add -ErrorAction Stop to the three writes so a write failure is always terminating, independent of the caller's ErrorActionPreference. Adds a regression test that points GITHUB_ENV at a non-existent directory under ErrorActionPreference=Continue and asserts Import-TestData throws.
Copilot started reviewing on behalf of
Marius Storhaug (MariusStorhaug)
July 10, 2026 21:30
View session
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The shared
Helpersmodule now provides anImport-TestDatacommand, so every repo that installs the helpers gets it automatically — the same wayInstall-PSModuleis already provided. It reads thePSMODULE_TEST_DATAenvironment variable (a single-line JSON object with optionalsecretsandvariablesmaps) and exposes each entry as an environment variable for the remaining steps in the same job, masking secret values in the logs.New:
Import-TestDatain the Helpers moduleTest data no longer has to be wired up per repo. Previously this logic lived in a caller-shipped
./.github/scripts/Expose-TestData.ps1that every consumer had to carry, and most never did (Template-PSModule, Confluence, …), so theTest/BeforeAll/AfterAll-ModuleLocalworkflows failed with script not found. Shipping the logic in the installedHelpersmodule means every consumer gets it for free.Call it from any step after the helpers are installed:
Behavior:
secretsvalues are masked in the logs via::add-mask::;variablesvalues are not.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).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.Import-TestDatais exported while the validators stay private; the existing regression test still passes.Import-TestData→ pinProcess-PSModuleto that version → Template-PSModule bumps.