Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
76 changes: 47 additions & 29 deletions .github/workflows/AfterAll-ModuleLocal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,18 @@ name: AfterAll-ModuleLocal
on:
workflow_call:
secrets:
TEST_APP_ENT_CLIENT_ID:
description: The client ID of an Enterprise GitHub App for running tests.
required: false
TEST_APP_ENT_PRIVATE_KEY:
description: The private key of an Enterprise GitHub App for running tests.
required: false
TEST_APP_ORG_CLIENT_ID:
description: The client ID of an Organization GitHub App for running tests.
required: false
TEST_APP_ORG_PRIVATE_KEY:
description: The private key of an Organization GitHub App for running tests.
required: false
TEST_USER_ORG_FG_PAT:
description: The fine-grained personal access token with org access for running tests.
required: false
TEST_USER_USER_FG_PAT:
description: The fine-grained personal access token with user account access for running tests.
required: false
TEST_USER_PAT:
description: The classic personal access token for running tests.
TestData:
description: |
Optional single-line JSON object with 'secrets' and 'variables' maps. Each entry is exposed
as an environment variable available to the AfterAll teardown script; 'secrets' values are
masked in the logs, 'variables' values are not.
required: false
inputs:
Settings:
type: string
description: The complete settings object including test suites.
required: true

env:
TEST_APP_ENT_CLIENT_ID: ${{ secrets.TEST_APP_ENT_CLIENT_ID }}
TEST_APP_ENT_PRIVATE_KEY: ${{ secrets.TEST_APP_ENT_PRIVATE_KEY }}
TEST_APP_ORG_CLIENT_ID: ${{ secrets.TEST_APP_ORG_CLIENT_ID }}
TEST_APP_ORG_PRIVATE_KEY: ${{ secrets.TEST_APP_ORG_PRIVATE_KEY }}
TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }}
TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }}
TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }}

permissions:
contents: read # to checkout the repo

Expand All @@ -55,6 +31,48 @@ jobs:
persist-credentials: false
fetch-depth: 0

- name: Expose caller-provided test data
shell: pwsh
env:
PSMODULE_TEST_DATA: ${{ secrets.TestData }}
run: |
Comment thread
MariusStorhaug marked this conversation as resolved.
if ([string]::IsNullOrWhiteSpace($env:PSMODULE_TEST_DATA)) {
Write-Host 'No test data was provided by the calling workflow.'
return
}
try {
$data = $env:PSMODULE_TEST_DATA | ConvertFrom-Json -ErrorAction Stop
} catch {
throw "The 'TestData' secret must be a JSON object with 'secrets' and/or 'variables' maps. $_"
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
}
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
function Add-EnvFromMap {
param(
[object] $Map,
[switch] $Mask
)
if (-not $Map) { return }
foreach ($item in $Map.PSObject.Properties) {
$name = $item.Name
$value = [string]$item.Value
if ($Mask) {
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
foreach ($line in ($value -split "`n")) {
$line = $line.TrimEnd("`r")
if ($line.Length -gt 0) {
Write-Host "::add-mask::$line"
}
}
}
$delimiter = "GHENV_$([guid]::NewGuid().ToString('N'))"
Add-Content -Path $env:GITHUB_ENV -Value "$name<<$delimiter"
Add-Content -Path $env:GITHUB_ENV -Value $value
Add-Content -Path $env:GITHUB_ENV -Value $delimiter
Write-Host "Exposed [$name] as an environment variable."
}
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
}

Add-EnvFromMap -Map $data.secrets -Mask
Add-EnvFromMap -Map $data.variables

- name: Run AfterAll Teardown Scripts
if: always()
uses: PSModule/GitHub-Script@1ee97bbc652d19c38ae12f6e1e47e9d9fbd12d0a # v1.8.0
Expand Down
76 changes: 47 additions & 29 deletions .github/workflows/BeforeAll-ModuleLocal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,18 @@ name: BeforeAll-ModuleLocal
on:
workflow_call:
secrets:
TEST_APP_ENT_CLIENT_ID:
description: The client ID of an Enterprise GitHub App for running tests.
required: false
TEST_APP_ENT_PRIVATE_KEY:
description: The private key of an Enterprise GitHub App for running tests.
required: false
TEST_APP_ORG_CLIENT_ID:
description: The client ID of an Organization GitHub App for running tests.
required: false
TEST_APP_ORG_PRIVATE_KEY:
description: The private key of an Organization GitHub App for running tests.
required: false
TEST_USER_ORG_FG_PAT:
description: The fine-grained personal access token with org access for running tests.
required: false
TEST_USER_USER_FG_PAT:
description: The fine-grained personal access token with user account access for running tests.
required: false
TEST_USER_PAT:
description: The classic personal access token for running tests.
TestData:
description: |
Optional single-line JSON object with 'secrets' and 'variables' maps. Each entry is exposed
as an environment variable available to the BeforeAll setup script; 'secrets' values are
masked in the logs, 'variables' values are not.
required: false
inputs:
Settings:
type: string
description: The complete settings object including test suites.
required: true

