-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (84 loc) · 3.38 KB
/
Copy pathBeforeAll-ModuleLocal.yml
File metadata and controls
91 lines (84 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: BeforeAll-ModuleLocal
on:
workflow_call:
secrets:
TestSecrets:
description: |
Optional JSON object mapping environment variable names to secret values. Each entry is
exposed as an environment variable available to the BeforeAll setup script.
required: false
inputs:
Settings:
type: string
description: The complete settings object including test suites.
required: true
permissions:
contents: read # to checkout the repo
jobs:
BeforeAll-ModuleLocal:
name: BeforeAll-ModuleLocal
runs-on: ubuntu-latest
env:
Settings: ${{ inputs.Settings }}
steps:
- name: Checkout Code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
fetch-depth: 0
- name: Expose caller-provided test secrets
shell: pwsh
env:
PSMODULE_TEST_SECRETS: ${{ secrets.TestSecrets }}
run: |
if ([string]::IsNullOrWhiteSpace($env:PSMODULE_TEST_SECRETS)) {
Write-Host 'No test secrets were provided by the calling workflow.'
return
}
try {
$secrets = $env:PSMODULE_TEST_SECRETS | ConvertFrom-Json -ErrorAction Stop
} catch {
throw "The 'TestSecrets' secret must be a JSON object mapping names to values. $_"
}
foreach ($secret in $secrets.PSObject.Properties) {
$name = $secret.Name
$value = [string]$secret.Value
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."
}
- name: Run BeforeAll Setup Scripts
uses: PSModule/GitHub-Script@1ee97bbc652d19c38ae12f6e1e47e9d9fbd12d0a # v1.8.0
with:
Name: BeforeAll-ModuleLocal
ShowInfo: false
ShowOutput: true
Debug: ${{ fromJson(inputs.Settings).Debug }}
Prerelease: ${{ fromJson(inputs.Settings).Prerelease }}
Verbose: ${{ fromJson(inputs.Settings).Verbose }}
Version: ${{ fromJson(inputs.Settings).Version }}
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
Script: |
LogGroup "Running BeforeAll Setup Scripts" {
$beforeAllScript = 'tests/BeforeAll.ps1'
if (-not (Test-Path $beforeAllScript)) {
Write-Host "No BeforeAll.ps1 script found at [$beforeAllScript] - exiting successfully"
exit 0
}
Write-Host "Running BeforeAll setup script: $beforeAllScript"
try {
& $beforeAllScript
Write-Host "BeforeAll script completed successfully: $beforeAllScript"
} catch {
Write-Error "BeforeAll script failed: $beforeAllScript - $_"
throw
}
}