1+ name : Publish to PowerShell Gallery
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*' # e.g., v1.0.1, v1.0.2, etc.
7+
8+ jobs :
9+ publish :
10+ runs-on : windows-latest
11+
12+ env :
13+ PSGALLERY_API_KEY : ${{ secrets.PSGALLERY_API_KEY }}
14+
15+ steps :
16+ - name : Checkout repository
17+ uses : actions/checkout@v4
18+
19+ - name : Install NuGet provider and PowerShellGet
20+ shell : pwsh
21+ run : |
22+ $ErrorActionPreference = 'Stop'
23+
24+ Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
25+
26+ Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
27+ Install-Module PowerShellGet -Force -Scope CurrentUser -AllowClobber
28+
29+ - name : Validate manifest version matches tag and publish module
30+ shell : pwsh
31+ run : |
32+ $ErrorActionPreference = 'Stop'
33+
34+ if (-not $env:PSGALLERY_API_KEY) {
35+ throw 'PSGALLERY_API_KEY secret is not configured in repository secrets.'
36+ }
37+
38+ # Manifest is in /module
39+ $manifest = Join-Path $PSScriptRoot 'module/OffsetInspect.psd1'
40+
41+ if (-not (Test-Path $manifest)) {
42+ throw "Manifest not found at expected path: $manifest"
43+ }
44+
45+ Write-Host "Using manifest: $manifest"
46+
47+ $moduleInfo = Test-ModuleManifest -Path $manifest
48+
49+ # Tag name is something like "v1.0.2"
50+ $tag = '${{ github.ref_name }}'
51+ Write-Host "Git tag: $tag"
52+
53+ if ($tag -notmatch '^v(?<ver>.+)$') {
54+ throw "Tag '$tag' is not in expected 'vX.Y.Z' format."
55+ }
56+
57+ $tagVersion = $Matches['ver']
58+
59+ Write-Host "Tag version: $tagVersion"
60+ Write-Host "Manifest version: $($moduleInfo.Version)"
61+
62+ if ($moduleInfo.Version.ToString() -ne $tagVersion) {
63+ throw "Manifest version '$($moduleInfo.Version)' does not match tag version '$tagVersion'."
64+ }
65+
66+ # Publish the module folder to PSGallery
67+ Publish-Module `
68+ -Path 'module' `
69+ -Repository 'PSGallery' `
70+ -NuGetApiKey $env:PSGALLERY_API_KEY `
71+ -Verbose
0 commit comments