Enhance GitHub Actions workflow to collect commits for release notes.… #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: Build and Release | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: # Allow manual triggering | |
| jobs: | |
| build-and-release: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch full history for version bumping | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.21' | |
| - name: Get version from VERSION file | |
| id: get_version | |
| run: | | |
| $version = Get-Content VERSION -Raw | |
| $version = $version.Trim() | |
| Write-Host "Building release for version: $version" | |
| echo "version=$version" >> $env:GITHUB_OUTPUT | |
| - name: Create logs directory | |
| run: | | |
| if (-not (Test-Path "logs")) { | |
| New-Item -ItemType Directory -Path "logs" | |
| } | |
| - name: Download dependencies | |
| run: | | |
| go mod tidy | |
| - name: Create dist directory | |
| run: | | |
| if (-not (Test-Path "dist")) { | |
| New-Item -ItemType Directory -Path "dist" | |
| } | |
| - name: Build executable | |
| id: build_executable | |
| run: | | |
| $version = ${{ steps.get_version.outputs.version }} | |
| $exeName = "UE-Git-Plugin-Manager-v$version.exe" | |
| $exePath = "dist/$exeName" | |
| Write-Host "Building $exeName..." | |
| go build -o $exePath . | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Build failed!" | |
| exit 1 | |
| } | |
| Write-Host "Build successful!" | |
| echo "exe_name=$exeName" >> $env:GITHUB_OUTPUT | |
| echo "exe_path=$exePath" >> $env:GITHUB_OUTPUT | |
| - name: Verify executable | |
| run: | | |
| $exeName = "${{ steps.build_executable.outputs.exe_name }}" | |
| $exePath = "${{ steps.build_executable.outputs.exe_path }}" | |
| if (Test-Path $exePath) { | |
| $fileSize = (Get-Item $exePath).Length | |
| Write-Host "Executable created successfully: $exeName" | |
| Write-Host "Size: $fileSize bytes" | |
| } else { | |
| Write-Error "Executable not found: $exePath" | |
| exit 1 | |
| } | |
| - name: Log version info | |
| run: | | |
| Write-Host "Building release for version: ${{ steps.get_version.outputs.version }}" | |
| Write-Host "Version is controlled by the VERSION file in the repository" | |
| - name: Collect commits for release notes | |
| id: collect_commits | |
| run: | | |
| # Try to find the last release tag | |
| $lastTag = $null | |
| try { | |
| $lastTag = git describe --tags --abbrev=0 --match "v*" 2>$null | |
| if ($LASTEXITCODE -ne 0) { | |
| $lastTag = $null | |
| } | |
| } catch { | |
| $lastTag = $null | |
| } | |
| # Get commits since last tag (or all commits if no tag exists) | |
| $commits = "" | |
| if ($lastTag) { | |
| Write-Host "Collecting commits since tag: $lastTag" | |
| $commits = git log --pretty=format:"- %s" --no-merges "$lastTag..HEAD" 2>$null | |
| } else { | |
| Write-Host "No previous tag found, collecting all commits" | |
| $commits = git log --pretty=format:"- %s" --no-merges | |
| } | |
| # Handle empty commit list | |
| if ([string]::IsNullOrWhiteSpace($commits)) { | |
| $commits = "- No changes (only merge commits)" | |
| Write-Host "Warning: No non-merge commits found" | |
| } else { | |
| Write-Host "Found commits for release notes" | |
| } | |
| # Store in GitHub output (escape newlines and special characters) | |
| $commitsEscaped = $commits -replace "`r?`n", "`n" -replace '"', '`"' | |
| echo "commits<<EOF" >> $env:GITHUB_OUTPUT | |
| echo "$commitsEscaped" >> $env:GITHUB_OUTPUT | |
| echo "EOF" >> $env:GITHUB_OUTPUT | |
| - name: Create Release | |
| run: | | |
| $version = "${{ steps.get_version.outputs.version }}" | |
| $exeName = "${{ steps.build_executable.outputs.exe_name }}" | |
| $exePath = "${{ steps.build_executable.outputs.exe_path }}" | |
| $commits = "${{ steps.collect_commits.outputs.commits }}" | |
| $notes = @" | |
| ## Changes in v$version | |
| $commits | |
| ### Download | |
| Download the ``$exeName`` file below and run it to use the latest version. | |
| ### Installation | |
| 1. Download ``$exeName`` | |
| 2. Run the executable | |
| 3. Follow the setup wizard | |
| "@ | |
| gh release create "v$version" --title "Release v$version" --notes $notes $exePath | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} |