Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 21 additions & 112 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create Release PR
name: Create Release

on:
workflow_dispatch:
Expand All @@ -21,18 +21,16 @@ on:

permissions:
contents: write
pull-requests: write

jobs:
create-release-pr:
create-release:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Ruby
uses: ruby/setup-ruby@v1
Expand Down Expand Up @@ -97,140 +95,51 @@ jobs:
echo "=== CHANGELOG PREVIEW ==="
bundle exec rake release:changelog[${{ steps.next_version.outputs.NEXT_VERSION }}] || true

- name: Create release branch
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
BRANCH_NAME="release/v${{ steps.next_version.outputs.NEXT_VERSION }}"
git checkout -b "$BRANCH_NAME"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV

- name: Run tests before release
if: ${{ github.event.inputs.dry_run != 'true' }}
run: bundle exec rake ci

- name: Create release
- name: Create release and tag
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
echo "🚀 Creating ${{ steps.release_type.outputs.RELEASE_TYPE }} release..."
bundle exec rake release:create[${{ steps.release_type.outputs.RELEASE_TYPE }}]

- name: Push release branch
- name: Push changes and tag
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
git push origin "$BRANCH_NAME"

- name: Create Pull Request
if: ${{ github.event.inputs.dry_run != 'true' }}
id: create_pr
uses: actions/github-script@v7
with:
script: |
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Release v${{ steps.next_version.outputs.NEXT_VERSION }}`,
head: process.env.BRANCH_NAME,
base: 'main',
body: `## Release v${{ steps.next_version.outputs.NEXT_VERSION }}

This is an automated release PR created by GitHub Actions.

### Release Type: ${{ steps.release_type.outputs.RELEASE_TYPE }}

### Changes

This PR includes:
- 📝 Updated CHANGELOG.md with new version
- 🏷️ Version tag v${{ steps.next_version.outputs.NEXT_VERSION }}
- ✅ All tests passing

### What happens when merged?

When this PR is merged to main:
1. 🚀 GitHub Actions will automatically create a GitHub release
2. 📦 Release artifacts will be built and attached
3. 🌐 Release will be published

### Review Checklist

- [ ] Review the changelog entries
- [ ] Verify the version bump is appropriate
- [ ] Confirm all tests are passing
- [ ] Check that no sensitive information is included

---

*This PR was created automatically by the [Create Release PR workflow](.github/workflows/create-release-pr.yml)*`,
draft: false
});

// Add labels
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: ['release', '${{ steps.release_type.outputs.RELEASE_TYPE }}']
});

console.log(`Created PR #${pr.number}: ${pr.html_url}`);

// Set outputs
core.setOutput('pr_number', pr.number);
core.setOutput('pr_url', pr.html_url);

return {
pr_number: pr.number,
pr_url: pr.html_url
};

- name: Comment on PR with details
if: ${{ github.event.inputs.dry_run != 'true' }}
uses: actions/github-script@v7
with:
script: |
const prNumber = ${{ steps.create_pr.outputs.pr_number }};

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `### 🚀 Release Summary

| Item | Value |
|------|-------|
| **Current Version** | ${{ steps.current_version.outputs.CURRENT_VERSION }} |
| **New Version** | ${{ steps.next_version.outputs.NEXT_VERSION }} |
| **Release Type** | ${{ steps.release_type.outputs.RELEASE_TYPE }} |
| **Branch** | \`${process.env.BRANCH_NAME}\` |
VERSION_TAG="v${{ steps.next_version.outputs.NEXT_VERSION }}"
echo "📤 Pushing changes and tag $VERSION_TAG to GitHub..."

### 📋 Next Steps
# Push any changelog changes
git push origin main

1. **Review** the changes in this PR
2. **Merge** this PR to trigger the release
3. **Monitor** the release workflow in the Actions tab
# Push the version tag (this will trigger the release.yml workflow)
git push origin "$VERSION_TAG"

The release will be automatically created when this PR is merged! 🎉`
});
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 PR Created! 🎉" >> $GITHUB_STEP_SUMMARY
echo "## Release Created! 🎉" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ steps.next_version.outputs.NEXT_VERSION }}" >> $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 "- **Branch**: $BRANCH_NAME" >> $GITHUB_STEP_SUMMARY
echo "- **PR**: ${{ steps.create_pr.outputs.pr_url }}" >> $GITHUB_STEP_SUMMARY
echo "- **Tag**: v${{ steps.next_version.outputs.NEXT_VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### What's Next?" >> $GITHUB_STEP_SUMMARY
echo "1. Review and merge the PR" >> $GITHUB_STEP_SUMMARY
echo "2. The release will be automatically created" >> $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**: ${{ steps.next_version.outputs.NEXT_VERSION }}" >> $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
145 changes: 145 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
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

- 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..."
bundle exec rake release:create[${{ steps.release_type.outputs.RELEASE_TYPE }}]

- name: Push changes and tag
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
VERSION_TAG="v${{ steps.next_version.outputs.NEXT_VERSION }}"
echo "📤 Pushing changes and tag $VERSION_TAG to GitHub..."

# Push any changelog changes
git push origin main

# Push the version tag (this will trigger the release.yml workflow)
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
32 changes: 3 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
push:
tags:
- 'v*'
pull_request:
types: [closed]
branches: [main]

env:
VERSION_REGEX: 'v[0-9]+\.[0-9]+\.[0-9]+'
Expand All @@ -17,12 +14,6 @@ permissions:
jobs:
release:
runs-on: ubuntu-latest
# Only run if it's a merged PR with release label, or a version tag push
if: |
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
(github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'release'))

steps:
- name: Checkout code
Expand All @@ -42,31 +33,14 @@ jobs:
bundle exec rake rubocop
bundle exec rake test

- name: Extract version from tag or PR
- name: Extract version from tag
id: version
run: |
if [ "${{ github.event_name }}" = "push" ]; then
# Extract from tag
VERSION=${GITHUB_REF#refs/tags/v}
else
# Extract from PR title (should be "Release vX.Y.Z")
VERSION=$(echo "${{ github.event.pull_request.title }}" | grep -oE "$VERSION_REGEX" | sed 's/^v//')
if [ -z "$VERSION" ]; then
echo "Could not extract version from PR title: ${{ github.event.pull_request.title }}"
exit 1
fi
fi
# Extract version from tag (refs/tags/v1.2.3 -> 1.2.3)
VERSION=${GITHUB_REF#refs/tags/v}
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"

- name: Create tag if from PR
if: github.event_name == 'pull_request'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -a "v${{ steps.version.outputs.VERSION }}" -m "Release version ${{ steps.version.outputs.VERSION }}"
git push origin "v${{ steps.version.outputs.VERSION }}"

- name: Extract changelog for version
id: changelog
run: |
Expand Down
Loading