|
9 | 9 |
|
10 | 10 | jobs: |
11 | 11 | publishmodule: |
12 | | - runs-on: ubuntu-latest |
| 12 | + runs-on: windows-latest |
13 | 13 | steps: |
14 | 14 | - uses: actions/checkout@v4 |
15 | | - - name: prepare and publish module |
| 15 | + - name: Validate and publish module |
16 | 16 | shell: pwsh |
17 | 17 | run: | |
18 | | - Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted |
19 | | - $data = Import-PowerShellDataFile .\code365scripts.openai\code365scripts.openai.psd1 |
| 18 | + # Module path and name |
| 19 | + $ModulePath = ".\code365scripts.openai" |
| 20 | + $ModuleName = "code365scripts.openai" |
| 21 | + |
| 22 | + Write-Host "🚀 Starting PowerShell module publishing: $ModuleName" -ForegroundColor Green |
| 23 | + |
| 24 | + # 1. Validate module manifest |
| 25 | + Write-Host "📋 Validating module manifest..." -ForegroundColor Yellow |
| 26 | + try { |
| 27 | + $manifest = Test-ModuleManifest -Path "$ModulePath\$ModuleName.psd1" |
| 28 | + Write-Host "✅ Module manifest validation successful" -ForegroundColor Green |
| 29 | + Write-Host " Module version: $($manifest.Version)" -ForegroundColor Cyan |
| 30 | + Write-Host " Exported functions: $($manifest.ExportedFunctions.Keys -join ', ')" -ForegroundColor Cyan |
| 31 | + } |
| 32 | + catch { |
| 33 | + Write-Error "❌ Module manifest validation failed: $_" |
| 34 | + exit 1 |
| 35 | + } |
| 36 | + |
| 37 | + # 2. Install required dependencies |
| 38 | + Write-Host "📦 Installing PowerShellGet and required modules..." -ForegroundColor Yellow |
| 39 | + if (-not (Get-Module -ListAvailable -Name PowerShellGet)) { |
| 40 | + Install-Module -Name PowerShellGet -Force -AllowClobber -Scope CurrentUser |
| 41 | + } |
| 42 | + |
| 43 | + # 3. Set PowerShell Gallery as trusted repository |
| 44 | + Write-Host "🔒 Configuring PowerShell Gallery..." -ForegroundColor Yellow |
| 45 | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted |
| 46 | + |
| 47 | + # 4. Install required modules if specified in manifest |
| 48 | + $data = Import-PowerShellDataFile "$ModulePath\$ModuleName.psd1" |
20 | 49 | if($data.RequiredModules) { |
21 | | - $data.RequiredModules | Foreach-Object {Install-Module -Name $_.ModuleName -RequiredVersion $_.ModuleVersion } |
22 | | - } |
23 | | - Remove-Item -Path ".git" -Recurse -Force |
24 | | - Remove-Item -Path ".github" -Recurse -Force |
25 | | - Remove-Item -Path ".vscode" -Recurse -Force |
26 | | - # - uses: dlemstra/code-sign-action@v1 |
27 | | - # with: |
28 | | - # certificate: ${{ secrets.CERTIFICATE }} |
29 | | - # password: ${{ secrets.CERTIFICATE_PASSWORD }} |
30 | | - # folder: . |
31 | | - # recursive: true |
32 | | - # files: | |
33 | | - # *.ps1 |
34 | | - # *.psm1 |
35 | | - - name: Publish Module to PowerShell Gallery |
36 | | - uses: pcgeek86/publish-powershell-module-action@v20 |
37 | | - id: publish-module |
38 | | - with: |
39 | | - NuGetApiKey: ${{ secrets.NUGETKEY }} |
| 50 | + Write-Host "📦 Installing required modules..." -ForegroundColor Yellow |
| 51 | + $data.RequiredModules | Foreach-Object { |
| 52 | + Write-Host " Installing: $($_.ModuleName) version $($_.ModuleVersion)" -ForegroundColor Cyan |
| 53 | + Install-Module -Name $_.ModuleName -RequiredVersion $_.ModuleVersion -Scope CurrentUser -Force |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + # 5. Check if module already exists and version comparison |
| 58 | + Write-Host "🔍 Checking if module exists in PowerShell Gallery..." -ForegroundColor Yellow |
| 59 | + try { |
| 60 | + $existingModule = Find-Module -Name $ModuleName -ErrorAction Stop |
| 61 | + Write-Host "📦 Found existing module version: $($existingModule.Version)" -ForegroundColor Cyan |
| 62 | + |
| 63 | + if ($manifest.Version -le $existingModule.Version) { |
| 64 | + Write-Error "⚠️ Current module version ($($manifest.Version)) is not higher than published version ($($existingModule.Version))" |
| 65 | + exit 1 |
| 66 | + } |
| 67 | + } |
| 68 | + catch { |
| 69 | + Write-Host "📦 This is a new module, proceeding with first-time publishing" -ForegroundColor Green |
| 70 | + } |
| 71 | + |
| 72 | + # 6. Clean up unnecessary files for publishing |
| 73 | + Write-Host "🧹 Cleaning up unnecessary files..." -ForegroundColor Yellow |
| 74 | + if (Test-Path ".git") { Remove-Item -Path ".git" -Recurse -Force } |
| 75 | + if (Test-Path ".github") { Remove-Item -Path ".github" -Recurse -Force } |
| 76 | + if (Test-Path ".vscode") { Remove-Item -Path ".vscode" -Recurse -Force } |
| 77 | + |
| 78 | + # 7. Publish module |
| 79 | + Write-Host "🚀 Publishing module to PowerShell Gallery..." -ForegroundColor Yellow |
| 80 | + try { |
| 81 | + Publish-Module -Path $ModulePath -NuGetApiKey "${{ secrets.NUGETKEY }}" -Verbose |
| 82 | + Write-Host "🎉 Module published successfully!" -ForegroundColor Green |
| 83 | + Write-Host "📦 Module link: https://www.powershellgallery.com/packages/$ModuleName" -ForegroundColor Cyan |
| 84 | + } |
| 85 | + catch { |
| 86 | + Write-Error "❌ Module publishing failed: $_" |
| 87 | + exit 1 |
| 88 | + } |
| 89 | + |
| 90 | + Write-Host "✅ Publishing process completed!" -ForegroundColor Green |
0 commit comments