-
Notifications
You must be signed in to change notification settings - Fork 0
355 lines (300 loc) · 11.6 KB
/
Copy pathci-cd.yml
File metadata and controls
355 lines (300 loc) · 11.6 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# GitHub Actions CI/CD Workflow for Windows Server PowerShell Solutions
# Author: Adrian Johnson (adrian207@gmail.com)
# Version: 1.0.0
# Date: December 2024
name: Windows Server PowerShell Solutions CI/CD
on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master ]
release:
types: [ published ]
env:
POWERSHELL_VERSION: '7.4.0'
MODULE_PATH: './Modules'
jobs:
# Code Quality and Linting
code-quality:
name: Code Quality Check
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PowerShell
uses: actions/setup-powershell@v1
with:
version: ${{ env.POWERSHELL_VERSION }}
- name: Install PSScriptAnalyzer
run: |
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
- name: Run PSScriptAnalyzer
run: |
$results = @()
Get-ChildItem -Path . -Recurse -Include "*.ps1", "*.psm1" | ForEach-Object {
$analysis = Invoke-ScriptAnalyzer -Path $_.FullName -Severity Error, Warning
if ($analysis) {
$results += $analysis
}
}
if ($results.Count -gt 0) {
Write-Host "Script Analysis Issues Found:" -ForegroundColor Red
$results | Format-Table -AutoSize
exit 1
} else {
Write-Host "No script analysis issues found!" -ForegroundColor Green
}
- name: Validate PowerShell Syntax
run: |
$errors = @()
Get-ChildItem -Path . -Recurse -Include "*.ps1", "*.psm1" | ForEach-Object {
$content = Get-Content $_.FullName -Raw
$null = [System.Management.Automation.PSParser]::Tokenize($content, [ref]$null)
if ($null) {
$errors += "Syntax error in $($_.FullName)"
}
}
if ($errors.Count -gt 0) {
Write-Host "PowerShell Syntax Errors:" -ForegroundColor Red
$errors | ForEach-Object { Write-Host $_ -ForegroundColor Red }
exit 1
} else {
Write-Host "All PowerShell files have valid syntax!" -ForegroundColor Green
}
# Security Scanning
security-scan:
name: Security Scan
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PowerShell
uses: actions/setup-powershell@v1
with:
version: ${{ env.POWERSHELL_VERSION }}
- name: Install Security Modules
run: |
Install-Module -Name SecurityPolicyDsc -Force -Scope CurrentUser
Install-Module -Name AuditPolicyDsc -Force -Scope CurrentUser
- name: Run Security Analysis
run: |
Write-Host "Running security analysis..." -ForegroundColor Yellow
# Check for hardcoded credentials
$credentialPatterns = @(
'password\s*=\s*["\'][^"\']+["\']',
'pwd\s*=\s*["\'][^"\']+["\']',
'pass\s*=\s*["\'][^"\']+["\']',
'secret\s*=\s*["\'][^"\']+["\']'
)
$securityIssues = @()
Get-ChildItem -Path . -Recurse -Include "*.ps1", "*.psm1", "*.json" | ForEach-Object {
$content = Get-Content $_.FullName -Raw
foreach ($pattern in $credentialPatterns) {
if ($content -match $pattern) {
$securityIssues += "Potential credential exposure in $($_.FullName)"
}
}
}
if ($securityIssues.Count -gt 0) {
Write-Host "Security Issues Found:" -ForegroundColor Red
$securityIssues | ForEach-Object { Write-Host $_ -ForegroundColor Red }
exit 1
} else {
Write-Host "No security issues found!" -ForegroundColor Green
}
# Documentation Validation
documentation-check:
name: Documentation Check
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check Documentation Structure
run: |
$requiredFiles = @(
'README.md',
'ARCHITECTURE.md',
'DEPLOYMENT-GUIDE.md',
'API-REFERENCE.md',
'SECURITY-COMPLIANCE.md',
'LICENSE',
'CONTRIBUTING.md'
)
$missingFiles = @()
foreach ($file in $requiredFiles) {
if (-not (Test-Path $file)) {
$missingFiles += $file
}
}
if ($missingFiles.Count -gt 0) {
Write-Host "Missing Documentation Files:" -ForegroundColor Red
$missingFiles | ForEach-Object { Write-Host $_ -ForegroundColor Red }
exit 1
} else {
Write-Host "All required documentation files present!" -ForegroundColor Green
}
- name: Validate Markdown Syntax
run: |
# Check for basic markdown syntax issues
$markdownFiles = Get-ChildItem -Path . -Recurse -Include "*.md"
$issues = @()
foreach ($file in $markdownFiles) {
$content = Get-Content $file.FullName -Raw
# Check for unclosed headers
if ($content -match '^#{1,6}\s*$') {
$issues += "Empty header in $($file.FullName)"
}
# Check for author information
if ($file.Name -eq 'README.md' -and $content -notmatch 'Adrian Johnson') {
$issues += "Missing author information in $($file.FullName)"
}
}
if ($issues.Count -gt 0) {
Write-Host "Documentation Issues:" -ForegroundColor Red
$issues | ForEach-Object { Write-Host $_ -ForegroundColor Red }
exit 1
} else {
Write-Host "Documentation validation passed!" -ForegroundColor Green
}
# Build and Test
build-test:
name: Build and Test
runs-on: windows-latest
needs: [code-quality, security-scan, documentation-check]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PowerShell
uses: actions/setup-powershell@v1
with:
version: ${{ env.POWERSHELL_VERSION }}
- name: Install Dependencies
run: |
# Install required PowerShell modules
$modules = @(
'ActiveDirectory',
'DnsServer',
'DhcpServer',
'Hyper-V',
'FailoverClusters',
'WebAdministration',
'RemoteDesktop',
'PrintManagement'
)
foreach ($module in $modules) {
try {
Import-Module $module -ErrorAction Stop
Write-Host "Module $module imported successfully" -ForegroundColor Green
} catch {
Write-Host "Module $module not available (expected in CI environment)" -ForegroundColor Yellow
}
}
- name: Run Unit Tests
run: |
$testFiles = Get-ChildItem -Path . -Recurse -Include "*Test*.ps1"
$testResults = @()
foreach ($testFile in $testFiles) {
Write-Host "Running tests in $($testFile.FullName)" -ForegroundColor Yellow
try {
& $testFile.FullName
$testResults += "PASS: $($testFile.Name)"
} catch {
$testResults += "FAIL: $($testFile.Name) - $($_.Exception.Message)"
}
}
Write-Host "Test Results:" -ForegroundColor Cyan
$testResults | ForEach-Object { Write-Host $_ }
- name: Generate Test Report
run: |
$report = @"
# Test Report - $(Get-Date)
## Test Summary
- Total Test Files: $($testFiles.Count)
- Tests Run: $(Get-Date)
## Results
$($testResults -join "`n")
## Environment
- PowerShell Version: $($PSVersionTable.PSVersion)
- OS Version: $($PSVersionTable.OS)
- Platform: $($PSVersionTable.Platform)
"@
$report | Out-File -FilePath "test-report.md" -Encoding UTF8
- name: Upload Test Report
uses: actions/upload-artifact@v3
with:
name: test-report
path: test-report.md
# Release Preparation
release-prep:
name: Release Preparation
runs-on: windows-latest
needs: [build-test]
if: github.event_name == 'release'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Release Package
run: |
$releaseDir = "Windows-Server-PowerShell-Solutions-v${{ github.event.release.tag_name }}"
New-Item -ItemType Directory -Path $releaseDir -Force
# Copy all solution directories
$solutions = @(
'AD-CS-Scripts',
'Active-Directory-Scripts',
'AD-LDS-Scripts',
'AD-RMS-Scripts',
'ADFS-Scripts',
'Backup-Storage-Services',
'DHCP-Scripts',
'DNS-Scripts',
'Failover-Clustering-Scripts',
'File-Storage-Services',
'HGS-Scripts',
'Hyper-V-Scripts',
'IIS-Web-Server',
'NPAS-Scripts',
'Print-Server-Scripts',
'Remote-Access-Services',
'Remote-Desktop-Services',
'Entra-Connect-Scripts'
)
foreach ($solution in $solutions) {
if (Test-Path $solution) {
Copy-Item -Path $solution -Destination $releaseDir -Recurse
Write-Host "Copied $solution to release package" -ForegroundColor Green
}
}
# Copy documentation
Copy-Item -Path "*.md" -Destination $releaseDir
Copy-Item -Path "LICENSE" -Destination $releaseDir
# Create ZIP package
Compress-Archive -Path $releaseDir -DestinationPath "$releaseDir.zip"
Write-Host "Release package created: $releaseDir.zip" -ForegroundColor Green
- name: Upload Release Artifacts
uses: actions/upload-artifact@v3
with:
name: release-package
path: Windows-Server-PowerShell-Solutions-v${{ github.event.release.tag_name }}.zip
# Notification
notify:
name: Notify Results
runs-on: windows-latest
needs: [code-quality, security-scan, documentation-check, build-test]
if: always()
steps:
- name: Notify Success
if: needs.code-quality.result == 'success' && needs.security-scan.result == 'success' && needs.documentation-check.result == 'success' && needs.build-test.result == 'success'
run: |
Write-Host "🎉 All CI/CD checks passed successfully!" -ForegroundColor Green
Write-Host "✅ Code Quality: PASSED" -ForegroundColor Green
Write-Host "✅ Security Scan: PASSED" -ForegroundColor Green
Write-Host "✅ Documentation: PASSED" -ForegroundColor Green
Write-Host "✅ Build & Test: PASSED" -ForegroundColor Green
- name: Notify Failure
if: needs.code-quality.result == 'failure' || needs.security-scan.result == 'failure' || needs.documentation-check.result == 'failure' || needs.build-test.result == 'failure'
run: |
Write-Host "❌ CI/CD checks failed!" -ForegroundColor Red
Write-Host "Code Quality: $($needs.code-quality.result)" -ForegroundColor $(if ($needs.code-quality.result -eq 'success') { 'Green' } else { 'Red' })
Write-Host "Security Scan: $($needs.security-scan.result)" -ForegroundColor $(if ($needs.security-scan.result -eq 'success') { 'Green' } else { 'Red' })
Write-Host "Documentation: $($needs.documentation-check.result)" -ForegroundColor $(if ($needs.documentation-check.result -eq 'success') { 'Green' } else { 'Red' })
Write-Host "Build & Test: $($needs.build-test.result)" -ForegroundColor $(if ($needs.build-test.result -eq 'success') { 'Green' } else { 'Red' })