-
Notifications
You must be signed in to change notification settings - Fork 0
240 lines (212 loc) · 8.5 KB
/
Copy pathbuild.yml
File metadata and controls
240 lines (212 loc) · 8.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
name: Build & Test
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test-pwsh:
name: Test (pwsh / ${{ matrix.os }})
runs-on: ${{ matrix.os }}
defaults:
run:
shell: pwsh
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache PowerShell modules
uses: actions/cache@v4
id: ps-cache
with:
path: |
~/.local/share/powershell/Modules
~/Documents/PowerShell/Modules
key: ps-modules-${{ matrix.os }}-pwsh-pester5-pssa
- name: Install Pester
if: steps.ps-cache.outputs.cache-hit != 'true'
run: |
Install-Module -Name Pester -MinimumVersion 5.0 -Force -Scope CurrentUser -SkipPublisherCheck
- name: Install PSScriptAnalyzer
if: steps.ps-cache.outputs.cache-hit != 'true'
run: |
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser -SkipPublisherCheck
- name: Run PSScriptAnalyzer
run: |
$Results = Invoke-ScriptAnalyzer -Path './YFridelance.PS.ModuleFactory' -Recurse -Settings './PSScriptAnalyzerSettings.psd1' -ReportSummary
if ($Results) {
$Results | Format-Table -AutoSize
throw "PSScriptAnalyzer found $($Results.Count) issue(s)."
}
Write-Host "PSScriptAnalyzer: No issues found." -ForegroundColor Green
- name: Run Pester tests
run: |
$PesterConfig = New-PesterConfiguration
$PesterConfig.Run.Path = './Tests'
$PesterConfig.Run.Exit = $true
$PesterConfig.Output.Verbosity = 'Detailed'
$PesterConfig.TestResult.Enabled = $true
$PesterConfig.TestResult.OutputPath = './TestResults.xml'
$PesterConfig.TestResult.OutputFormat = 'NUnitXml'
Invoke-Pester -Configuration $PesterConfig
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.os }}-pwsh
path: ./TestResults.xml
test-ps51:
name: Test (PowerShell 5.1 / windows-latest)
runs-on: windows-latest
defaults:
run:
shell: powershell
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache PowerShell modules
uses: actions/cache@v4
id: ps-cache
with:
path: |
~/Documents/WindowsPowerShell/Modules
key: ps-modules-windows-latest-ps51-pester5-pssa
- name: Install Pester
if: steps.ps-cache.outputs.cache-hit != 'true'
run: |
Install-Module -Name Pester -MinimumVersion 5.0 -Force -Scope CurrentUser -SkipPublisherCheck
- name: Install PSScriptAnalyzer
if: steps.ps-cache.outputs.cache-hit != 'true'
run: |
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser -SkipPublisherCheck
- name: Run PSScriptAnalyzer
run: |
$Results = Invoke-ScriptAnalyzer -Path './YFridelance.PS.ModuleFactory' -Recurse -Settings './PSScriptAnalyzerSettings.psd1' -ReportSummary
if ($Results) {
$Results | Format-Table -AutoSize
throw "PSScriptAnalyzer found $($Results.Count) issue(s)."
}
Write-Host "PSScriptAnalyzer: No issues found." -ForegroundColor Green
- name: Run Pester tests
run: |
$PesterConfig = New-PesterConfiguration
$PesterConfig.Run.Path = './Tests'
$PesterConfig.Run.Exit = $true
$PesterConfig.Output.Verbosity = 'Detailed'
$PesterConfig.TestResult.Enabled = $true
$PesterConfig.TestResult.OutputPath = './TestResults.xml'
$PesterConfig.TestResult.OutputFormat = 'NUnitXml'
Invoke-Pester -Configuration $PesterConfig
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-windows-latest-ps51
path: ./TestResults.xml
build-and-publish:
name: Build & Publish
needs: [test-pwsh, test-ps51]
runs-on: ubuntu-latest
if: github.event_name == 'push'
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache PowerShell modules
uses: actions/cache@v4
id: ps-cache
with:
path: |
~/.local/share/powershell/Modules
key: ps-modules-ubuntu-latest-pwsh-pester5
- name: Install Pester
if: steps.ps-cache.outputs.cache-hit != 'true'
shell: pwsh
run: |
Install-Module -Name Pester -MinimumVersion 5.0 -Force -Scope CurrentUser -SkipPublisherCheck
- name: Build module
shell: pwsh
run: ./build.ps1 -Clean
- name: Set prerelease tag
if: github.ref == 'refs/heads/develop'
shell: pwsh
run: |
. ./YFridelance.PS.ModuleFactory/Private/Update-ManifestField.ps1
$Script:DefaultEncoding = [System.Text.UTF8Encoding]::new($true)
$ManifestPath = './dist/YFridelance.PS.ModuleFactory/YFridelance.PS.ModuleFactory.psd1'
$PrereleaseTag = "preview$($env:GITHUB_RUN_NUMBER)"
Update-ManifestField -ManifestPath $ManifestPath -FieldName 'Prerelease' -Value $PrereleaseTag
Write-Host "Prerelease tag set: $PrereleaseTag" -ForegroundColor Green
- name: Ensure no prerelease tag
if: github.ref == 'refs/heads/main'
shell: pwsh
run: |
. ./YFridelance.PS.ModuleFactory/Private/Update-ManifestField.ps1
$Script:DefaultEncoding = [System.Text.UTF8Encoding]::new($true)
$ManifestPath = './dist/YFridelance.PS.ModuleFactory/YFridelance.PS.ModuleFactory.psd1'
Update-ManifestField -ManifestPath $ManifestPath -FieldName 'Prerelease' -Value ''
Write-Host "Prerelease tag cleared for stable release." -ForegroundColor Green
- name: Verify build output
shell: pwsh
run: |
$ManifestPath = './dist/YFridelance.PS.ModuleFactory/YFridelance.PS.ModuleFactory.psd1'
if (-not (Test-Path $ManifestPath)) {
throw "Build output not found: $ManifestPath"
}
$Manifest = Test-ModuleManifest -Path $ManifestPath
$Prerelease = $Manifest.PrivateData.PSData.Prerelease
Write-Host "Module: $($Manifest.Name)"
Write-Host "Version: $($Manifest.Version)"
if ($Prerelease) { Write-Host "Prerelease: $Prerelease" }
Write-Host "Functions: $($Manifest.ExportedFunctions.Keys -join ', ')"
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: YFridelance.PS.ModuleFactory
path: ./dist/YFridelance.PS.ModuleFactory/
- name: Publish to PowerShell Gallery
shell: pwsh
env:
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
DOTNET_CLI_UI_LANGUAGE: en
run: |
$ModulePath = './dist/YFridelance.PS.ModuleFactory'
if (-not (Test-Path $ModulePath)) {
throw "Build output not found: $ModulePath"
}
try {
Publish-Module -Path $ModulePath -NuGetApiKey $env:PSGALLERY_API_KEY -Repository PSGallery -ErrorAction Stop
Write-Host "Published successfully to PSGallery." -ForegroundColor Green
}
catch {
if ($_.Exception.Message -match '409|already exists|duplicate|version must exceed') {
Write-Warning "Module version already exists on PSGallery. Skipping publish."
}
else {
throw
}
}
- name: Create git version tag
shell: pwsh
run: |
$ManifestPath = './dist/YFridelance.PS.ModuleFactory/YFridelance.PS.ModuleFactory.psd1'
$Manifest = Test-ModuleManifest -Path $ManifestPath
$Version = $Manifest.Version.ToString()
$Prerelease = $Manifest.PrivateData.PSData.Prerelease
if ($Prerelease) {
$Tag = "v$Version-$Prerelease"
}
else {
$Tag = "v$Version"
}
Write-Host "Creating tag: $Tag" -ForegroundColor Green
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a $Tag -m "Release $Tag"
git push origin $Tag