Fix release workflow to checkout main branch to prevent push conflicts #4
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 | |
| on: | |
| push: | |
| tags: | |
| - 'release-patch' | |
| - 'release-minor' | |
| - 'release-major' | |
| workflow_dispatch: | |
| inputs: | |
| bump_type: | |
| description: 'Version bump type' | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| name: Build and Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main # Always checkout main branch, not the tag | |
| fetch-depth: 0 # Full history needed for changelog | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup .NET 9 | |
| uses: actions/setup-dotnet@v3 | |
| with: | |
| dotnet-version: '9.0.x' | |
| - name: Install zip utility | |
| run: sudo apt-get update && sudo apt-get install -y zip | |
| - name: Extract bump type from tag or input | |
| id: bump | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| BUMP_TYPE="${{ inputs.bump_type }}" | |
| else | |
| BUMP_TYPE=${GITHUB_REF#refs/tags/release-} | |
| fi | |
| echo "type=$BUMP_TYPE" >> $GITHUB_OUTPUT | |
| echo "Bump type: $BUMP_TYPE" | |
| - name: Bump version in all files | |
| run: | | |
| chmod +x bump-version.sh get-version.sh | |
| ./bump-version.sh ${{ steps.bump.outputs.type }} -y | |
| - name: Get new version | |
| id: version | |
| run: | | |
| VERSION=$(./get-version.sh) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "New version: $VERSION" | |
| - name: Generate changelog from commits | |
| id: changelog | |
| run: | | |
| # Find previous version tag (not release trigger tags) | |
| PREV_TAG=$(git describe --tags --abbrev=0 --match "v[0-9]*" HEAD^ 2>/dev/null || echo "") | |
| echo "Previous tag: ${PREV_TAG:-none (first release)}" | |
| if [ -z "$PREV_TAG" ]; then | |
| # First release - get all commits | |
| COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges | head -20) | |
| else | |
| # Get commits since last version tag | |
| COMMITS=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges) | |
| fi | |
| # Build changelog for GitHub release | |
| { | |
| echo "changelog<<EOF" | |
| echo "## What's Changed" | |
| echo "" | |
| echo "$COMMITS" | |
| if [ -n "$PREV_TAG" ]; then | |
| echo "" | |
| echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...v${{ steps.version.outputs.version }}" | |
| fi | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| - name: Update CHANGELOG.md | |
| run: | | |
| VERSION=${{ steps.version.outputs.version }} | |
| DATE=$(date +%Y-%m-%d) | |
| # Create new version section with current date | |
| sed -i "s/## \[Unreleased\]/## [Unreleased]\n\n## [$VERSION] - $DATE/" CHANGELOG.md | |
| # Update version comparison links at bottom | |
| PREV_TAG=$(git describe --tags --abbrev=0 --match "v[0-9]*" HEAD^ 2>/dev/null || echo "") | |
| if [ -n "$PREV_TAG" ]; then | |
| # Update [Unreleased] link | |
| sed -i "s|\[Unreleased\]:.*|[Unreleased]: https://github.com/${{ github.repository }}/compare/v$VERSION...HEAD|" CHANGELOG.md | |
| # Add new version link | |
| sed -i "/\[Unreleased\]:/a [$VERSION]: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...v$VERSION" CHANGELOG.md | |
| else | |
| # First release | |
| sed -i "/\[Unreleased\]:/a [$VERSION]: https://github.com/${{ github.repository }}/releases/tag/v$VERSION" CHANGELOG.md | |
| fi | |
| - name: Commit version changes | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add LocalizationManager.csproj README.md CHANGELOG.md | |
| git commit -m "Bump version to ${{ steps.version.outputs.version }} [skip ci]" | |
| - name: Push version commit to main | |
| run: | | |
| git push origin HEAD:main | |
| echo "✓ Pushed version commit to main" | |
| - name: Create and push version tag | |
| run: | | |
| git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}" | |
| git push origin "v${{ steps.version.outputs.version }}" | |
| echo "✓ Created and pushed tag v${{ steps.version.outputs.version }}" | |
| - name: Build all platforms | |
| run: | | |
| ./build.sh | |
| echo "✓ Built all platforms" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ steps.version.outputs.version }} | |
| name: "Localization Resource Manager v${{ steps.version.outputs.version }}" | |
| body: | | |
| # LRM v${{ steps.version.outputs.version }} | |
| ${{ steps.changelog.outputs.changelog }} | |
| ## 📦 Downloads | |
| Choose the appropriate version for your platform: | |
| - **Linux (x64):** `lrm-${{ steps.version.outputs.version }}-linux-x64.tar.gz` | |
| - **Linux (ARM64):** `lrm-${{ steps.version.outputs.version }}-linux-arm64.tar.gz` *(Raspberry Pi, etc.)* | |
| - **Windows (x64):** `lrm-${{ steps.version.outputs.version }}-win-x64.zip` | |
| - **Windows (ARM64):** `lrm-${{ steps.version.outputs.version }}-win-arm64.zip` | |
| ## 📖 Installation | |
| See the [Installation Guide](https://github.com/${{ github.repository }}#installation) for detailed instructions. | |
| ## 🧪 Verified | |
| ✅ All 21 tests passing | |
| files: | | |
| publish/lrm-${{ steps.version.outputs.version }}-linux-x64.tar.gz | |
| publish/lrm-${{ steps.version.outputs.version }}-linux-arm64.tar.gz | |
| publish/lrm-${{ steps.version.outputs.version }}-win-x64.zip | |
| publish/lrm-${{ steps.version.outputs.version }}-win-arm64.zip | |
| draft: false | |
| prerelease: false | |
| - name: Delete release trigger tag | |
| if: always() | |
| run: | | |
| git push origin --delete ${{ github.ref_name }} || true | |
| echo "✓ Cleaned up trigger tag" |