Skip to content

Commit 46244b9

Browse files
authored
fix: resolve branch protection conflicts in release workflow (#10)
- Remove changelog commits to main branch in create-release.yml - Generate changelog dynamically in release.yml instead of reading from file - Create tags directly without requiring main branch pushes - Add optional ADMIN_TOKEN support for repositories that need it This fixes the "Changes must be made through a pull request" error by avoiding direct pushes to protected main branch while maintaining full release functionality. Fixes: remote rejected main -> main (push declined due to repository rule violations)
1 parent 3acfb97 commit 46244b9

2 files changed

Lines changed: 31 additions & 19 deletions

File tree

.github/workflows/create-release.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
uses: actions/checkout@v4
3232
with:
3333
fetch-depth: 0
34+
token: ${{ secrets.ADMIN_TOKEN || secrets.GITHUB_TOKEN }}
3435

3536
- name: Set up Ruby
3637
uses: ruby/setup-ruby@v1
@@ -103,18 +104,26 @@ jobs:
103104
if: ${{ github.event.inputs.dry_run != 'true' }}
104105
run: |
105106
echo "🚀 Creating ${{ steps.release_type.outputs.RELEASE_TYPE }} release..."
106-
bundle exec rake release:create[${{ steps.release_type.outputs.RELEASE_TYPE }}]
107+
108+
# Generate changelog content without committing
109+
VERSION_TAG="v${{ steps.next_version.outputs.NEXT_VERSION }}"
110+
echo "📝 Generating changelog for $VERSION_TAG..."
111+
CHANGELOG_CONTENT=$(bundle exec ruby scripts/version.rb next ${{ steps.release_type.outputs.RELEASE_TYPE }} | xargs -I {} bundle exec rake release:changelog[{}] 2>/dev/null || echo "Changelog generation failed")
112+
113+
# Create tag directly (without committing changelog to main)
114+
echo "🏷️ Creating tag $VERSION_TAG..."
115+
git tag -a "$VERSION_TAG" -m "Release version ${{ steps.next_version.outputs.NEXT_VERSION }}"
116+
117+
echo "✅ Tag $VERSION_TAG created successfully!"
107118
108119
- name: Push changes and tag
109120
if: ${{ github.event.inputs.dry_run != 'true' }}
110121
run: |
111122
VERSION_TAG="v${{ steps.next_version.outputs.NEXT_VERSION }}"
112-
echo "📤 Pushing changes and tag $VERSION_TAG to GitHub..."
113-
114-
# Push any changelog changes
115-
git push origin main
123+
echo "📤 Creating and pushing tag $VERSION_TAG to GitHub..."
116124
117-
# Push the version tag (this will trigger the release.yml workflow)
125+
# Only push the version tag (this will trigger the release.yml workflow)
126+
# We don't need to push to main since the tag creation doesn't require it
118127
git push origin "$VERSION_TAG"
119128
120129
echo "✅ Successfully pushed tag $VERSION_TAG"

.github/workflows/release.yml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,30 @@ jobs:
4141
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
4242
echo "Extracted version: $VERSION"
4343
44-
- name: Extract changelog for version
44+
- name: Generate changelog for release
4545
id: changelog
4646
run: |
47-
# Extract changelog section for this version
47+
# Generate changelog dynamically using the version helper
4848
VERSION="${{ steps.version.outputs.VERSION }}"
49-
CHANGELOG_SECTION=$(awk "/^## \[$VERSION\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md)
50-
51-
# If no specific version section found, use unreleased section
52-
if [ -z "$CHANGELOG_SECTION" ]; then
53-
CHANGELOG_SECTION=$(awk "/^## \[Unreleased\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md)
54-
fi
55-
49+
echo "📝 Generating changelog for version $VERSION..."
50+
51+
# Use the VersionHelper to generate changelog content
52+
CHANGELOG_CONTENT=$(bundle exec ruby -e "
53+
require_relative 'lib/version_helper'
54+
puts VersionHelper.generate_changelog_for_version('$VERSION')
55+
")
56+
5657
# Save to file to preserve multiline content
57-
echo "$CHANGELOG_SECTION" > changelog_body.txt
58-
59-
# Also set as output for use in release
58+
echo "$CHANGELOG_CONTENT" > changelog_body.txt
59+
60+
# Set as output for use in release
6061
{
6162
echo 'BODY<<EOF'
62-
echo "$CHANGELOG_SECTION"
63+
echo "$CHANGELOG_CONTENT"
6364
echo 'EOF'
6465
} >> $GITHUB_OUTPUT
66+
67+
echo "✅ Generated changelog for version $VERSION"
6568
6669
- name: Build and package application
6770
run: |

0 commit comments

Comments
 (0)