Create Release #2
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: | |
| workflow_dispatch: | |
| inputs: | |
| release_type: | |
| description: 'Type of release' | |
| required: true | |
| default: 'auto' | |
| type: choice | |
| options: | |
| - auto | |
| - major | |
| - minor | |
| - patch | |
| dry_run: | |
| description: 'Dry run (preview only)' | |
| required: false | |
| default: false | |
| type: boolean | |
| permissions: | |
| contents: write | |
| jobs: | |
| create-release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.ADMIN_TOKEN || secrets.GITHUB_TOKEN }} | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: '3.2' | |
| bundler-cache: true | |
| - name: Configure Git | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| - name: Determine release type | |
| id: release_type | |
| run: | | |
| if [ "${{ github.event.inputs.release_type }}" = "auto" ]; then | |
| # Run preview to get suggested release type | |
| PREVIEW_OUTPUT=$(bundle exec rake release:preview) | |
| echo "$PREVIEW_OUTPUT" | |
| # Extract suggested release type from output | |
| SUGGESTED_TYPE=$(echo "$PREVIEW_OUTPUT" | grep "Suggested release type:" | awk '{print $NF}') | |
| if [ -z "$SUGGESTED_TYPE" ]; then | |
| echo "Could not determine release type automatically, defaulting to patch" | |
| RELEASE_TYPE="patch" | |
| else | |
| RELEASE_TYPE="$SUGGESTED_TYPE" | |
| fi | |
| else | |
| RELEASE_TYPE="${{ github.event.inputs.release_type }}" | |
| fi | |
| echo "RELEASE_TYPE=$RELEASE_TYPE" >> $GITHUB_OUTPUT | |
| echo "Selected release type: $RELEASE_TYPE" | |
| - name: Get current version | |
| id: current_version | |
| run: | | |
| CURRENT=$(ruby scripts/version.rb current) | |
| echo "CURRENT_VERSION=$CURRENT" >> $GITHUB_OUTPUT | |
| - name: Calculate next version | |
| id: next_version | |
| run: | | |
| RELEASE_TYPE=${{ steps.release_type.outputs.RELEASE_TYPE }} | |
| NEXT_VERSION=$(ruby scripts/version.rb next "$RELEASE_TYPE") | |
| echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_OUTPUT | |
| echo "Next version will be: $NEXT_VERSION" | |
| - name: Preview release (dry run) | |
| if: ${{ github.event.inputs.dry_run == 'true' }} | |
| run: | | |
| echo "=== DRY RUN MODE ===" | |
| echo "Current version: ${{ steps.current_version.outputs.CURRENT_VERSION }}" | |
| echo "Release type: ${{ steps.release_type.outputs.RELEASE_TYPE }}" | |
| echo "Next version: ${{ steps.next_version.outputs.NEXT_VERSION }}" | |
| echo | |
| echo "=== COMMIT PREVIEW ===" | |
| bundle exec rake release:preview | |
| echo | |
| echo "=== CHANGELOG PREVIEW ===" | |
| bundle exec rake release:changelog[${{ steps.next_version.outputs.NEXT_VERSION }}] || true | |
| - name: Run tests before release | |
| if: ${{ github.event.inputs.dry_run != 'true' }} | |
| run: bundle exec rake ci | |
| - name: Create release and tag | |
| if: ${{ github.event.inputs.dry_run != 'true' }} | |
| run: | | |
| echo "🚀 Creating ${{ steps.release_type.outputs.RELEASE_TYPE }} release..." | |
| # Generate changelog content without committing | |
| VERSION_TAG="v${{ steps.next_version.outputs.NEXT_VERSION }}" | |
| echo "📝 Generating changelog for $VERSION_TAG..." | |
| 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") | |
| # Create tag directly (without committing changelog to main) | |
| echo "🏷️ Creating tag $VERSION_TAG..." | |
| git tag -a "$VERSION_TAG" -m "Release version ${{ steps.next_version.outputs.NEXT_VERSION }}" | |
| echo "✅ Tag $VERSION_TAG created successfully!" | |
| - name: Push changes and tag | |
| if: ${{ github.event.inputs.dry_run != 'true' }} | |
| run: | | |
| VERSION_TAG="v${{ steps.next_version.outputs.NEXT_VERSION }}" | |
| echo "📤 Creating and pushing tag $VERSION_TAG to GitHub..." | |
| # Only push the version tag (this will trigger the release.yml workflow) | |
| # We don't need to push to main since the tag creation doesn't require it | |
| git push origin "$VERSION_TAG" | |
| echo "✅ Successfully pushed tag $VERSION_TAG" | |
| echo "🎯 The release.yml workflow will now create the GitHub release automatically" | |
| - name: Output summary | |
| if: ${{ github.event.inputs.dry_run != 'true' }} | |
| run: | | |
| echo "## Release Created! 🎉" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Version**: v${{ steps.next_version.outputs.NEXT_VERSION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Type**: ${{ steps.release_type.outputs.RELEASE_TYPE }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Tag**: v${{ steps.next_version.outputs.NEXT_VERSION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### What happens next?" >> $GITHUB_STEP_SUMMARY | |
| echo "1. 🚀 The release.yml workflow is now running" >> $GITHUB_STEP_SUMMARY | |
| echo "2. 📦 GitHub release will be created automatically" >> $GITHUB_STEP_SUMMARY | |
| echo "3. 🌐 Monitor progress at: https://github.com/${{ github.repository }}/actions" >> $GITHUB_STEP_SUMMARY | |
| - name: Output dry run summary | |
| if: ${{ github.event.inputs.dry_run == 'true' }} | |
| run: | | |
| echo "## Dry Run Complete! 👀" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Would create version**: v${{ steps.next_version.outputs.NEXT_VERSION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Release type**: ${{ steps.release_type.outputs.RELEASE_TYPE }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "To create the actual release, run this workflow again without dry run mode." >> $GITHUB_STEP_SUMMARY |