Skip to content

Commit 6a2826f

Browse files
⚙️ [Maintenance]: Adopt Process-PSModule v6.1.1 and showcase test data (secret + variable) in tests (#26)
Updates the shared `Process-PSModule` reusable workflow from `v5.4.3` to the latest `v6.1.1`, and adds a worked example of the v6 `TestData` feature so module authors can see how to pass a secret and a variable down to their tests. ## Changed: Process-PSModule bumped to v6.1.1 The template now consumes `Process-PSModule` `v6.1.1` (was `v5.4.3`). The v6 major release replaced the fixed `TEST_*` workflow secret inputs with a single `TestData` object; the template did not use any `TEST_*` secrets, and the `.github/PSModule.yml` settings keys used here (`Test.CodeCoverage.PercentTarget`, `Linter.env`) remain valid in v6. ## New: Showcase for passing test data to the module tests `.github/workflows/Process-PSModule.yml` now passes a `TestData` object with one secret and one variable: ```yaml TestData: >- { "secrets": { "TEST_SECRET": "${{ secrets.TEST_SECRET }}" }, "variables": { "TEST_VARIABLE": ${{ toJSON(vars.TEST_VARIABLE) }} } } ``` - Entries in `secrets` are masked in the logs; entries in `variables` are not. - Both are exposed to the module test jobs as `$env:<name>`. `tests/Environment.Tests.ps1` consumes them and asserts they arrive. The tests **skip** when the values are absent, so a fresh repository created from this template stays green (GitHub does not copy repository secrets/variables to template instances). ## Technical Details - `.github/workflows/Process-PSModule.yml`: pin `workflow.yml@60bdf8a…` (`v5.4.3`) → `@ea19a3eb1293246d1b00e4faae1544442c3be0ec` (`v6.1.1`); add the commented `TestData` block. - `tests/Environment.Tests.ps1`: new, mirrors the sibling test-file header; `-Skip` when the env var is empty; PSScriptAnalyzer-clean against `.github/linters/.powershell-psscriptanalyzer.psd1`. - Non-sensitive demo repository secret `TEST_SECRET` and variable `TEST_VARIABLE` were added to this repo so its own CI exercises the showcase; both are safe placeholder values. - Validated locally with Pester: 2 passed with the env vars set, 2 skipped without. PR checks (pull_request event) are green. - Supersedes Dependabot PR #23 (bump to `5.5.7`), which Dependabot will close automatically once this merges to a higher version. ### Known limitation on v6.1.1 On v6.1.0/v6.1.1 the `Plan` job fails on `schedule` and `workflow_dispatch` events (its `Resolve-Version` step requires a `pull_request` event), so the template's scheduled/manual runs will fail until fixed upstream. `pull_request` runs — the primary development path — are unaffected. Tracked in PSModule/Process-PSModule#373.
1 parent 59fc671 commit 6a2826f

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

.github/workflows/Process-PSModule.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ permissions:
2727

2828
jobs:
2929
Process-PSModule:
30-
uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@60bdf8a5a4c92c53fcf2a8d23f7d5f5c93e6864e # v5.4.3
30+
uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@ea19a3eb1293246d1b00e4faae1544442c3be0ec # v6.1.1
3131
secrets:
3232
APIKEY: ${{ secrets.APIKEY }}
33+
# Showcase: send data down to the module tests (see tests/Environment.Tests.ps1).
34+
# TestData is a single-line JSON object with optional "secrets" (masked in logs) and
35+
# "variables" (not masked) maps. Every entry is exposed to the module test jobs as
36+
# $env:<name>. Reference a repository secret with the direct "${{ secrets.NAME }}"
37+
# form (single-line values, no quotes or backslashes) and a repository variable with
38+
# ${{ toJSON(vars.NAME) }} so any characters are encoded safely. The folded ">-" scalar
39+
# keeps the whole value on one line so GitHub registers a single log mask. Omit
40+
# TestData entirely when your tests need no data.
41+
TestData: >-
42+
{ "secrets": { "TEST_SECRET": "${{ secrets.TEST_SECRET }}" },
43+
"variables": { "TEST_VARIABLE": ${{ toJSON(vars.TEST_VARIABLE) }} } }

tests/Environment.Tests.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
2+
'PSReviewUnusedParameter', '',
3+
Justification = 'Required for Pester tests'
4+
)]
5+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
6+
'PSUseDeclaredVarsMoreThanAssignments', '',
7+
Justification = 'Required for Pester tests'
8+
)]
9+
[CmdletBinding()]
10+
param()
11+
12+
Describe 'TestData is exposed to the module tests' {
13+
# Showcase for the Process-PSModule 'TestData' feature. The calling workflow
14+
# (.github/workflows/Process-PSModule.yml) passes a repository secret and a repository
15+
# variable through a single TestData object, and the framework exposes each of them to
16+
# the module tests as an environment variable. To see these run, add a repository secret
17+
# named 'TEST_SECRET' and a repository variable named 'TEST_VARIABLE'. When they are not
18+
# configured the tests skip, so a fresh repository created from this template stays green.
19+
20+
It 'Exposes the secret from the "secrets" map as $env:TEST_SECRET' -Skip:([string]::IsNullOrEmpty($env:TEST_SECRET)) {
21+
# Values in the "secrets" map are masked in the workflow logs.
22+
$env:TEST_SECRET | Should -Not -BeNullOrEmpty
23+
}
24+
25+
It 'Exposes the variable from the "variables" map as $env:TEST_VARIABLE' -Skip:([string]::IsNullOrEmpty($env:TEST_VARIABLE)) {
26+
# Values in the "variables" map are not masked.
27+
$env:TEST_VARIABLE | Should -Not -BeNullOrEmpty
28+
}
29+
}

0 commit comments

Comments
 (0)