Deploy CodeConverter #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy CodeConverter | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| deployWeb: | |
| description: "Deploy web to GitHub Pages" | |
| required: false | |
| type: boolean | |
| default: false | |
| publishNuget: | |
| description: "Publish NuGet package and dotnet tool" | |
| required: false | |
| type: boolean | |
| default: false | |
| createRelease: | |
| description: "Create GitHub release" | |
| required: false | |
| type: boolean | |
| default: false | |
| nugetApiKey: | |
| description: "NuGet API key (required if Publish NuGet is checked)" | |
| required: false | |
| type: string | |
| jobs: | |
| deploy: | |
| concurrency: deploy-${{ github.ref }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout 🛎️ | |
| uses: actions/checkout@v4 | |
| - name: Download ZIP artifacts | |
| uses: dawidd6/action-download-artifact@v6 | |
| with: | |
| workflow: dotnet.yml | |
| branch: master | |
| name_is_regexp: true | |
| name: ICSharpCode\.CodeConverter.*\.zip$ | |
| path: release-artifacts | |
| skip_unpack: | |
| - name: Rename ZIP files | |
| shell: pwsh | |
| run: | | |
| Get-ChildItem -Path release-artifacts -Filter "*.zip.zip" | ForEach-Object { | |
| $newName = $_.Name -replace '\.zip\.zip$', '.zip' | |
| Rename-Item -Path $_.FullName -NewName $newName | |
| } | |
| - name: Download NuGet and VSIX artifacts | |
| if: ${{ inputs.createRelease || inputs.publishNuget }} | |
| uses: dawidd6/action-download-artifact@v6 | |
| with: | |
| workflow: dotnet.yml | |
| branch: master | |
| name_is_regexp: true | |
| name: ICSharpCode\.CodeConverter.*\.(nupkg|vsix)$ | |
| path: release-artifacts | |
| skip_unpack: false | |
| - name: Extract web files | |
| if: ${{ inputs.deployWeb }} | |
| shell: pwsh | |
| run: | | |
| Expand-Archive -Path release-artifacts/ICSharpCode.CodeConverter.Web.*.zip -DestinationPath site -Force | |
| - name: Extract build version from artifacts | |
| id: get_version | |
| if: ${{ inputs.createRelease }} | |
| shell: pwsh | |
| run: | | |
| $artifact = Get-ChildItem -Path release-artifacts -Filter "ICSharpCode.CodeConverter.*.nupkg" | Select-Object -First 1 | |
| if ($artifact) { | |
| $version = $artifact.Name -replace '^ICSharpCode\.CodeConverter\.(.+)\.nupkg$', '$1' | |
| Write-Output "version=$version" >> $env:GITHUB_OUTPUT | |
| } else { | |
| throw "No NuGet packages found in release-artifacts directory" | |
| } | |
| - name: Extract latest changelog section | |
| id: changelog | |
| shell: pwsh | |
| if: ${{ inputs.createRelease }} | |
| run: | | |
| ./Get-LatestChangelog.ps1 -Path CHANGELOG.md | Tee-Object -FilePath release-notes.md | |
| - name: Publish web to GitHub Pages 🚀 | |
| if: ${{ inputs.deployWeb }} | |
| uses: JamesIves/github-pages-deploy-action@v4 | |
| with: | |
| branch: 'autoupdated/gh-pages' | |
| folder: 'site' | |
| - name: Publish NuGet packages (tool and library) | |
| if: ${{ inputs.publishNuget }} | |
| shell: pwsh | |
| env: | |
| NUGET_API_KEY: ${{ inputs.nugetApiKey }} | |
| run: | | |
| if (-not $env:NUGET_API_KEY) { throw "nugetApiKey input is required when Publish NuGet is checked." } | |
| Write-Output "::add-mask::$env:NUGET_API_KEY" | |
| $source = "https://api.nuget.org/v3/index.json" | |
| $packages = Get-ChildItem -Path release-artifacts -Filter "*.nupkg" | |
| foreach ($package in $packages) { | |
| dotnet nuget push $package.FullName -k $env:NUGET_API_KEY -s $source --skip-duplicate | |
| } | |
| - name: Publish GitHub release with changelog | |
| if: ${{ inputs.createRelease }} | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.get_version.outputs.version }} | |
| name: v${{ steps.get_version.outputs.version }} | |
| body_path: release-notes.md | |
| files: release-artifacts/** |