-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (137 loc) · 5.87 KB
/
Copy pathBeforeAll-ModuleLocal.yml
File metadata and controls
151 lines (137 loc) · 5.87 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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.
required: false
inputs:
Name:
type: string
description: The name of the module to process. Scripts default to the repository name if nothing is specified.
required: false
Debug:
type: boolean
description: Enable debug output.
required: false
default: false
Verbose:
type: boolean
description: Enable verbose output.
required: false
default: false
Version:
type: string
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
required: false
default: ''
Prerelease:
type: boolean
description: Whether to use a prerelease version of the 'GitHub' module.
required: false
default: false
WorkingDirectory:
type: string
description: The working directory where the script will run from.
required: false
default: '.'
permissions:
contents: read # to checkout the repo
jobs:
BeforeAll-ModuleLocal:
name: BeforeAll-ModuleLocal
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v5
- name: Install-PSModuleHelpers
uses: PSModule/Install-PSModuleHelpers@v1
- name: Run BeforeAll Setup Scripts
uses: PSModule/GitHub-Script@v1
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 }}
with:
Name: BeforeAll-ModuleLocal
ShowInfo: false
ShowOutput: true
Debug: ${{ inputs.Debug }}
Prerelease: ${{ inputs.Prerelease }}
Verbose: ${{ inputs.Verbose }}
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}
Script: |
LogGroup "Running BeforeAll Setup Scripts" {
function Find-TestDirectories {
param ([string]$Path)
$directories = @()
$childDirs = Get-ChildItem -Path $Path -Directory
foreach ($dir in $childDirs) {
$directories += $dir.FullName
$directories += Find-TestDirectories -Path $dir.FullName
}
return $directories
}
# Locate the tests directory.
$testsPath = Resolve-Path 'tests' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Path
if (-not $testsPath) {
Write-Warning 'No tests directory found'
exit 0
}
Write-Host "Tests found at [$testsPath]"
$allTestFolders = @($testsPath) + (Find-TestDirectories -Path $testsPath)
$processedDirectories = @()
foreach ($folder in $allTestFolders) {
$beforeAllScript = Join-Path $folder "BeforeAll.ps1"
if (Test-Path $beforeAllScript -PathType Leaf) {
# Get unique directory path to avoid duplicate execution
$uniqueDirectory = Resolve-Path $folder -Relative
if ($processedDirectories -notcontains $uniqueDirectory) {
$processedDirectories += $uniqueDirectory
Write-Host "Running BeforeAll setup script: $beforeAllScript"
try {
Push-Location $folder
& $beforeAllScript
Write-Host "BeforeAll script completed successfully: $beforeAllScript"
}
catch {
Write-Error "BeforeAll script failed: $beforeAllScript - $_"
throw
}
finally {
Pop-Location
}
}
}
}
if ($processedDirectories.Count -eq 0) {
Write-Host "No BeforeAll.ps1 scripts found in test directories"
} else {
Write-Host "Processed BeforeAll scripts in $($processedDirectories.Count) directories:"
$processedDirectories | ForEach-Object { Write-Host " - $_" }
}
}