|
| 1 | +# SPDX-FileCopyrightText: Copyright Corsinvest Srl |
| 2 | +# SPDX-License-Identifier: GPL-3.0-only |
| 3 | + |
| 4 | +name: Release and Publish to PowerShell Gallery |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - 'v*' |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + tag: |
| 13 | + description: 'Tag to release (e.g. v9.1.3)' |
| 14 | + required: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Extract and validate version |
| 25 | + id: version |
| 26 | + shell: pwsh |
| 27 | + run: | |
| 28 | + # Read version from module manifest |
| 29 | + $manifest = Import-PowerShellDataFile ./Corsinvest.ProxmoxVE.Api/Corsinvest.ProxmoxVE.Api.psd1 |
| 30 | + $moduleVersion = $manifest.ModuleVersion |
| 31 | + Write-Host "Module version: $moduleVersion" |
| 32 | +
|
| 33 | + # Get tag version |
| 34 | + if ("${{ github.event_name }}" -eq "workflow_dispatch") { |
| 35 | + $tagVersion = "${{ github.event.inputs.tag }}".TrimStart('v') |
| 36 | + } else { |
| 37 | + $tagVersion = "${{ github.ref }}".Replace('refs/tags/v', '') |
| 38 | + } |
| 39 | + Write-Host "Tag version: $tagVersion" |
| 40 | +
|
| 41 | + # Validate versions match |
| 42 | + if ($moduleVersion -ne $tagVersion) { |
| 43 | + Write-Host "ERROR: Version mismatch!" |
| 44 | + Write-Host " Module version : $moduleVersion" |
| 45 | + Write-Host " Git tag : v$tagVersion" |
| 46 | + exit 1 |
| 47 | + } |
| 48 | +
|
| 49 | + Write-Host "Version validated: $moduleVersion" |
| 50 | + echo "version=$moduleVersion" >> $env:GITHUB_OUTPUT |
| 51 | +
|
| 52 | + - name: Create GitHub Release |
| 53 | + uses: softprops/action-gh-release@v2 |
| 54 | + with: |
| 55 | + tag_name: v${{ steps.version.outputs.version }} |
| 56 | + name: v${{ steps.version.outputs.version }} |
| 57 | + generate_release_notes: true |
| 58 | + prerelease: ${{ contains(steps.version.outputs.version, '-') }} |
| 59 | + |
| 60 | + - name: Publish module to PowerShell Gallery |
| 61 | + shell: pwsh |
| 62 | + env: |
| 63 | + PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }} |
| 64 | + run: | |
| 65 | + Publish-Module -Path ./Corsinvest.ProxmoxVE.Api -NuGetApiKey $env:PSGALLERY_API_KEY -Verbose |
0 commit comments