fix: update module version to 4.0.0.9 and ensure code signing action … #81
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: publish to powershell gallery | |
on: | |
push: | |
branches: [master] | |
paths: | |
- "**.psd1" | |
workflow_dispatch: | |
jobs: | |
publishmodule: | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dlemstra/code-sign-action@v1 | |
with: | |
certificate: ${{ secrets.CERTIFICATE }} | |
password: ${{ secrets.CERTIFICATE_PASSWORD }} | |
folder: . | |
recursive: true | |
files: | | |
*.ps1 | |
*.psm1 | |
- name: Validate and publish module | |
shell: pwsh | |
run: | | |
# Module path and name | |
$ModulePath = ".\code365scripts.openai" | |
$ModuleName = "code365scripts.openai" | |
Write-Host "🚀 Starting PowerShell module publishing: $ModuleName" -ForegroundColor Green | |
# 1. Install PowerShellGet and configure repository first | |
Write-Host "� Installing PowerShellGet and configuring repository..." -ForegroundColor Yellow | |
if (-not (Get-Module -ListAvailable -Name PowerShellGet)) { | |
Install-Module -Name PowerShellGet -Force -AllowClobber -Scope CurrentUser | |
} | |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted | |
# 2. Install required modules BEFORE validating manifest | |
Write-Host "📦 Installing required modules..." -ForegroundColor Yellow | |
$data = Import-PowerShellDataFile "$ModulePath\$ModuleName.psd1" | |
if($data.RequiredModules) { | |
$data.RequiredModules | Foreach-Object { | |
Write-Host " Installing: $($_.ModuleName) version $($_.ModuleVersion)" -ForegroundColor Cyan | |
try { | |
Install-Module -Name $_.ModuleName -RequiredVersion $_.ModuleVersion -Scope CurrentUser -Force -AllowClobber | |
Write-Host " ✅ Successfully installed: $($_.ModuleName)" -ForegroundColor Green | |
} | |
catch { | |
Write-Warning " ⚠️ Failed to install $($_.ModuleName): $_" | |
Write-Host " Attempting to install latest version..." -ForegroundColor Yellow | |
try { | |
Install-Module -Name $_.ModuleName -Scope CurrentUser -Force -AllowClobber | |
Write-Host " ✅ Successfully installed latest version of: $($_.ModuleName)" -ForegroundColor Green | |
} | |
catch { | |
Write-Warning " ⚠️ Could not install $($_.ModuleName), continuing anyway..." | |
} | |
} | |
} | |
} | |
# 3. Now validate module manifest | |
Write-Host "� Validating module manifest..." -ForegroundColor Yellow | |
try { | |
$manifest = Test-ModuleManifest -Path "$ModulePath\$ModuleName.psd1" | |
Write-Host "✅ Module manifest validation successful" -ForegroundColor Green | |
Write-Host " Module version: $($manifest.Version)" -ForegroundColor Cyan | |
Write-Host " Exported functions: $($manifest.ExportedFunctions.Keys -join ', ')" -ForegroundColor Cyan | |
} | |
catch { | |
Write-Warning "⚠️ Module manifest validation failed: $_" | |
Write-Host "� Attempting to validate without strict dependency checking..." -ForegroundColor Yellow | |
try { | |
# Try importing the PowerShellDataFile directly for basic validation | |
$manifestData = Import-PowerShellDataFile "$ModulePath\$ModuleName.psd1" | |
Write-Host "✅ Basic manifest parsing successful" -ForegroundColor Green | |
Write-Host " Module version: $($manifestData.ModuleVersion)" -ForegroundColor Cyan | |
} | |
catch { | |
Write-Error "❌ Critical manifest error: $_" | |
exit 1 | |
} | |
} | |
# 4. Check if module already exists and version comparison | |
Write-Host "🔍 Checking if module exists in PowerShell Gallery..." -ForegroundColor Yellow | |
try { | |
$existingModule = Find-Module -Name $ModuleName -ErrorAction Stop | |
Write-Host "📦 Found existing module version: $($existingModule.Version)" -ForegroundColor Cyan | |
# Get version from manifest data we already loaded | |
$currentVersion = if ($manifest) { $manifest.Version } else { $manifestData.ModuleVersion } | |
if ([version]$currentVersion -le [version]$existingModule.Version) { | |
Write-Error "⚠️ Current module version ($currentVersion) is not higher than published version ($($existingModule.Version))" | |
exit 1 | |
} | |
Write-Host "✅ Version check passed: $currentVersion > $($existingModule.Version)" -ForegroundColor Green | |
} | |
catch { | |
Write-Host "📦 This is a new module, proceeding with first-time publishing" -ForegroundColor Green | |
} | |
# 5. Clean up unnecessary files for publishing | |
Write-Host "🧹 Cleaning up unnecessary files..." -ForegroundColor Yellow | |
if (Test-Path ".git") { Remove-Item -Path ".git" -Recurse -Force } | |
if (Test-Path ".github") { Remove-Item -Path ".github" -Recurse -Force } | |
if (Test-Path ".vscode") { Remove-Item -Path ".vscode" -Recurse -Force } | |
# 6. Publish module | |
Write-Host "🚀 Publishing module to PowerShell Gallery..." -ForegroundColor Yellow | |
try { | |
Publish-Module -Path $ModulePath -NuGetApiKey "${{ secrets.NUGETKEY }}" -Verbose -Force | |
Write-Host "🎉 Module published successfully!" -ForegroundColor Green | |
Write-Host "📦 Module link: https://www.powershellgallery.com/packages/$ModuleName" -ForegroundColor Cyan | |
} | |
catch { | |
Write-Error "❌ Module publishing failed: $_" | |
Write-Host "📋 Attempting to publish with SkipAutomaticTags..." -ForegroundColor Yellow | |
try { | |
Publish-Module -Path $ModulePath -NuGetApiKey "${{ secrets.NUGETKEY }}" -Verbose -Force -SkipAutomaticTags | |
Write-Host "🎉 Module published successfully (with SkipAutomaticTags)!" -ForegroundColor Green | |
Write-Host "📦 Module link: https://www.powershellgallery.com/packages/$ModuleName" -ForegroundColor Cyan | |
} | |
catch { | |
Write-Error "❌ Final publishing attempt failed: $_" | |
exit 1 | |
} | |
} | |
Write-Host "✅ Publishing process completed!" -ForegroundColor Green |