From 6f0055bd68bbc7677e29aa189683d189f92ae557 Mon Sep 17 00:00:00 2001 From: GraceSolutions Date: Wed, 3 Jun 2026 09:29:45 -0400 Subject: [PATCH] Run CI on self-hosted host runners (powershell-linux); switch publish to PSResourceGet 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. --- .gitea/workflows/publish-psgallery.yml | 109 +++++++++---------------- 1 file changed, 37 insertions(+), 72 deletions(-) diff --git a/.gitea/workflows/publish-psgallery.yml b/.gitea/workflows/publish-psgallery.yml index 4b21bff..9db7448 100644 --- a/.gitea/workflows/publish-psgallery.yml +++ b/.gitea/workflows/publish-psgallery.yml @@ -8,38 +8,25 @@ on: jobs: build: if: github.event.pull_request.merged == true - runs-on: ubuntu-latest + runs-on: powershell-linux 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 + - name: Verify host prerequisites (pwsh, dotnet) + shell: pwsh 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 + $ErrorActionPreference = 'Stop' + $missing = @() + if (-not (Get-Command pwsh -ErrorAction SilentlyContinue)) { $missing += 'pwsh' } + if (-not (Get-Command dotnet -ErrorAction SilentlyContinue)) { $missing += 'dotnet' } + if ($missing.Count -gt 0) { + throw "Host runner is missing required tool(s): $($missing -join ', '). Provision them on the runner host." + } + Write-Host ("pwsh: " + (pwsh -NoProfile -Command '$PSVersionTable.PSVersion.ToString()')) + Write-Host ("dotnet: " + (dotnet --version)) - name: Build and test module shell: pwsh @@ -64,7 +51,7 @@ jobs: release: needs: build if: ${{ success() && github.event.pull_request.merged == true }} - runs-on: ubuntu-latest + runs-on: powershell-linux outputs: version: ${{ steps.meta.outputs.version }} tag: ${{ steps.meta.outputs.tag }} @@ -74,26 +61,14 @@ jobs: with: fetch-depth: 0 - - name: Install PowerShell 7 (if not present) - shell: bash + - name: Verify host prerequisites (pwsh) + shell: pwsh 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 + $ErrorActionPreference = 'Stop' + if (-not (Get-Command pwsh -ErrorAction SilentlyContinue)) { + throw "Host runner is missing required tool: pwsh. Provision it on the runner host." + } + Write-Host ("pwsh: " + (pwsh -NoProfile -Command '$PSVersionTable.PSVersion.ToString()')) - name: Download module artifact uses: actions/download-artifact@v4 @@ -226,28 +201,16 @@ jobs: publish: needs: release if: ${{ success() && github.event.pull_request.merged == true }} - runs-on: ubuntu-latest + runs-on: powershell-linux steps: - - name: Install PowerShell 7 (if not present) - shell: bash + - name: Verify host prerequisites (pwsh) + shell: pwsh 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 + $ErrorActionPreference = 'Stop' + if (-not (Get-Command pwsh -ErrorAction SilentlyContinue)) { + throw "Host runner is missing required tool: pwsh. Provision it on the runner host." + } + Write-Host ("pwsh: " + (pwsh -NoProfile -Command '$PSVersionTable.PSVersion.ToString()')) - name: Download module artifact uses: actions/download-artifact@v4 @@ -255,15 +218,16 @@ jobs: name: PSInfisicalAPI-module path: Module/PSInfisicalAPI - - name: Bootstrap PowerShellGet / NuGet provider + - name: Bootstrap Microsoft.PowerShell.PSResourceGet 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 + if (-not (Get-Module -ListAvailable -Name Microsoft.PowerShell.PSResourceGet)) { + throw "Microsoft.PowerShell.PSResourceGet is not installed on the host runner. Provision it (Install-Module Microsoft.PowerShell.PSResourceGet -Scope AllUsers)." } - 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 shell: pwsh @@ -290,7 +254,8 @@ jobs: $ErrorActionPreference = 'Stop' $moduleDir = Join-Path $PWD 'Module/PSInfisicalAPI' Write-Host "Publishing module from: $moduleDir" - Publish-Module ` + Publish-PSResource ` -Path $moduleDir ` - -NuGetApiKey $env:PSGALLERY_API_KEY ` + -Repository PSGallery ` + -ApiKey $env:PSGALLERY_API_KEY ` -Verbose