name: Create Release PR
on:
workflow_dispatch:
inputs:
version_action:
description: 'Version action to perform'
required: false
default: 'patch'
type: choice
options:
- patch
- minor
- major
dry_run:
description: 'Perform a dry run (do not actually create PR)'
required: false
default: false
type: boolean
permissions:
contents: write
pull-requests: write
issues: write
env:
CARGO_TERM_COLOR: always
jobs:
create-release-pr:
name: ${{ inputs.dry_run && format('🔥 Dry Run ({0})', inputs.version_action) || format('📝 Create Release PR ({0})', inputs.version_action) }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Cache cargo-edit binary
id: cache-cargo-edit
if: ${{ !inputs.dry_run }}
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/cargo-set-version
~/.cargo/bin/cargo-rm
~/.cargo/bin/cargo-add
key: ${{ runner.os }}-cargo-edit-v0.12.1
restore-keys: |
${{ runner.os }}-cargo-edit-
- name: Cache cargo-edit build dependencies
if: ${{ !inputs.dry_run && steps.cache-cargo-edit.outputs.cache-hit != 'true' }}
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/cache
~/.cargo/registry/index
~/.cargo/git/db
key: ${{ runner.os }}-cargo-edit-deps-v0.12.1
restore-keys: |
${{ runner.os }}-cargo-edit-deps-
- name: Install cargo-edit for version bumping
if: ${{ !inputs.dry_run && steps.cache-cargo-edit.outputs.cache-hit != 'true' }}
run: |
echo "Installing cargo-edit v0.12.1..."
cargo install cargo-edit --version 0.12.1 --verbose
echo "cargo-edit installed successfully!"
- name: Bump version and create PR
if: ${{ !inputs.dry_run }}
run: |
echo "Bumping version with type: ${{ inputs.version_action }}"
# Create new branch for version bump
BRANCH_NAME="release/bump-version-${{ inputs.version_action }}-$(date +%s)"
git checkout -b "$BRANCH_NAME"
# Bump version
cargo set-version --bump ${{ inputs.version_action }}
# Get new version for PR title
NEW_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
# Update Cargo.lock by running cargo check
echo "Updating Cargo.lock..."
cargo check
# Commit changes (both Cargo.toml and Cargo.lock)
git config user.name "otplus-actions[bot]"
git config user.email "otplus-actions[bot]@users.noreply.github.com"
git add Cargo.toml Cargo.lock
git commit -m "chore: bump version to $NEW_VERSION (${{ inputs.version_action }})"
# Push branch
git push origin "$BRANCH_NAME"
# Create Pull Request using GitHub CLI
echo "Creating Pull Request..."
gh pr create \
--title "🚀 Release v$NEW_VERSION" \
--body "## 📦 Version Bump Release
This PR bumps the version from the current version to **v$NEW_VERSION** using a **${{ inputs.version_action }}** bump.
### Changes
- Bump version in \`Cargo.toml\` to $NEW_VERSION
- Update \`Cargo.lock\` to reflect version changes
### Next Steps
1. Review and approve this PR
2. Merge this PR to main
3. The release workflow will automatically publish to crates.io
**Auto-generated by Release Workflow**" \
--head "$BRANCH_NAME" \
--base main || {
# Fallback: Create PR using REST API if CLI fails
echo "GitHub CLI failed, trying REST API..."
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/pulls \
-d "{
\"title\":\"🚀 Release v$NEW_VERSION\",
\"head\":\"$BRANCH_NAME\",
\"base\":\"main\",
\"body\":\"## 📦 Version Bump Release\n\nThis PR bumps the version from the current version to **v$NEW_VERSION** using a **${{ inputs.version_action }}** bump.\n\n### Changes\n- Bump version in \\\`Cargo.toml\\\` to $NEW_VERSION\n- Update \\\`Cargo.lock\\\` to reflect version changes\n\n### Next Steps\n1. Review and approve this PR\n2. Merge this PR to main\n3. Use 'Publish to Crates.io' workflow to release\n\n**Auto-generated by Release Workflow**\"
}"
}
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
- name: PR Created Notice
if: ${{ !inputs.dry_run }}
run: |
echo "## 🎯 PR Created Successfully!" >> $GITHUB_STEP_SUMMARY
echo "- Pull Request has been created for version bump" >> $GITHUB_STEP_SUMMARY
echo "- Please review and merge the PR to trigger the actual release" >> $GITHUB_STEP_SUMMARY
echo "- After merging, use the 'Publish to Crates.io' workflow to release" >> $GITHUB_STEP_SUMMARY