env:
TEST_APP_ENT_CLIENT_ID: ${{ secrets.TEST_APP_ENT_CLIENT_ID }}
TEST_APP_ENT_PRIVATE_KEY: ${{ secrets.TEST_APP_ENT_PRIVATE_KEY }}
TEST_APP_ORG_CLIENT_ID: ${{ secrets.TEST_APP_ORG_CLIENT_ID }}
TEST_APP_ORG_PRIVATE_KEY: ${{ secrets.TEST_APP_ORG_PRIVATE_KEY }}
TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }}
TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }}
TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }}

permissions:
contents: read # to checkout the repo

Expand All @@ -55,6 +31,48 @@ jobs:
persist-credentials: false
fetch-depth: 0

- name: Expose caller-provided test data
shell: pwsh
env:
PSMODULE_TEST_DATA: ${{ secrets.TestData }}
run: |
Comment thread
MariusStorhaug marked this conversation as resolved.
if ([string]::IsNullOrWhiteSpace($env:PSMODULE_TEST_DATA)) {
Write-Host 'No test data was provided by the calling workflow.'
return
}
try {
$data = $env:PSMODULE_TEST_DATA | ConvertFrom-Json -ErrorAction Stop
} catch {
throw "The 'TestData' secret must be a JSON object with 'secrets' and/or 'variables' maps. $_"
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
}
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
function Add-EnvFromMap {
param(
[object] $Map,
[switch] $Mask
)
if (-not $Map) { return }
foreach ($item in $Map.PSObject.Properties) {
$name = $item.Name
$value = [string]$item.Value
if ($Mask) {
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
foreach ($line in ($value -split "`n")) {
$line = $line.TrimEnd("`r")
if ($line.Length -gt 0) {
Write-Host "::add-mask::$line"
}
}
}
$delimiter = "GHENV_$([guid]::NewGuid().ToString('N'))"
Add-Content -Path $env:GITHUB_ENV -Value "$name<<$delimiter"
Add-Content -Path $env:GITHUB_ENV -Value $value
Add-Content -Path $env:GITHUB_ENV -Value $delimiter
Write-Host "Exposed [$name] as an environment variable."
}
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
}

Add-EnvFromMap -Map $data.secrets -Mask
Add-EnvFromMap -Map $data.variables

- name: Run BeforeAll Setup Scripts
uses: PSModule/GitHub-Script@1ee97bbc652d19c38ae12f6e1e47e9d9fbd12d0a # v1.8.0
with:
Expand Down
74 changes: 47 additions & 27 deletions .github/workflows/Test-ModuleLocal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,11 @@ name: Test-ModuleLocal
on:
workflow_call:
secrets:
TEST_APP_ENT_CLIENT_ID:
description: The client ID of an Enterprise GitHub App for running tests.
required: false
TEST_APP_ENT_PRIVATE_KEY:
description: The private key of an Enterprise GitHub App for running tests.
required: false
TEST_APP_ORG_CLIENT_ID:
description: The client ID of an Organization GitHub App for running tests.
required: false
TEST_APP_ORG_PRIVATE_KEY:
description: The private key of an Organization GitHub App for running tests.
required: false
TEST_USER_ORG_FG_PAT:
description: The fine-grained personal access token with org access for running tests.
required: false
TEST_USER_USER_FG_PAT:
description: The fine-grained personal access token with user account access for running tests.
required: false
TEST_USER_PAT:
description: The classic personal access token for running tests.
TestData:
description: |
Optional single-line JSON object with 'secrets' and 'variables' maps. Each entry is exposed
as an environment variable the module's Pester tests read via $env:<name>; 'secrets' values
are masked in the logs, 'variables' values are not.
required: false
inputs:
Settings:
Expand All @@ -34,13 +19,6 @@ permissions:
contents: read # to checkout the repo and create releases on the repo

env:
TEST_APP_ENT_CLIENT_ID: ${{ secrets.TEST_APP_ENT_CLIENT_ID }}
TEST_APP_ENT_PRIVATE_KEY: ${{ secrets.TEST_APP_ENT_PRIVATE_KEY }}
TEST_APP_ORG_CLIENT_ID: ${{ secrets.TEST_APP_ORG_CLIENT_ID }}
TEST_APP_ORG_PRIVATE_KEY: ${{ secrets.TEST_APP_ORG_PRIVATE_KEY }}
TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }}
TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }}
TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }}
GITHUB_TOKEN: ${{ github.token }}

jobs:
Expand All @@ -58,6 +36,48 @@ jobs:
persist-credentials: false
fetch-depth: 0

