diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index f442eda..a70f92d 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -27,6 +27,17 @@ permissions: jobs: Process-PSModule: - uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@60bdf8a5a4c92c53fcf2a8d23f7d5f5c93e6864e # v5.4.3 + uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@ea19a3eb1293246d1b00e4faae1544442c3be0ec # v6.1.1 secrets: APIKEY: ${{ secrets.APIKEY }} + # Showcase: send data down to the module tests (see tests/Environment.Tests.ps1). + # TestData is a single-line JSON object with optional "secrets" (masked in logs) and + # "variables" (not masked) maps. Every entry is exposed to the module test jobs as + # $env:. Reference a repository secret with the direct "${{ secrets.NAME }}" + # form (single-line values, no quotes or backslashes) and a repository variable with + # ${{ toJSON(vars.NAME) }} so any characters are encoded safely. The folded ">-" scalar + # keeps the whole value on one line so GitHub registers a single log mask. Omit + # TestData entirely when your tests need no data. + TestData: >- + { "secrets": { "TEST_SECRET": "${{ secrets.TEST_SECRET }}" }, + "variables": { "TEST_VARIABLE": ${{ toJSON(vars.TEST_VARIABLE) }} } } diff --git a/tests/Environment.Tests.ps1 b/tests/Environment.Tests.ps1 new file mode 100644 index 0000000..01e729e --- /dev/null +++ b/tests/Environment.Tests.ps1 @@ -0,0 +1,29 @@ +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSReviewUnusedParameter', '', + Justification = 'Required for Pester tests' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', '', + Justification = 'Required for Pester tests' +)] +[CmdletBinding()] +param() + +Describe 'TestData is exposed to the module tests' { + # Showcase for the Process-PSModule 'TestData' feature. The calling workflow + # (.github/workflows/Process-PSModule.yml) passes a repository secret and a repository + # variable through a single TestData object, and the framework exposes each of them to + # the module tests as an environment variable. To see these run, add a repository secret + # named 'TEST_SECRET' and a repository variable named 'TEST_VARIABLE'. When they are not + # configured the tests skip, so a fresh repository created from this template stays green. + + It 'Exposes the secret from the "secrets" map as $env:TEST_SECRET' -Skip:([string]::IsNullOrEmpty($env:TEST_SECRET)) { + # Values in the "secrets" map are masked in the workflow logs. + $env:TEST_SECRET | Should -Not -BeNullOrEmpty + } + + It 'Exposes the variable from the "variables" map as $env:TEST_VARIABLE' -Skip:([string]::IsNullOrEmpty($env:TEST_VARIABLE)) { + # Values in the "variables" map are not masked. + $env:TEST_VARIABLE | Should -Not -BeNullOrEmpty + } +}