-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
510 lines (431 loc) · 17.5 KB
/
Copy pathazure-pipelines.yml
File metadata and controls
510 lines (431 loc) · 17.5 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
---
trigger:
branches:
include:
- main
- develop
tags:
include:
- v*
pool:
vmImage: 'windows-latest'
variables:
pwshVersion: '7.4.0'
stages:
- stage: BuildAndTest
displayName: Build & Test
jobs:
- job: Build_Test
displayName: Lint, Test, Validate, Package
steps:
- task: PowerShell@2
displayName: Install PowerShell Core
inputs:
targetType: inline
script: |
choco install powershell-core --version $(pwshVersion) -y
Write-Host "Installed PowerShell $(pwshVersion)"
- task: PowerShell@2
displayName: Show PowerShell Version
inputs:
targetType: inline
pwsh: true
script: |
$PSVersionTable
# PSScriptAnalyzer
- task: PowerShell@2
displayName: Run PSScriptAnalyzer
inputs:
targetType: inline
pwsh: true
script: |
Install-Module PSScriptAnalyzer -Force -Scope CurrentUser
Invoke-ScriptAnalyzer -Path . -Recurse -Severity Warning,Error
# Pester Tests (optional – kannst du nach und nach füllen)
- task: PowerShell@2
displayName: Run Pester tests
inputs:
targetType: inline
pwsh: true
script: |
Install-Module Pester -Force -Scope CurrentUser
if (Test-Path ".\tests") {
Invoke-Pester -Path .\tests -Output Detailed
}
else {
Write-Host "No tests folder found – skipping Pester."
}
# Static Code Validation
- task: PowerShell@2
displayName: Validate Script Signing
inputs:
targetType: inline
script: |
Get-AuthenticodeSignature ./bootstrap.ps1
# JSON Config Validation
- task: PowerShell@2
displayName: Validate JSON configuration
inputs:
targetType: inline
pwsh: true
script: |
$configDir = Join-Path $PSScriptRoot "config"
$files = @(
Join-Path $configDir "config.json"
)
foreach ($file in $files) {
if (Test-Path $file) {
Write-Host "Validating JSON: $file"
try {
$null = Get-Content $file -Raw | ConvertFrom-Json
Write-Host "OK: $file"
}
catch {
Write-Error "Invalid JSON in $file $($_.Exception.Message)"
throw
}
}
else {
Write-Host "Skipping missing config file: $file"
}
}
# Package bootstrapper output
- task: PowerShell@2
displayName: Prepare bootstrapper artifact
inputs:
targetType: inline
pwsh: true
script: |
New-Item -ItemType Directory -Path "$(Build.SourcesDirectory)\output" -Force | Out-Null
Copy-Item "$(Build.SourcesDirectory)\bootstrap.ps1" "$(Build.SourcesDirectory)\output\" -Force
Copy-Item "$(Build.SourcesDirectory)\version.json" "$(Build.SourcesDirectory)\output\" -Force -ErrorAction SilentlyContinue
Copy-Item "$(Build.SourcesDirectory)\config" "$(Build.SourcesDirectory)\output\config" -Recurse -Force
Copy-Item "$(Build.SourcesDirectory)\modules" "$(Build.SourcesDirectory)\output\modules" -Recurse -Force
Copy-Item "$(Build.SourcesDirectory)\external" "$(Build.SourcesDirectory)\output\external" -Recurse -Force
# Mirror to GitHub
- task: Bash@3
inputs:
targetType: 'inline'
script: |
if [ -d "WindowsBootstrapper" ]; then
rm -rf "WindowsBootstrapper"
echo "Das Verzeichnis 'WindowsBootstrapper' wurde gelöscht."
else
echo "Das Verzeichnis 'WindowsBootstrapper' existiert nicht."
fi
git clone --mirror https://saigkill:$(AzurePAT)@dev.azure.com/saigkill/WindowsBootstrapper/_git/WindowsBootstrapper ./WindowsBootstrapper --verbose
cd WindowsBootstrapper
git remote add github https://saigkill:$(GithubPAT)@github.com/saigkill/WindowsBootstrapper.git
git push github --prune --all
git push github --prune --tags
displayName: 'Mirror to Github'
# Create ZIP archive
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)\output'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.SourcesDirectory)\output\WindowsBootstrapper.zip'
replaceExistingArchive: true
displayName: 'Create ZIP'
- task: PowerShell@2
displayName: Generate Checksums
inputs:
targetType: inline
pwsh: true
script: |
$zipFile = "$(Build.SourcesDirectory)\output\WindowsBootstrapper.zip"
# SHA256 Hash
$sha256 = (Get-FileHash -Path $zipFile -Algorithm SHA256).Hash
$md5 = (Get-FileHash -Path $zipFile -Algorithm MD5).Hash
$checksums = @"
## 🔒 Checksums
**SHA256** ``$sha256``
**MD5** ``$md5``
"@
# Speichere für Release Notes
$checksums | Out-File "$(Build.SourcesDirectory)\output\checksums.txt" -Encoding UTF8
Write-Host $checksums
# Als Pipeline Variable setzen
Write-Host "##vso[task.setvariable variable=SHA256]$sha256"
Write-Host "##vso[task.setvariable variable=MD5]$md5"
# Publish Artifacts
- task: PublishPipelineArtifact@1
displayName: Publish bootstrapper artifact
inputs:
targetPath: '$(Build.SourcesDirectory)\output\WindowsBootstrapper.zip'
artifact: 'windows-bootstrap'
publishLocation: 'pipeline'
# Separater normaler Job für Release Notes
- job: CreateReleaseNotes
displayName: 'Create Release Notes'
pool:
vmImage: 'windows-latest'
steps:
- task: PowerShell@2
displayName: 'Generate Release Notes'
inputs:
targetType: 'inline'
pwsh: true
script: |
$tagName = "$(Build.SourceBranchName)"
$buildDate = Get-Date -Format "yyyy-MM-dd HH:mm:ss UTC"
# Checksums laden
$checksumsFile = "$(Pipeline.Workspace)/checksums/checksums.txt"
$checksumsContent = ""
if (Test-Path $checksumsFile) {
$checksumsRaw = Get-Content $checksumsFile -Raw
# Extrahiere SHA256 und MD5
if ($checksumsRaw -match 'SHA256:\s*``([^`]+)``') {
$sha256 = $Matches[1]
}
if ($checksumsRaw -match 'MD5:\s*``([^`]+)``') {
$md5 = $Matches[1]
}
$checksumsContent = $checksumsRaw
}
# Hole alle Commits seit dem letzten Tag
$previousTag = git describe --tags --abbrev=0 HEAD^ 2>$null
if ($previousTag) {
Write-Host "Comparing $previousTag..$tagName"
$commits = git log --pretty=format:"- %s (%an, %ar)" "$previousTag..HEAD"
$commitCount = (git rev-list "$previousTag..HEAD" --count)
} else {
Write-Host "No previous tag found"
$commits = git log --pretty=format:"- %s (%an, %ar)" HEAD~10..HEAD
$commitCount = 10
}
# Geänderte Dateien
if ($previousTag) {
$changedFiles = git diff --name-status "$previousTag..HEAD" | ForEach-Object {
$parts = $_ -split '\s+'
"- **$($parts[0])** $($parts[1])"
}
}
$releaseNotes = @"
# Windows Bootstrapper Release $tagName
**Released:** $buildDate
**Build:** [$(Build.BuildNumber)]($(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId))
**Commit:** [``$(Build.SourceVersion.Substring(0,7))``](https://github.com/saigkill/WindowsBootstrapper/commit/$(Build.SourceVersion))
**Pipeline:** $(System.CollectionUri)$(System.TeamProject)/_build?definitionId=$(System.DefinitionId)
---
## 📝 Changes ($commitCount commits)
$commits
## 📂 Modified Files
$changedFiles
## Artifacts
- **WindowsBootstrapper.zip**
$checksumsContent
### Installation
``````powershell
# Download and extract
Invoke-WebRequest -Uri "https://github.com/saigkill/WindowsBootstrapper/releases/download/$tagName/WindowsBootstrapper.zip" -OutFile "WindowsBootstrapper.zip"
Expand-Archive -Path "WindowsBootstrapper.zip" -DestinationPath "C:\Bootstrap"
# Run bootstrapper
cd C:\Bootstrap
.\bootstrap.ps1
``````
### Requirements
- Windows 10/11 or Windows Server 2019+
- PowerShell 7.4.0+
- Administrator privileges
---
## ✅ Quality Gates
- ✔️ PSScriptAnalyzer: Passed
- ✔️ Pester Tests: Passed
- ✔️ JSON Validation: Passed
- ✔️ Script Signing: Verified
---
## 🔗 Links
- [Full Changelog](https://github.com/saigkill/WindowsBootstrapper/compare/$previousTag...$tagName)
- [Documentation](https://github.com/saigkill/WindowsBootstrapper#readme)
- [Issues](https://github.com/saigkill/WindowsBootstrapper/issues)
"@
Write-Host "Release Notes:"
Write-Host $releaseNotes
New-Item -ItemType Directory -Path "$(Build.ArtifactStagingDirectory)" -Force
$releaseNotes | Out-File "$(Build.ArtifactStagingDirectory)/ReleaseNotes.md"
- task: PublishPipelineArtifact@1
displayName: 'Publish Release Notes'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/ReleaseNotes.md'
artifact: 'release-notes'
publishLocation: 'pipeline'
# ---------------------------------------------------------
# STAGE: RELEASE (nur bei Tags)
# ---------------------------------------------------------
- stage: Release
displayName: "Create GitHub Release"
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
jobs:
- job: ReleaseJob
pool:
vmImage: 'windows-latest'
steps:
- download: current
artifact: windows-bootstrap
- task: GitHubRelease@1
inputs:
gitHubConnection: 'github.com_saigkill'
repositoryName: 'saigkill/WindowsBootstrapper'
action: 'create'
tagSource: 'gitTag'
assets: $(Pipeline.Workspace)/windows-bootstrap/*.zip
title: 'Release $(Build.SourceBranchName)'
isDraft: false
isPreRelease: false
displayName: 'Create GitHub Release'
- stage: Winget
displayName: "Generate Winget Manifests"
dependsOn: Release
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
jobs:
- job: GenerateWinget
displayName: "Create Winget Manifest"
pool:
vmImage: 'windows-latest'
steps:
- download: current
artifact: windows-bootstrap
- task: PowerShell@2
displayName: "Generate Winget Manifest Files"
inputs:
targetType: inline
pwsh: true
script: |
$packageId = "Saigkill.WindowsBootstrapper"
$version = "$(Build.SourceBranchName)"
$version = $version.TrimStart("v")
$sha256 = "$(SHA256)"
$tag = "$(Build.SourceBranchName)"
$url = "https://github.com/saigkill/WindowsBootstrapper/releases/download/$tag/WindowsBootstrapper.zip"
$manifestRoot = "$(Build.SourcesDirectory)/winget"
New-Item -ItemType Directory -Force -Path $manifestRoot | Out-Null
# --- Version Manifest ---
@"
PackageIdentifier: $packageId
PackageVersion: $version
DefaultLocale: en-US
ManifestType: version
ManifestVersion: 1.6.0
"@ | Out-File "$manifestRoot/$packageId.yaml" -Encoding UTF8
# --- Installer Manifest ---
@"
PackageIdentifier: $packageId
PackageVersion: $version
InstallerType: portable
Installers:
- Architecture: x64
InstallerUrl: $url
InstallerSha256: $sha256
PortableCommandAlias: windowsbootstrapper
ManifestType: installer
ManifestVersion: 1.6.0
"@ | Out-File "$manifestRoot/$packageId.installer.yaml" -Encoding UTF8
# --- Locale Manifest ---
@"
PackageIdentifier: $packageId
PackageVersion: $version
PackageLocale: de-DE
Publisher: Saigkill
PackageName: Windows Bootstrapper
ShortDescription: Automatischer Windows-Bootstrapper für Systemkonfiguration und Softwareinstallation.
ManifestType: locale
ManifestVersion: 1.6.0
"@ | Out-File "$manifestRoot/$packageId.locale.de-DE.yaml" -Encoding UTF8
# --- Locale Manifest ---
@"
PackageIdentifier: $packageId
PackageVersion: $version
PackageLocale: en-US
Publisher: Saigkill
PackageName: Windows Bootstrapper
ShortDescription: Automatic Windows bootstrapper for system configuration and software installation.
ManifestType: defaultLocale
ManifestVersion: 1.6.0
"@ | Out-File "$manifestRoot/$packageId.locale.en-US.yaml" -Encoding UTF8
- task: PublishPipelineArtifact@1
displayName: "Publish Winget Manifests"
inputs:
targetPath: "$(Build.SourcesDirectory)/winget"
artifact: "winget-manifests"
- stage: WingetPR
displayName: "Create Winget Pull Request"
dependsOn: Winget
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
jobs:
- job: WingetPRJob
displayName: "Generate PR for microsoft/winget-pkgs"
pool:
vmImage: 'windows-latest'
steps:
- checkout: none
- task: PowerShell@2
displayName: "Clone winget-pkgs fork"
inputs:
targetType: inline
pwsh: true
script: |
git clone https://$(GithubPAT)@github.com/saigkill/winget-pkgs.git winget-pkgs
cd winget-pkgs
git remote add upstream https://github.com/microsoft/winget-pkgs.git
git fetch upstream
git merge upstream/master
- download: current
artifact: winget-manifests
- task: PowerShell@2
displayName: "Copy manifests to correct folder"
inputs:
targetType: inline
pwsh: true
script: |
$packageId = "Saigkill.WindowsBootstrapper"
$version = "$(Build.SourceBranchName)".TrimStart("v")
$folder = "winget-pkgs/manifests/s/Saigkill/WindowsBootstrapper/$version"
New-Item -ItemType Directory -Force -Path $folder | Out-Null
Copy-Item "$(Pipeline.Workspace)/winget-manifests/*" $folder -Recurse -Force
- task: PowerShell@2
displayName: "Commit and push changes"
inputs:
targetType: inline
pwsh: true
script: |
cd winget-pkgs
git config user.email "Sascha.Manns@outlook.de"
git config user.name "Saigkill CI Bot"
git add .
git commit -m "Add WindowsBootstrapper $version"
git push origin master
- task: PowerShell@2
displayName: "Create Pull Request"
inputs:
targetType: inline
pwsh: true
script: |
$version = "$(Build.SourceBranchName)".TrimStart("v")
$body = "Automated submission of WindowsBootstrapper $version via Azure DevOps."
gh pr create `
--repo saigkill/winget-pkgs `
--base master `
--head master `
--title "WindowsBootstrapper $version" `
--body $body `
--reviewer "microsoft/winget-pkgs"
# Neuer Deployment Job für Azure DevOps
- deployment: DeployToAzureDevOps
displayName: 'Deploy Release to Azure DevOps'
environment: 'Production'
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: windows-bootstrap
- task: PowerShell@2
displayName: 'Deploy to Environment'
inputs:
targetType: 'inline'
pwsh: true
script: |
Write-Host "Deploying WindowsBootstrapper to Production"
# Weitere Deployment-Schritte hier