Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/Process-PSModule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:<name>. 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) }} } }
29 changes: 29 additions & 0 deletions tests/Environment.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading