87 lines
2.8 KiB
YAML
87 lines
2.8 KiB
YAML
name: Publish to PowerShell Gallery
|
|
|
|
on:
|
|
pull_request:
|
|
types: [closed]
|
|
branches: [main]
|
|
|
|
jobs:
|
|
publish:
|
|
if: github.event.pull_request.merged == true
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up .NET SDK
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: '8.0.x'
|
|
|
|
- name: Install PowerShell 7 (if not present)
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
if command -v pwsh >/dev/null 2>&1; then
|
|
echo "pwsh already installed: $(pwsh --version)"
|
|
exit 0
|
|
fi
|
|
|
|
sudo apt-get update
|
|
sudo apt-get install -y --no-install-recommends wget ca-certificates apt-transport-https gnupg
|
|
|
|
source /etc/os-release
|
|
wget -q "https://packages.microsoft.com/config/ubuntu/${VERSION_ID}/packages-microsoft-prod.deb" -O /tmp/ms-prod.deb
|
|
sudo dpkg -i /tmp/ms-prod.deb
|
|
rm -f /tmp/ms-prod.deb
|
|
|
|
sudo apt-get update
|
|
sudo apt-get install -y powershell
|
|
pwsh --version
|
|
|
|
- name: Bootstrap PowerShellGet / NuGet provider
|
|
shell: pwsh
|
|
run: |
|
|
$ErrorActionPreference = 'Stop'
|
|
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
|
|
if (-not (Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue)) {
|
|
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser | Out-Null
|
|
}
|
|
Get-PackageProvider -Name NuGet | Format-Table Name,Version
|
|
|
|
- name: Build and test module
|
|
shell: pwsh
|
|
run: ./build.ps1 -RunTests
|
|
|
|
- name: Validate module manifest
|
|
shell: pwsh
|
|
run: |
|
|
$ErrorActionPreference = 'Stop'
|
|
$manifestPath = Join-Path $PWD 'Module/PSInfisicalAPI/PSInfisicalAPI.psd1'
|
|
$manifest = Test-ModuleManifest -Path $manifestPath
|
|
Write-Host "Manifest OK: $($manifest.Name) $($manifest.Version)"
|
|
|
|
- name: Verify PowerShell Gallery API key is configured
|
|
shell: pwsh
|
|
env:
|
|
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
|
|
run: |
|
|
if ([string]::IsNullOrWhiteSpace($env:PSGALLERY_API_KEY)) {
|
|
throw "Repository secret 'PSGALLERY_API_KEY' is not configured."
|
|
}
|
|
|
|
- name: Publish to PowerShell Gallery
|
|
shell: pwsh
|
|
env:
|
|
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
|
|
run: |
|
|
$ErrorActionPreference = 'Stop'
|
|
$moduleDir = Join-Path $PWD 'Module/PSInfisicalAPI'
|
|
Write-Host "Publishing module from: $moduleDir"
|
|
Publish-Module `
|
|
-Path $moduleDir `
|
|
-NuGetApiKey $env:PSGALLERY_API_KEY `
|
|
-Verbose
|