-
-
Notifications
You must be signed in to change notification settings - Fork 0
273 lines (241 loc) · 9.3 KB
/
CI.yaml
File metadata and controls
273 lines (241 loc) · 9.3 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
pull-requests: write
jobs:
lint:
name: PSScriptAnalyzer Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Cache PowerShell modules
id: cache-lint-modules
uses: actions/cache@v5
with:
path: ~/.local/share/powershell/Modules
key: ${{ runner.os }}-psmodules-lint-${{ hashFiles('build.depend.psd1') }}
restore-keys: |
${{ runner.os }}-psmodules-lint-
- name: Install PSScriptAnalyzer
if: steps.cache-lint-modules.outputs.cache-hit != 'true'
shell: pwsh
run: |
$moduleFound = Get-Module -ListAvailable -Name PSScriptAnalyzer
if ($moduleFound) {
try {
Import-Module PSScriptAnalyzer -Force -ErrorAction Stop
Get-Command Invoke-ScriptAnalyzer -ErrorAction Stop | Out-Null
Write-Host 'PSScriptAnalyzer already available'
}
catch {
Write-Host 'PSScriptAnalyzer cache appears invalid; reinstalling...'
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
}
}
else {
Write-Host 'Installing PSScriptAnalyzer...'
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
}
- name: Run PSScriptAnalyzer
shell: pwsh
run: |
$results = Invoke-ScriptAnalyzer -Path ./PlexAutomationToolkit -Recurse -Settings PSGallery -ReportSummary
$errors = $results | Where-Object { $_.Severity -eq 'Error' }
if ($results) {
Write-Host "::group::PSScriptAnalyzer Results"
$results | Format-Table -AutoSize
Write-Host "::endgroup::"
}
if ($errors) {
Write-Host "::error::PSScriptAnalyzer found $($errors.Count) error(s)"
exit 1
}
Write-Host "PSScriptAnalyzer passed with no errors"
unit-tests:
name: Unit Tests (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v6
- name: Cache PowerShell modules
uses: actions/cache@v5
with:
path: |
~/Documents/PowerShell/Modules
~/.local/share/powershell/Modules
key: ${{ runner.os }}-psmodules-${{ hashFiles('build.depend.psd1') }}
restore-keys: |
${{ runner.os }}-psmodules-
- name: Build and Test
shell: pwsh
run: |
New-Item -Path out -ItemType Directory -Force | Out-Null
./build.ps1 -Task Build,Test -Bootstrap
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v6
if: success()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: out/codeCoverage.xml
flags: ${{ matrix.os }}
fail_ci_if_error: false
- name: Upload Test Results
uses: actions/upload-artifact@v7
if: always()
with:
name: test-results-${{ matrix.os }}
path: out/
retention-days: 30
unit-tests-ps51:
name: Unit Tests (Windows PowerShell 5.1)
runs-on: windows-latest
steps:
- uses: actions/checkout@v6
- name: Cache PowerShell modules
uses: actions/cache@v5
with:
path: |
~/Documents/WindowsPowerShell/Modules
key: ${{ runner.os }}-psmodules-ps51-${{ hashFiles('build.depend.psd1') }}
restore-keys: |
${{ runner.os }}-psmodules-ps51-
- name: Build and Test
shell: powershell
run: |
New-Item -Path out -ItemType Directory -Force | Out-Null
./build.ps1 -Task Build,Test -Bootstrap
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v6
if: success()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: out/codeCoverage.xml
flags: windows-ps51
fail_ci_if_error: false
- name: Upload Test Results
uses: actions/upload-artifact@v7
if: always()
with:
name: test-results-windows-ps51
path: out/
retention-days: 30
integration-tests:
name: Integration Tests (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 90
# Only run for pushes to main or PRs from the same repo (has access to secrets)
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
needs: [unit-tests, unit-tests-ps51]
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v6
- name: Cache PowerShell modules
uses: actions/cache@v5
with:
path: |
~/Documents/PowerShell/Modules
~/.local/share/powershell/Modules
key: ${{ runner.os }}-psmodules-${{ hashFiles('build.depend.psd1') }}
restore-keys: |
${{ runner.os }}-psmodules-
- name: Build Module
shell: pwsh
run: ./build.ps1 -Task Build -Bootstrap
- name: Check Integration Secrets
id: check-secrets
shell: pwsh
env:
PLEX_SERVER_URI: ${{ secrets.PLEX_SERVER_URI }}
PLEX_TOKEN: ${{ secrets.PLEX_TOKEN }}
run: |
if (-not $env:PLEX_SERVER_URI -or -not $env:PLEX_TOKEN) {
Write-Host "::warning::Integration tests skipped - PLEX_SERVER_URI or PLEX_TOKEN secrets not configured"
"secrets_configured=false" >> $env:GITHUB_OUTPUT
exit 0
}
"secrets_configured=true" >> $env:GITHUB_OUTPUT
- name: Validate Plex Token
if: steps.check-secrets.outputs.secrets_configured == 'true'
shell: pwsh
env:
PLEX_SERVER_URI: ${{ secrets.PLEX_SERVER_URI }}
PLEX_TOKEN: ${{ secrets.PLEX_TOKEN }}
run: |
# Import the built module
$moduleManifest = Get-ChildItem -Path Output/PlexAutomationToolkit -Filter '*.psd1' -Recurse |
Select-Object -First 1
if (-not $moduleManifest) {
Write-Host "::error::Module manifest not found in Output/PlexAutomationToolkit"
exit 1
}
Import-Module $moduleManifest.FullName -Force
# Add a temporary server for validation
$validationServerName = 'CI-TokenValidation'
Add-PatServer -Name $validationServerName -ServerUri $env:PLEX_SERVER_URI -Token $env:PLEX_TOKEN -SkipValidation -Confirm:$false
try {
$testResult = Test-PatServer -Name $validationServerName
if (-not $testResult.IsAuthenticated) {
$errorLines = @(
"PLEX_TOKEN secret is expired or invalid (401)."
"To fix:"
" 1) Run 'Update-PatServerToken' locally to get a fresh token"
" 2) Update the PLEX_TOKEN secret in GitHub repo Settings > Secrets and variables > Actions"
)
Write-Host "::error::$($errorLines -join ' ')"
exit 1
}
if (-not $testResult.IsConnected) {
Write-Host "::warning::Plex server at $env:PLEX_SERVER_URI is not reachable. Integration tests may fail."
}
else {
Write-Host "Token validation successful: $($testResult.FriendlyName) v$($testResult.Version)"
}
}
finally {
Remove-PatServer -Name $validationServerName -Confirm:$false -ErrorAction 'SilentlyContinue'
}
- name: Run Integration Tests
if: steps.check-secrets.outputs.secrets_configured == 'true'
timeout-minutes: 75
shell: pwsh
env:
PLEX_SERVER_URI: ${{ secrets.PLEX_SERVER_URI }}
PLEX_TOKEN: ${{ secrets.PLEX_TOKEN }}
PLEX_TEST_SECTION_ID: ${{ secrets.PLEX_TEST_SECTION_ID }}
PLEX_TEST_SECTION_NAME: ${{ secrets.PLEX_TEST_SECTION_NAME }}
PLEX_TEST_LIBRARY_PATH: ${{ secrets.PLEX_TEST_LIBRARY_PATH }}
PLEX_ALLOW_LIBRARY_REFRESH: ${{ secrets.PLEX_ALLOW_LIBRARY_REFRESH }}
run: |
# Set up build environment (required for persistence tests)
Set-BuildEnvironment -Force
# Import the built module
$moduleManifest = Get-ChildItem -Path Output/PlexAutomationToolkit -Filter '*.psd1' -Recurse |
Select-Object -First 1
if (-not $moduleManifest) {
Write-Host "::error::Module manifest not found in Output/PlexAutomationToolkit"
exit 1
}
Write-Host "Importing module from: $($moduleManifest.FullName)"
Import-Module $moduleManifest.FullName -Force
Write-Host "Running integration tests against: $env:PLEX_SERVER_URI"
Invoke-Pester -Path tests/Integration/ -CI -Output Detailed
- name: Upload Integration Test Results
uses: actions/upload-artifact@v7
if: always()
with:
name: integration-results-${{ matrix.os }}
path: testResults.xml
if-no-files-found: ignore