|
| 1 | +name: Release PowerShell Module |
| 2 | +description: Create GitHub release and optionally publish to PSGallery |
| 3 | +inputs: |
| 4 | + release-type: |
| 5 | + description: Release type |
| 6 | + required: true |
| 7 | + release-version: |
| 8 | + description: Release version |
| 9 | + required: true |
| 10 | + publish-psgallery: |
| 11 | + description: Publish to PowerShell Gallery |
| 12 | + required: true |
| 13 | +secrets: |
| 14 | + PSGALLERY_API_KEY: |
| 15 | + description: API Key for PowerShell Gallery |
| 16 | + required: false |
| 17 | +runs: |
| 18 | + using: composite |
| 19 | + steps: |
| 20 | + - name: Generate release notes |
| 21 | + shell: pwsh |
| 22 | + id: generate_release_notes |
| 23 | + env: |
| 24 | + GITHUB_TOKEN: ${{ github.token }} |
| 25 | + run: | |
| 26 | + git fetch --tags |
| 27 | + $tags = @(git tag --sort=-v:refname) |
| 28 | + $previousTag = if ($tags.Count -gt 0) { $tags[0] } else { $null } |
| 29 | + $uri = "https://api.github.com/repos/${{ github.repository }}/releases/generate-notes" |
| 30 | + $body = @{ |
| 31 | + tag_name = "v${{ inputs.release-version }}" |
| 32 | + target_commitish = "main" |
| 33 | + } |
| 34 | + # Only include previous_tag_name if a previous tag exists |
| 35 | + if ($previousTag) { |
| 36 | + $body['previous_tag_name'] = $previousTag |
| 37 | + } |
| 38 | + $requestParams = @{ |
| 39 | + Method = 'Post' |
| 40 | + Uri = $uri |
| 41 | + Headers = @{ |
| 42 | + Authorization = "Bearer ${{ env.GITHUB_TOKEN }}" |
| 43 | + Accept = 'application/vnd.github+json' |
| 44 | + } |
| 45 | + Body = ($body | ConvertTo-Json -Depth 3) |
| 46 | + ContentType = 'application/json' |
| 47 | + } |
| 48 | + $result = Invoke-RestMethod @requestParams |
| 49 | + Write-Output 'releaseNotes<<EOF' >> $env:GITHUB_OUTPUT |
| 50 | + Write-Output ($result.body.ToString()) >> $env:GITHUB_OUTPUT |
| 51 | + Write-Output 'EOF' >> $env:GITHUB_OUTPUT |
| 52 | +
|
| 53 | + - name: Create release |
| 54 | + id: create_release |
| 55 | + uses: actions/create-release@v1 |
| 56 | + env: |
| 57 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + with: |
| 59 | + tag_name: v${{ inputs.release-version }} |
| 60 | + release_name: Release v${{ inputs.release-version }} |
| 61 | + body: ${{ steps.generate_release_notes.outputs.releaseNotes }} |
| 62 | + draft: false |
| 63 | + prerelease: ${{ inputs.release-type == 'Prerelease' }} |
| 64 | + |
| 65 | + - name: Publish build package to PSGallery |
| 66 | + if: ${{ inputs.publish-psgallery == 'true' && env.PSGALLERY_API_KEY != '' }} |
| 67 | + shell: pwsh |
| 68 | + run: | |
| 69 | + Set-StrictMode -Version Latest |
| 70 | + [void] (Import-Module InvokeBuild) |
| 71 | + Invoke-Build -NugetApiKey ${{ env.PSGALLERY_API_KEY }} -Task Publish |
| 72 | +
|
| 73 | + - name: Publish build package to Github Release |
| 74 | + shell: pwsh |
| 75 | + run: | |
| 76 | + Set-StrictMode -Version Latest |
| 77 | + [void] (Import-Module InvokeBuild) |
| 78 | + Invoke-Build -Task Package |
| 79 | +
|
| 80 | + - name: Upload build package to Github Release |
| 81 | + uses: actions/upload-release-asset@v1 |
| 82 | + with: |
| 83 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 84 | + asset_path: ./build/package/${{ github.event.repository.name }}.${{ inputs.release-version }}.nupkg |
| 85 | + asset_name: ${{ github.event.repository.name }}-v${{ inputs.release-version }}.nupkg |
| 86 | + asset_content_type: application/octet-stream |
| 87 | + env: |
| 88 | + GITHUB_TOKEN: ${{ github.token }} |
0 commit comments