fix(release) Use Windows and cargo install git-cliff #17
Workflow file for this run
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: Create Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to release (e.g., 1.4.0)' | |
| required: true | |
| type: string | |
| use_existing_changelog: | |
| description: 'Use existing CHANGELOG_{VERSION}.md file instead of generating one' | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: windows-latest | |
| name: Create GitHub Release | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Rust | |
| uses: actions-rust-lang/setup-rust-toolchain@v1 | |
| with: | |
| toolchain: stable | |
| - name: Install git-cliff | |
| shell: pwsh | |
| run: | | |
| cargo install git-cliff | |
| git-cliff --version | |
| - name: Extract version | |
| id: version | |
| shell: pwsh | |
| run: | | |
| if ($env:GITHUB_EVENT_NAME -eq "workflow_dispatch") { | |
| $env:VERSION = $env:GITHUB_EVENT_INPUTS_VERSION | |
| } else { | |
| $env:VERSION = $env:GITHUB_REF -replace "refs/tags/v", "" | |
| } | |
| echo "version=$env:VERSION" >> $env:GITHUB_OUTPUT | |
| - name: Check for existing changelog | |
| id: changelog_check | |
| shell: pwsh | |
| run: | | |
| $env:VERSION = "${{ steps.version.outputs.version }}" | |
| $env:CHANGELOG_FILE = "CHANGELOG_$env:VERSION.md" | |
| if ("${{ github.event.inputs.use_existing_changelog }}" -eq "true") -and (Test-Path $env:CHANGELOG_FILE)) { | |
| echo "changelog_exists=true" >> $env:GITHUB_OUTPUT | |
| echo "Using existing changelog: $env:CHANGELOG_FILE" | |
| } elseif (Test-Path $env:CHANGELOG_FILE) { | |
| echo "changelog_exists=false" >> $env:GITHUB_OUTPUT | |
| echo "Changelog file exists but use_existing_changelog is false" | |
| } else { | |
| echo "changelog_exists=false" >> $env:GITHUB_OUTPUT | |
| echo "No changelog file found, will generate with git-cliff" | |
| } | |
| - name: Generate changelog with git-cliff | |
| if: steps.changelog_check.outputs.changelog_exists == 'false' | |
| shell: pwsh | |
| run: | | |
| $env:VERSION = "${{ steps.version.outputs.version }}" | |
| git-cliff --config cliff.toml --tag "v$env:VERSION" --verbose > CHANGELOG.md | |
| - name: Format generated changelog | |
| if: steps.changelog_check.outputs.changelog_exists == 'false' | |
| shell: pwsh | |
| run: | | |
| $env:VERSION = "${{ steps.version.outputs.version }}" | |
| "# Changelog - Version $env:VERSION" | Out-File -Encoding UTF8 CHANGELOG_temp.md | |
| "" | Out-File -Encoding UTF8 -Append CHANGELOG_temp.md | |
| "*This changelog was automatically generated using git-cliff*" | Out-File -Encoding UTF8 -Append CHANGELOG_temp.md | |
| "" | Out-File -Encoding UTF8 -Append CHANGELOG_temp.md | |
| Get-Content CHANGELOG.md | Out-File -Encoding UTF8 -Append CHANGELOG_temp.md | |
| Move-Item CHANGELOG_temp.md CHANGELOG.md | |
| Copy-Item CHANGELOG.md "CHANGELOG_$env:VERSION.md" | |
| - name: Create release notes | |
| id: release_notes | |
| shell: pwsh | |
| run: | | |
| $env:VERSION = "${{ steps.version.outputs.version }}" | |
| if ("${{ steps.changelog_check.outputs.changelog_exists }}" -eq "true") { | |
| $env:CHANGELOG_FILE = "CHANGELOG_$env:VERSION.md" | |
| "### Release $env:VERSION" | Out-File -Encoding UTF8 release_notes.md | |
| "" | Out-File -Encoding UTF8 -Append release_notes.md | |
| "*Using existing ``$env:CHANGELOG_FILE``*" | Out-File -Encoding UTF8 -Append release_notes.md | |
| "" | Out-File -Encoding UTF8 -Append release_notes.md | |
| Get-Content $env:CHANGELOG_FILE | Out-File -Encoding UTF8 -Append release_notes.md | |
| } else { | |
| "### Release $env:VERSION" | Out-File -Encoding UTF8 release_notes.md | |
| "" | Out-File -Encoding UTF8 -Append release_notes.md | |
| "*Automatically generated using git-cliff*" | Out-File -Encoding UTF8 -Append release_notes.md | |
| "" | Out-File -Encoding UTF8 -Append release_notes.md | |
| Get-Content CHANGELOG.md | Select-Object -Skip 2 | Out-File -Encoding UTF8 -Append release_notes.md | |
| } | |
| echo "notes_file=release_notes.md" >> $env:GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| shell: pwsh | |
| run: | | |
| $env:VERSION = "${{ steps.version.outputs.version }}" | |
| $env:NOTES_FILE = "${{ steps.release_notes.outputs.notes_file }}" | |
| gh release create "v$env:VERSION" --title "v$env:VERSION" --notes-file $env:NOTES_FILE --repo $env:GITHUB_REPOSITORY | |
| - name: Commit new changelog if generated | |
| if: steps.changelog_check.outputs.changelog_exists == 'false' | |
| shell: pwsh | |
| run: | | |
| $env:VERSION = "${{ steps.version.outputs.version }}" | |
| git add "CHANGELOG_$env:VERSION.md" | |
| git commit -m "chore: Generate changelog for v$env:VERSION [skip ci]" | |
| git push | |
| - name: Upload changelog artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: changelog-${{ steps.version.outputs.version }} | |
| path: | | |
| CHANGELOG_${{ steps.version.outputs.version }}.md | |
| CHANGELOG.md | |
| release_notes.md |