Skip to content

Create Release

Create Release #63

Workflow file for this run

name: Create Release
on:
workflow_dispatch:
inputs:
bump_type:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
default: 'patch'
schedule:
- cron: '0 0 * * 1' # Run every Monday at midnight UTC
env:
REPO_NAME: ${{ github.repository }}
CHANGELOG: ''
DEFAULT_BUMP_TYPE: patch
jobs:
check-and-release:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.version_check.outputs.new_version }}
current_version: ${{ steps.version_check.outputs.current_version }}
release_created: ${{ steps.create_release.outputs.release_created }}
pr_url: ${{ steps.create_pr.outputs.pr_url }}
env:
BUMP_TYPE: ''
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for changelog generation
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Set bump type
id: set_bump_type
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "BUMP_TYPE=${{ github.event.inputs.bump_type }}" >> $GITHUB_ENV
else
echo "BUMP_TYPE=${{ env.DEFAULT_BUMP_TYPE }}" >> $GITHUB_ENV
fi
- name: Bump version
id: version_check
run: |
make version-bump TYPE=${{ env.BUMP_TYPE }}
NEW_VERSION=$(cat VERSION)
SETUP_VERSION=$(grep -Po "(?<=version=\")[^\"]*" setup.py)
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "current_version=$SETUP_VERSION" >> $GITHUB_OUTPUT
- name: Create branch and PR for version bump
if: steps.version_check.outputs.new_version != ''
id: create_pr
env:
GH_TOKEN: ${{ secrets.PAT }}
run: |
# Create a new branch for the version bump
NEW_VERSION=${{ steps.version_check.outputs.new_version }}
BRANCH_NAME="release/v${NEW_VERSION}"
chmod +x .github/scripts/generate_changelog.sh
.github/scripts/generate_changelog.sh --version ${{ steps.version_check.outputs.new_version }}
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git checkout -b $BRANCH_NAME
# Commit changes to the new branch
git add VERSION setup.py CHANGELOG.md
git commit -m "Bump version to ${NEW_VERSION}"
git push -u origin $BRANCH_NAME
.github/scripts/generate_changelog.sh --version ${{ steps.version_check.outputs.new_version }} --mode RELEASE --output-to-file
# Create a pull request
gh pr create \
--title "Release v${NEW_VERSION}" \
--body-file release_notes.md \
--base main \
--head $BRANCH_NAME
gh pr edit $PR_URL --add-label "release-request"
- name: Cleanup on failure
if: failure()
env:
GH_TOKEN: ${{ secrets.PAT }}
VERSION: ${{ steps.version_check.outputs.new_version }}
run: |
# Check if the release branch exists
if git ls-remote --heads origin "release/v${VERSION}" | grep -q "release/v${VERSION}"; then
# Delete the branch if it exists
git push origin --delete "release/v${VERSION}"
echo "Cleaned up release/v${VERSION} branch"
fi