Run CI on self-hosted host runners (powershell-linux); switch publish to PSResourceGet
Publish to PowerShell Gallery / build (pull_request) Failing after 21s
Publish to PowerShell Gallery / release (pull_request) Has been skipped
Publish to PowerShell Gallery / publish (pull_request) Has been skipped

All three jobs (build, release, publish) now target runs-on: powershell-linux, which maps to :host on the Gitea runner so steps execute directly on the host OS instead of inside a Docker container. Dropped the apt-get/sudo install blocks and actions/setup-dotnet in favor of a fast preflight that verifies pwsh (and dotnet for the build job) are present, failing loudly otherwise. Publish job migrated off the legacy PowerShellGet v2 path (Set-PSRepository / Install-PackageProvider NuGet / Publish-Module) to Microsoft.PowerShell.PSResourceGet (Set-PSResourceRepository / Publish-PSResource), which is bundled with PS 7.4+ on Linux and does not depend on the NuGet package provider.
This commit is contained in:
GraceSolutions
2026-06-03 09:29:45 -04:00
parent dce97e98de
commit 6f0055bd68
+37 -72
View File
@@ -8,38 +8,25 @@ on:
jobs: jobs:
build: build:
if: github.event.pull_request.merged == true if: github.event.pull_request.merged == true
runs-on: ubuntu-latest runs-on: powershell-linux
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Set up .NET SDK - name: Verify host prerequisites (pwsh, dotnet)
uses: actions/setup-dotnet@v4 shell: pwsh
with:
dotnet-version: '8.0.x'
- name: Install PowerShell 7 (if not present)
shell: bash
run: | run: |
set -euo pipefail $ErrorActionPreference = 'Stop'
if command -v pwsh >/dev/null 2>&1; then $missing = @()
echo "pwsh already installed: $(pwsh --version)" if (-not (Get-Command pwsh -ErrorAction SilentlyContinue)) { $missing += 'pwsh' }
exit 0 if (-not (Get-Command dotnet -ErrorAction SilentlyContinue)) { $missing += 'dotnet' }
fi if ($missing.Count -gt 0) {
throw "Host runner is missing required tool(s): $($missing -join ', '). Provision them on the runner host."
sudo apt-get update }
sudo apt-get install -y --no-install-recommends wget ca-certificates apt-transport-https gnupg Write-Host ("pwsh: " + (pwsh -NoProfile -Command '$PSVersionTable.PSVersion.ToString()'))
Write-Host ("dotnet: " + (dotnet --version))
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: Build and test module - name: Build and test module
shell: pwsh shell: pwsh
@@ -64,7 +51,7 @@ jobs:
release: release:
needs: build needs: build
if: ${{ success() && github.event.pull_request.merged == true }} if: ${{ success() && github.event.pull_request.merged == true }}
runs-on: ubuntu-latest runs-on: powershell-linux
outputs: outputs:
version: ${{ steps.meta.outputs.version }} version: ${{ steps.meta.outputs.version }}
tag: ${{ steps.meta.outputs.tag }} tag: ${{ steps.meta.outputs.tag }}
@@ -74,26 +61,14 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Install PowerShell 7 (if not present) - name: Verify host prerequisites (pwsh)
shell: bash shell: pwsh
run: | run: |
set -euo pipefail $ErrorActionPreference = 'Stop'
if command -v pwsh >/dev/null 2>&1; then if (-not (Get-Command pwsh -ErrorAction SilentlyContinue)) {
echo "pwsh already installed: $(pwsh --version)" throw "Host runner is missing required tool: pwsh. Provision it on the runner host."
exit 0 }
fi Write-Host ("pwsh: " + (pwsh -NoProfile -Command '$PSVersionTable.PSVersion.ToString()'))
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: Download module artifact - name: Download module artifact
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
@@ -226,28 +201,16 @@ jobs:
publish: publish:
needs: release needs: release
if: ${{ success() && github.event.pull_request.merged == true }} if: ${{ success() && github.event.pull_request.merged == true }}
runs-on: ubuntu-latest runs-on: powershell-linux
steps: steps:
- name: Install PowerShell 7 (if not present) - name: Verify host prerequisites (pwsh)
shell: bash shell: pwsh
run: | run: |
set -euo pipefail $ErrorActionPreference = 'Stop'
if command -v pwsh >/dev/null 2>&1; then if (-not (Get-Command pwsh -ErrorAction SilentlyContinue)) {
echo "pwsh already installed: $(pwsh --version)" throw "Host runner is missing required tool: pwsh. Provision it on the runner host."
exit 0 }
fi Write-Host ("pwsh: " + (pwsh -NoProfile -Command '$PSVersionTable.PSVersion.ToString()'))
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: Download module artifact - name: Download module artifact
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
@@ -255,15 +218,16 @@ jobs:
name: PSInfisicalAPI-module name: PSInfisicalAPI-module
path: Module/PSInfisicalAPI path: Module/PSInfisicalAPI
- name: Bootstrap PowerShellGet / NuGet provider - name: Bootstrap Microsoft.PowerShell.PSResourceGet
shell: pwsh shell: pwsh
run: | run: |
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted if (-not (Get-Module -ListAvailable -Name Microsoft.PowerShell.PSResourceGet)) {
if (-not (Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue)) { throw "Microsoft.PowerShell.PSResourceGet is not installed on the host runner. Provision it (Install-Module Microsoft.PowerShell.PSResourceGet -Scope AllUsers)."
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser | Out-Null
} }
Get-PackageProvider -Name NuGet | Format-Table Name,Version Import-Module Microsoft.PowerShell.PSResourceGet -ErrorAction Stop
Set-PSResourceRepository -Name PSGallery -Trusted -ApiVersion v2
Get-PSResourceRepository -Name PSGallery | Format-Table Name,Uri,Trusted,ApiVersion
- name: Verify PowerShell Gallery API key is configured - name: Verify PowerShell Gallery API key is configured
shell: pwsh shell: pwsh
@@ -290,7 +254,8 @@ jobs:
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
$moduleDir = Join-Path $PWD 'Module/PSInfisicalAPI' $moduleDir = Join-Path $PWD 'Module/PSInfisicalAPI'
Write-Host "Publishing module from: $moduleDir" Write-Host "Publishing module from: $moduleDir"
Publish-Module ` Publish-PSResource `
-Path $moduleDir ` -Path $moduleDir `
-NuGetApiKey $env:PSGALLERY_API_KEY ` -Repository PSGallery `
-ApiKey $env:PSGALLERY_API_KEY `
-Verbose -Verbose