@@ -3,15 +3,23 @@ name: Manual Publish to PowerShell Gallery
33on :
44 workflow_dispatch :
55 inputs :
6- confirm_publish :
7- description : ' Type "PUBLISH" to confirm you want to publish to PowerShell Gallery '
6+ mode :
7+ description : ' Select mode '
88 required : true
9+ type : choice
10+ options :
11+ - ' DRY_RUN'
12+ - ' PUBLISH'
13+ default : ' DRY_RUN'
14+ confirm_publish :
15+ description : ' If PUBLISH mode: Type "CONFIRM" to proceed'
16+ required : false
917 type : string
1018
1119jobs :
1220 publish :
1321 runs-on : windows-latest
14- if : github.event.inputs.confirm_publish == 'PUBLISH'
22+ if : github.event.inputs.mode == 'DRY_RUN' || (github.event.inputs.mode == ' PUBLISH' && github.event.inputs.confirm_publish == 'CONFIRM')
1523
1624 steps :
1725 - name : Checkout code
@@ -98,9 +106,15 @@ jobs:
98106 env :
99107 NUGET_API_KEY : ${{ secrets.POWERSHELLGALLERY_API }}
100108 run : |
101- # Validate that we have the API key
102- if (-not $env:NUGET_API_KEY) {
103- throw "POWERSHELLGALLERY_API secret is not set"
109+ $isDryRun = "${{ github.event.inputs.mode }}" -eq "DRY_RUN"
110+
111+ if ($isDryRun) {
112+ Write-Host "🧪 DRY RUN MODE - No actual publishing will occur"
113+ } else {
114+ # Validate that we have the API key
115+ if (-not $env:NUGET_API_KEY) {
116+ throw "POWERSHELLGALLERY_API secret is not set"
117+ }
104118 }
105119
106120 Write-Host "Publishing PSBlogger version ${{ steps.version.outputs.version }} to PowerShell Gallery..."
@@ -109,7 +123,11 @@ jobs:
109123 try {
110124 $existingModule = Find-Module -Name PSBlogger -RequiredVersion ${{ steps.version.outputs.version }} -ErrorAction SilentlyContinue
111125 if ($existingModule) {
112- throw "Version ${{ steps.version.outputs.version }} already exists on PowerShell Gallery"
126+ if ($isDryRun) {
127+ Write-Host "⚠️ DRY RUN: Version ${{ steps.version.outputs.version }} already exists on PowerShell Gallery"
128+ } else {
129+ throw "Version ${{ steps.version.outputs.version }} already exists on PowerShell Gallery"
130+ }
113131 }
114132 } catch {
115133 if ($_.Exception.Message -notlike "*Version*already exists*") {
@@ -119,10 +137,15 @@ jobs:
119137 }
120138 }
121139
122- # Actually publish the module (no -WhatIf here)
140+ # Publish the module
123141 try {
124- Publish-Module -Path "./src" -NuGetApiKey $env:NUGET_API_KEY -Verbose -Force
125- Write-Host "✅ Successfully published to PowerShell Gallery"
142+ if ($isDryRun) {
143+ Publish-Module -Path "./src" -WhatIf -Verbose
144+ Write-Host "🧪 DRY RUN: Would publish to PowerShell Gallery (no actual publishing)"
145+ } else {
146+ Publish-Module -Path "./src" -NuGetApiKey $env:NUGET_API_KEY -Verbose -Force
147+ Write-Host "✅ Successfully published to PowerShell Gallery"
148+ }
126149 } catch {
127150 Write-Error "❌ Failed to publish to PowerShell Gallery: $_"
128151 throw
@@ -131,6 +154,13 @@ jobs:
131154 - name : Create Git Tag and Release
132155 shell : pwsh
133156 run : |
157+ $isDryRun = "${{ github.event.inputs.mode }}" -eq "DRY_RUN"
158+
159+ if ($isDryRun) {
160+ Write-Host "🧪 DRY RUN: Would create tag v${{ steps.version.outputs.version }} and GitHub release"
161+ return
162+ }
163+
134164 # Configure git
135165 git config user.name "github-actions"
136166 git config user.email "github-actions@github.com"
@@ -176,6 +206,7 @@ jobs:
176206 echo "release-notes=$releaseNotes" >> $env:GITHUB_OUTPUT
177207
178208 - name : Create GitHub Release
209+ if : github.event.inputs.mode == 'PUBLISH'
179210 uses : actions/create-release@v1
180211 env :
181212 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -190,6 +221,18 @@ jobs:
190221 if : success()
191222 shell : pwsh
192223 run : |
193- Write-Host "🎉 Successfully published PSBlogger v${{ steps.version.outputs.version }} to PowerShell Gallery!"
194- Write-Host "📦 Module is now available at: https://www.powershellgallery.com/packages/PSBlogger/${{ steps.version.outputs.version }}"
195- Write-Host "🏷️ Created release: https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version.outputs.version }}"
224+ $isDryRun = "${{ github.event.inputs.mode }}" -eq "DRY_RUN"
225+
226+ if ($isDryRun) {
227+ Write-Host "🧪 DRY RUN COMPLETED SUCCESSFULLY!"
228+ Write-Host "✅ Module manifest validation passed"
229+ Write-Host "✅ All tests passed"
230+ Write-Host "✅ Module can be imported successfully"
231+ Write-Host ""
232+ Write-Host "Ready to publish PSBlogger v${{ steps.version.outputs.version }} to PowerShell Gallery"
233+ Write-Host "To actually publish, run this workflow again with PUBLISH mode and type CONFIRM"
234+ } else {
235+ Write-Host "🎉 Successfully published PSBlogger v${{ steps.version.outputs.version }} to PowerShell Gallery!"
236+ Write-Host "📦 Module is now available at: https://www.powershellgallery.com/packages/PSBlogger/${{ steps.version.outputs.version }}"
237+ Write-Host "🏷️ Created release: https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version.outputs.version }}"
238+ }
0 commit comments