Generate release notes from commits #6
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: Release Mod | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up MSBuild | |
| uses: microsoft/setup-msbuild@v2 | |
| - name: Build mod | |
| run: msbuild src\kc-accessibility\kc-accessibility.csproj /t:Build /p:Configuration=Release | |
| - name: Package staged mod | |
| shell: cmd | |
| run: scripts\package-mod.cmd | |
| - name: Resolve release metadata | |
| id: release_meta | |
| shell: pwsh | |
| run: | | |
| $version = if ($env:GITHUB_REF_TYPE -eq 'tag') { | |
| $env:GITHUB_REF_NAME | |
| } else { | |
| "manual-" + $env:GITHUB_RUN_NUMBER | |
| } | |
| $asset = "kc-accessibility-$version.zip" | |
| Copy-Item "dist\kc-accessibility.zip" "dist\$asset" -Force | |
| "version=$version" >> $env:GITHUB_OUTPUT | |
| "asset_name=$asset" >> $env:GITHUB_OUTPUT | |
| - name: Generate release notes | |
| id: release_notes | |
| if: github.ref_type == 'tag' | |
| shell: pwsh | |
| run: | | |
| $currentTag = "${{ steps.release_meta.outputs.version }}" | |
| $allTags = @(git tag --sort=creatordate) | |
| $currentIndex = [Array]::IndexOf($allTags, $currentTag) | |
| $previousTag = $null | |
| if ($currentIndex -gt 0) { | |
| $previousTag = $allTags[$currentIndex - 1] | |
| } | |
| $notesPath = "dist\release-notes.txt" | |
| $lines = @("Changes in $currentTag", "") | |
| if ($previousTag) { | |
| $lines += "Since ${previousTag}:" | |
| $commitLines = git log "$previousTag..$currentTag" --pretty=format:"- %s" | |
| } else { | |
| $lines += "Initial release:" | |
| $commitLines = git log "$currentTag" --pretty=format:"- %s" | |
| } | |
| if (-not $commitLines) { | |
| $commitLines = @("- No commit subjects found.") | |
| } | |
| $lines += $commitLines | |
| Set-Content -Path $notesPath -Value $lines | |
| "notes_path=$notesPath" >> $env:GITHUB_OUTPUT | |
| - name: Upload packaged mod artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.release_meta.outputs.asset_name }} | |
| path: dist/${{ steps.release_meta.outputs.asset_name }} | |
| - name: Create GitHub release | |
| if: github.ref_type == 'tag' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.release_meta.outputs.version }} | |
| name: ${{ steps.release_meta.outputs.version }} | |
| body_path: ${{ steps.release_notes.outputs.notes_path }} | |
| files: dist/${{ steps.release_meta.outputs.asset_name }} |