- name: Expose caller-provided test data
shell: pwsh
env:
PSMODULE_TEST_DATA: ${{ secrets.TestData }}
run: |
Comment thread
MariusStorhaug marked this conversation as resolved.
if ([string]::IsNullOrWhiteSpace($env:PSMODULE_TEST_DATA)) {
Write-Host 'No test data was provided by the calling workflow.'
return
}
try {
$data = $env:PSMODULE_TEST_DATA | ConvertFrom-Json -ErrorAction Stop
} catch {
throw "The 'TestData' secret must be a JSON object with 'secrets' and/or 'variables' maps. $_"
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
}
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
function Add-EnvFromMap {
param(
[object] $Map,
[switch] $Mask
)
if (-not $Map) { return }
foreach ($item in $Map.PSObject.Properties) {
$name = $item.Name
$value = [string]$item.Value
if ($Mask) {
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
foreach ($line in ($value -split "`n")) {
$line = $line.TrimEnd("`r")
if ($line.Length -gt 0) {
Write-Host "::add-mask::$line"
}
}
}
$delimiter = "GHENV_$([guid]::NewGuid().ToString('N'))"
Add-Content -Path $env:GITHUB_ENV -Value "$name<<$delimiter"
Add-Content -Path $env:GITHUB_ENV -Value $value
Add-Content -Path $env:GITHUB_ENV -Value $delimiter
Write-Host "Exposed [$name] as an environment variable."
}
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
}

Add-EnvFromMap -Map $data.secrets -Mask
Add-EnvFromMap -Map $data.variables

- name: Download module artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
Expand Down
18 changes: 11 additions & 7 deletions .github/workflows/Workflow-Test-Default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ jobs:
uses: ./.github/workflows/workflow.yml
secrets:
APIKey: ${{ secrets.APIKey }}
TEST_APP_ENT_CLIENT_ID: ${{ secrets.TEST_APP_ENT_CLIENT_ID }}
TEST_APP_ENT_PRIVATE_KEY: ${{ secrets.TEST_APP_ENT_PRIVATE_KEY }}
TEST_APP_ORG_CLIENT_ID: ${{ secrets.TEST_APP_ORG_CLIENT_ID }}
TEST_APP_ORG_PRIVATE_KEY: ${{ secrets.TEST_APP_ORG_PRIVATE_KEY }}
TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }}
TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }}
TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }}
# Self-test only: a dedicated, NON-SENSITIVE repository secret + variable exist purely to prove
# the TestData plumbing end to end - the "secrets" entry is masked and the "variables" entry is
# not, and both are exposed as $env:<name>. Their known values are asserted (value + length) in
# tests/.../Environment.Tests.ps1.
# Secrets use the direct "${{ secrets.X }}" form (CodeQL-clean; avoids toJSON(secrets.*)), which
# requires single-line secret values with no embedded quotes or backslashes; variables use
# toJSON(vars.X) so any characters are encoded safely. The folded '>-' scalar keeps the whole blob
# on ONE line so GitHub registers a single mask instead of one per line.
TestData: >-
{ "secrets": { "PSMODULE_TEST_SINGLELINE_SECRET": "${{ secrets.PSMODULE_TEST_SINGLELINE_SECRET }}" },
"variables": { "PSMODULE_TEST_VARIABLE": ${{ toJSON(vars.PSMODULE_TEST_VARIABLE) }} } }
Comment thread
MariusStorhaug marked this conversation as resolved.
with:
WorkingDirectory: tests/srcTestRepo
ImportantFilePatterns: |
Expand Down
18 changes: 11 additions & 7 deletions .github/workflows/Workflow-Test-WithManifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ jobs:
uses: ./.github/workflows/workflow.yml
secrets:
APIKey: ${{ secrets.APIKey }}
TEST_APP_ENT_CLIENT_ID: ${{ secrets.TEST_APP_ENT_CLIENT_ID }}
TEST_APP_ENT_PRIVATE_KEY: ${{ secrets.TEST_APP_ENT_PRIVATE_KEY }}
TEST_APP_ORG_CLIENT_ID: ${{ secrets.TEST_APP_ORG_CLIENT_ID }}
TEST_APP_ORG_PRIVATE_KEY: ${{ secrets.TEST_APP_ORG_PRIVATE_KEY }}
TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }}
TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }}
TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }}
# Self-test only: a dedicated, NON-SENSITIVE repository secret + variable exist purely to prove
# the TestData plumbing end to end - the "secrets" entry is masked and the "variables" entry is
# not, and both are exposed as $env:<name>. Their known values are asserted (value + length) in
# tests/.../Environment.Tests.ps1.
# Secrets use the direct "${{ secrets.X }}" form (CodeQL-clean; avoids toJSON(secrets.*)), which
# requires single-line secret values with no embedded quotes or backslashes; variables use
# toJSON(vars.X) so any characters are encoded safely. The folded '>-' scalar keeps the whole blob
# on ONE line so GitHub registers a single mask instead of one per line.
TestData: >-
{ "secrets": { "PSMODULE_TEST_SINGLELINE_SECRET": "${{ secrets.PSMODULE_TEST_SINGLELINE_SECRET }}" },
"variables": { "PSMODULE_TEST_VARIABLE": ${{ toJSON(vars.PSMODULE_TEST_VARIABLE) }} } }
Comment thread
MariusStorhaug marked this conversation as resolved.
with:
WorkingDirectory: tests/srcWithManifestTestRepo
ImportantFilePatterns: |
Expand Down
Loading
Loading