Repository navigation
375 lines (309 loc) · 14.1 KB
/
Copy pathrelease.yml
File metadata and controls
375 lines (309 loc) · 14.1 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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Artifact tag name (e.g. v0.7.0-test). This does NOT need to exist as a git tag.'
required: false
type: string
publish_release:
description: 'If true, create a GitHub Release and upload the ZIP as a release asset.'
required: false
default: false
type: boolean
publish_psgallery:
description: 'If true, publish the module to PowerShell Gallery (requires explicit intent).'
required: false
default: false
type: boolean
permissions:
contents: write
actions: read
jobs:
release:
name: Build artifact (and optionally publish release)
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.value }}
is_prerelease: ${{ steps.semver.outputs.is_prerelease }}
is_stable: ${{ steps.semver.outputs.is_stable }}
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Show PowerShell version
shell: pwsh
run: |
$PSVersionTable.PSVersion
pwsh -v
- name: Determine artifact tag
id: tag
shell: pwsh
run: |
$inputTag = '${{ inputs.tag }}'
if (-not [string]::IsNullOrWhiteSpace($inputTag)) {
"value=$inputTag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
exit 0
}
$refName = '${{ github.ref_name }}'
if ([string]::IsNullOrWhiteSpace($refName)) {
throw "github.ref_name is empty. Provide inputs.tag when using workflow_dispatch."
}
"value=$refName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
- name: Classify tag (stable vs prerelease)
id: semver
shell: pwsh
run: |
$tag = '${{ steps.tag.outputs.value }}'
$isStable = $tag -match '^v\d+\.\d+\.\d+$'
$isPrerelease = $tag -match '^v\d+\.\d+\.\d+-[0-9A-Za-z][0-9A-Za-z\.\-]*$'
"is_stable=$($isStable.ToString().ToLowerInvariant())" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
"is_prerelease=$($isPrerelease.ToString().ToLowerInvariant())" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
- name: Require tag to point to main HEAD
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: pwsh
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
git fetch origin main --depth 1 | Out-Null
$tagSha = (git rev-parse '${{ github.ref }}^{}').Trim()
$mainSha = (git rev-parse 'origin/main').Trim()
if ($tagSha -ne $mainSha) {
throw "Tag does not point to origin/main HEAD. Tag SHA=$tagSha, main SHA=$mainSha"
}
Write-Host "Tag points to origin/main HEAD ($mainSha)."
- name: Require green CI on the target commit
if: ${{ inputs.publish_release == true || inputs.publish_psgallery == true || startsWith(github.ref, 'refs/tags/v') }}
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$repo = '${{ github.repository }}'
$sha = '${{ github.sha }}'
# NOTE: This must match the workflow filename for CI.
# In this repository it is: .github/workflows/ci.yml
$uri = "https://api.github.com/repos/$repo/actions/workflows/ci.yml/runs?per_page=100&head_sha=$sha"
$headers = @{
Authorization = "Bearer $env:GH_TOKEN"
Accept = "application/vnd.github+json"
"X-GitHub-Api-Version" = "2022-11-28"
}
$resp = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers
$run = $resp.workflow_runs | Sort-Object run_number -Descending | Select-Object -First 1
if (-not $run) {
throw "No completed CI workflow run found for SHA $sha. If CI is currently running for this commit, wait for it to complete successfully on main before releasing."
}
if ($run.status -ne 'completed' -or $run.conclusion -ne 'success') {
throw "CI is not green for SHA $sha. Status=$($run.status), Conclusion=$($run.conclusion)."
}
Write-Host "CI is green for SHA $sha (run #$($run.run_number))."
- name: Validate tag version matches module manifest version(s)
shell: pwsh
run: |
$tag = '${{ steps.tag.outputs.value }}'
if ($tag -notmatch '^v(\d+\.\d+\.\d+)(?:-[0-9A-Za-z][0-9A-Za-z\.\-]*)?$') {
Write-Host "Tag '$tag' is not SemVer-like. Skipping module version validation."
exit 0
}
$expectedVersion = $Matches[1]
Write-Host "Expected module version from tag: $expectedVersion"
$manifestPaths = @(
'src/IdLE/IdLE.psd1',
'src/IdLE.Core/IdLE.Core.psd1',
'src/IdLE.Steps.Common/IdLE.Steps.Common.psd1',
'src/IdLE.Steps.DirectorySync/IdLE.Steps.DirectorySync.psd1',
'src/IdLE.Steps.Mailbox/IdLE.Steps.Mailbox.psd1',
'src/IdLE.Provider.AD/IdLE.Provider.AD.psd1',
'src/IdLE.Provider.EntraID/IdLE.Provider.EntraID.psd1',
'src/IdLE.Provider.ExchangeOnline/IdLE.Provider.ExchangeOnline.psd1',
'src/IdLE.Provider.DirectorySync.EntraConnect/IdLE.Provider.DirectorySync.EntraConnect.psd1',
'src/IdLE.Provider.Mock/IdLE.Provider.Mock.psd1'
)
$mismatches = @()
foreach ($path in $manifestPaths) {
if (-not (Test-Path -LiteralPath $path)) {
throw "Module manifest not found: $path"
}
$data = Import-PowerShellDataFile -LiteralPath $path
$actualVersion = [string]$data.ModuleVersion
if ($actualVersion -ne $expectedVersion) {
$mismatches += [pscustomobject]@{
Path = $path
Expected = $expectedVersion
ModuleVersion = $actualVersion
}
}
}
if ($mismatches.Count -gt 0) {
$mismatches | Format-Table -AutoSize | Out-String | Write-Host
throw "Tag '$tag' does not match module manifest version(s). Run the version bump before tagging."
}
Write-Host "Manifest versions match tag version ($expectedVersion)."
- name: Build release artifact
shell: pwsh
run: |
$tag = '${{ steps.tag.outputs.value }}'
./tools/New-IdleReleaseArtifact.ps1 -Tag $tag
- name: Verify artifact exists
shell: pwsh
run: |
$tag = '${{ steps.tag.outputs.value }}'
$path = "artifacts/IdLE-$tag.zip"
if (-not (Test-Path -LiteralPath $path)) {
throw "Expected artifact not found: $path"
}
Get-Item -LiteralPath $path | Format-List FullName, Length, LastWriteTimeUtc
- name: Expand artifact for dry-run upload
if: ${{ inputs.publish_release != true && !startsWith(github.ref, 'refs/tags/v') }}
shell: pwsh
run: |
$tag = '${{ steps.tag.outputs.value }}'
$zipPath = "artifacts/IdLE-$tag.zip"
$staging = "artifacts/staging-$tag"
if (Test-Path -LiteralPath $staging) {
Remove-Item -LiteralPath $staging -Recurse -Force
}
New-Item -ItemType Directory -Path $staging -Force | Out-Null
Expand-Archive -Path $zipPath -DestinationPath $staging -Force
Get-ChildItem -LiteralPath $staging -Recurse | Select-Object FullName | Format-List
- name: Upload workflow artifact (expanded folder)
if: ${{ inputs.publish_release != true && !startsWith(github.ref, 'refs/tags/v') }}
uses: actions/upload-artifact@v7
with:
name: IdLE-${{ steps.tag.outputs.value }}-expanded
path: artifacts/staging-${{ steps.tag.outputs.value }}
if-no-files-found: error
- name: Upload workflow artifact (zip)
if: ${{ inputs.publish_release == true || startsWith(github.ref, 'refs/tags/v') }}
uses: actions/upload-artifact@v7
with:
name: IdLE-${{ steps.tag.outputs.value }}-zip
path: artifacts/IdLE-${{ steps.tag.outputs.value }}.zip
if-no-files-found: error
- name: Create GitHub Release (optional)
if: ${{ inputs.publish_release == true || startsWith(github.ref, 'refs/tags/v') }}
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.tag.outputs.value }}
name: ${{ steps.tag.outputs.value }}
generate_release_notes: true
prerelease: ${{ steps.semver.outputs.is_prerelease == 'true' }}
files: |
artifacts/IdLE-${{ steps.tag.outputs.value }}.zip
psgallery_local_test:
name: Test module publish (local repository)
runs-on: ubuntu-latest
needs: release
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Show PowerShell version
shell: pwsh
run: |
$PSVersionTable.PSVersion
pwsh -v
- name: Install PowerShellGet
shell: pwsh
run: |
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Module -Name PowerShellGet -Scope CurrentUser -Force -AllowClobber
Import-Module PowerShellGet -Force
Get-Module PowerShellGet | Select-Object Name, Version, Path | Format-List
- name: Build publishable module package (bundled IdLE)
shell: pwsh
run: |
./tools/New-IdleModulePackage.ps1 -Clean | Format-List FullName
- name: Publish bundle to local PSRepository and verify install/import
shell: pwsh
run: |
$packagePath = Join-Path $env:GITHUB_WORKSPACE 'artifacts/IdLE'
if (-not (Test-Path -LiteralPath $packagePath)) {
throw "Staged package path not found: $packagePath"
}
$repoPath = Join-Path $env:RUNNER_TEMP 'psrepo'
New-Item -ItemType Directory -Path $repoPath -Force | Out-Null
Register-PSRepository -Name 'LocalRepo' -SourceLocation $repoPath -PublishLocation $repoPath -InstallationPolicy Trusted
Write-Host "Publishing IdLE..."
Publish-Module -Path $packagePath -Repository 'LocalRepo' -ErrorAction Stop
Write-Host " ✓ Published IdLE"
# Test that IdLE can be installed and imports correctly
Write-Host "`nInstalling IdLE from LocalRepo..."
Install-Module -Name 'IdLE' -Repository 'LocalRepo' -Scope CurrentUser -Force -AllowClobber -ErrorAction Stop
Import-Module IdLE -Force -ErrorAction Stop
$m = Get-Module IdLE
if (-not $m) { throw 'IdLE did not import successfully.' }
Write-Host "Imported IdLE: $($m.Name) $($m.Version) from $($m.ModuleBase)"
# Verify all bundled modules were loaded from the installed package
$expected = @((Import-PowerShellDataFile -LiteralPath (Join-Path $m.ModuleBase 'IdLE.psd1')).NestedModules |
ForEach-Object { [System.IO.Path]::GetFileNameWithoutExtension(($_ -replace '\\', '/')) })
foreach ($name in $expected) {
$nested = Get-Module -All -Name $name | Select-Object -First 1
if (-not $nested) { throw "$name was not loaded as nested module." }
if (-not $nested.ModuleBase.StartsWith($m.ModuleBase)) { throw "$name was loaded from '$($nested.ModuleBase)', not from the bundle." }
Write-Host " ✓ $name $($nested.Version)"
}
$factory = Get-Command -Module IdLE -Name 'New-IdleMockIdentityProvider' -ErrorAction SilentlyContinue
if (-not $factory) { throw 'IdLE does not export the provider factory functions.' }
Unregister-PSRepository -Name 'LocalRepo' -ErrorAction SilentlyContinue
psgallery:
name: Publish to PowerShell Gallery
runs-on: ubuntu-latest
needs: [release, psgallery_local_test]
environment: psgallery-prod
if: >-
${{
needs.release.outputs.is_stable == 'true'
&& (
startsWith(github.ref, 'refs/tags/v')
|| (github.event_name == 'workflow_dispatch' && inputs.publish_psgallery == true && inputs.tag != '')
)
}}
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Show PowerShell version
shell: pwsh
run: |
$PSVersionTable.PSVersion
pwsh -v
- name: Install PowerShellGet
shell: pwsh
run: |
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Module -Name PowerShellGet -Scope CurrentUser -Force -AllowClobber
Import-Module PowerShellGet -Force
Get-Module PowerShellGet | Select-Object Name, Version, Path | Format-List
- name: Build publishable module package (bundled IdLE)
shell: pwsh
run: |
./tools/New-IdleModulePackage.ps1 -Clean | Format-List FullName
- name: Publish IdLE to PSGallery
shell: pwsh
env:
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
run: |
if ([string]::IsNullOrWhiteSpace($env:PSGALLERY_API_KEY)) {
throw "Missing secret PSGALLERY_API_KEY."
}
$packagePath = Join-Path $env:GITHUB_WORKSPACE 'artifacts/IdLE'
$manifest = Join-Path $packagePath 'IdLE.psd1'
if (-not (Test-Path -LiteralPath $manifest)) {
throw "Staged package manifest not found: $manifest"
}
$data = Import-PowerShellDataFile -LiteralPath $manifest
Write-Host "Publishing: IdLE Version: $($data.ModuleVersion)"
Publish-Module -Path $packagePath -NuGetApiKey $env:PSGALLERY_API_KEY -Repository PSGallery -ErrorAction Stop
Write-Host " ✓ Successfully published IdLE"