|
| 1 | +name: psgraph-gallery-installed-e2e |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - '.github/workflows/gallery-installed-e2e.yml' |
| 7 | + - 'eng/Test-GalleryInstalledPSQuickGraph.ps1' |
| 8 | + |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + module_version: |
| 12 | + description: 'Optional exact PSGallery module version to validate, e.g. 2.5.0-beta5. Empty uses latest visible version.' |
| 13 | + required: false |
| 14 | + default: '' |
| 15 | + |
| 16 | + release: |
| 17 | + types: [published] |
| 18 | + |
| 19 | +jobs: |
| 20 | + gallery-installed: |
| 21 | + name: ${{ matrix.os }} / ${{ matrix.rid }} |
| 22 | + runs-on: ${{ matrix.os }} |
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + include: |
| 29 | + - os: ubuntu-24.04 |
| 30 | + rid: linux-x64 |
| 31 | + - os: windows-2022 |
| 32 | + rid: win-x64 |
| 33 | + - os: macos-14 |
| 34 | + rid: osx-arm64 |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout code |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Install PowerShell |
| 41 | + uses: PSModule/install-powershell@v1 |
| 42 | + with: |
| 43 | + Version: latest |
| 44 | + |
| 45 | + - name: Verify PowerShell version |
| 46 | + shell: pwsh |
| 47 | + run: | |
| 48 | + $PSVersionTable.PSVersion.ToString() | Write-Host |
| 49 | +
|
| 50 | + - name: Resolve module version |
| 51 | + id: module |
| 52 | + shell: pwsh |
| 53 | + run: | |
| 54 | + if ('${{ github.event_name }}' -eq 'release') { |
| 55 | + $tag = '${{ github.ref }}' -replace '^refs/tags/', '' |
| 56 | + $tag = $tag -replace '^v', '' |
| 57 | + if ($tag -notmatch '^[0-9]+\.[0-9]+\.[0-9]+(?:-[A-Za-z0-9\-]+)?$') { |
| 58 | + throw 'Bad tag format. Expected vX.Y.Z or vX.Y.Z-label.' |
| 59 | + } |
| 60 | +
|
| 61 | + $moduleVersion = $tag |
| 62 | + } |
| 63 | + elseif (-not [string]::IsNullOrWhiteSpace('${{ github.event.inputs.module_version }}')) { |
| 64 | + $moduleVersion = '${{ github.event.inputs.module_version }}' |
| 65 | + if ($moduleVersion -notmatch '^[0-9]+\.[0-9]+\.[0-9]+(?:-[A-Za-z0-9\-]+)?$') { |
| 66 | + throw 'Manual module_version must look like X.Y.Z or X.Y.Z-label.' |
| 67 | + } |
| 68 | + } |
| 69 | + else { |
| 70 | + $module = Find-Module -Name PSQuickGraph -Repository PSGallery -AllowPrerelease -ErrorAction Stop | Select-Object -First 1 |
| 71 | + if ($null -eq $module) { |
| 72 | + throw 'PSQuickGraph was not found in PSGallery.' |
| 73 | + } |
| 74 | +
|
| 75 | + $moduleVersion = $module.Version.ToString() |
| 76 | + } |
| 77 | +
|
| 78 | + $allowPrerelease = $moduleVersion.Contains('-') |
| 79 | + "module_version=$moduleVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 80 | + "allow_prerelease=$allowPrerelease" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 81 | +
|
| 82 | + - name: Install PSQuickGraph from PSGallery |
| 83 | + shell: pwsh |
| 84 | + run: | |
| 85 | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted |
| 86 | +
|
| 87 | + $moduleVersion = '${{ steps.module.outputs.module_version }}' |
| 88 | + $allowPrerelease = '${{ steps.module.outputs.allow_prerelease }}' -eq 'True' |
| 89 | +
|
| 90 | + $installParameters = @{ |
| 91 | + Name = 'PSQuickGraph' |
| 92 | + Repository = 'PSGallery' |
| 93 | + RequiredVersion = $moduleVersion |
| 94 | + Scope = 'CurrentUser' |
| 95 | + Force = $true |
| 96 | + ErrorAction = 'Stop' |
| 97 | + } |
| 98 | +
|
| 99 | + if ($allowPrerelease) { |
| 100 | + $installParameters.AllowPrerelease = $true |
| 101 | + } |
| 102 | +
|
| 103 | + $maxAttempts = 12 |
| 104 | + for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) { |
| 105 | + try { |
| 106 | + Install-Module @installParameters |
| 107 | + break |
| 108 | + } |
| 109 | + catch { |
| 110 | + if ($attempt -eq $maxAttempts) { |
| 111 | + throw |
| 112 | + } |
| 113 | +
|
| 114 | + Write-Warning "Install-Module failed on attempt $attempt/$maxAttempts. Waiting for PSGallery propagation before retrying. $($_.Exception.Message)" |
| 115 | + Start-Sleep -Seconds 30 |
| 116 | + } |
| 117 | + } |
| 118 | +
|
| 119 | + $installedParameters = @{ |
| 120 | + Name = 'PSQuickGraph' |
| 121 | + RequiredVersion = $moduleVersion |
| 122 | + ErrorAction = 'Stop' |
| 123 | + } |
| 124 | +
|
| 125 | + if ($allowPrerelease) { |
| 126 | + $installedParameters.AllowPrerelease = $true |
| 127 | + } |
| 128 | +
|
| 129 | + $installed = Get-InstalledModule @installedParameters |
| 130 | + if ($null -eq $installed) { |
| 131 | + throw "PSQuickGraph $moduleVersion was not found after Install-Module." |
| 132 | + } |
| 133 | +
|
| 134 | + - name: Run gallery-installed smoke suite |
| 135 | + shell: pwsh |
| 136 | + run: | |
| 137 | + $outputDirectory = Join-Path $PWD 'artifacts/gallery-installed-e2e/${{ matrix.rid }}' |
| 138 | + pwsh -NoLogo -NoProfile -File ./eng/Test-GalleryInstalledPSQuickGraph.ps1 ` |
| 139 | + -ModuleName PSQuickGraph ` |
| 140 | + -RequiredVersion '${{ steps.module.outputs.module_version }}' ` |
| 141 | + -OutputDirectory $outputDirectory |
| 142 | +
|
| 143 | + - name: Ensure Pester is available |
| 144 | + shell: pwsh |
| 145 | + run: | |
| 146 | + $pester = Get-Module -ListAvailable -Name Pester | |
| 147 | + Where-Object { $_.Version -ge [version]'5.0.0' } | |
| 148 | + Sort-Object Version -Descending | |
| 149 | + Select-Object -First 1 |
| 150 | +
|
| 151 | + if ($null -eq $pester) { |
| 152 | + Install-Module -Name Pester -Repository PSGallery -Scope CurrentUser -Force -SkipPublisherCheck -ErrorAction Stop |
| 153 | + } |
| 154 | +
|
| 155 | + - name: Run gallery-installed Pester suite |
| 156 | + shell: pwsh |
| 157 | + env: |
| 158 | + PSGRAPH_TEST_MODULE_NAME: PSQuickGraph |
| 159 | + PSGRAPH_TEST_MODULE_VERSION: ${{ steps.module.outputs.module_version }} |
| 160 | + run: | |
| 161 | + Invoke-Pester -Path ./PsGraph.Pester.Tests -CI |
| 162 | +
|
| 163 | + - name: Upload gallery-installed artifacts |
| 164 | + if: always() |
| 165 | + uses: actions/upload-artifact@v4 |
| 166 | + with: |
| 167 | + name: gallery-installed-e2e-${{ matrix.rid }} |
| 168 | + path: artifacts/gallery-installed-e2e/${{ matrix.rid }} |
| 169 | + if-no-files-found: warn |
0 commit comments