Skip to content

Commit

Permalink
feat: add major/minor releases script
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPasMue committed Dec 10, 2024
1 parent aec3ff3 commit ba82998
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 18 deletions.
25 changes: 7 additions & 18 deletions .github/workflows/autorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ jobs:
git config --global user.email ${{ secrets.PYANSYS_CI_BOT_EMAIL }}
# Retrieve the latest release tag from GitHub
- name: Get Latest Release Branch
- name: Get Latest Release Branch (only for patch releases)
if: ${{ inputs.release_type == 'patch' }}
id: get-release
run: |
# Fetch all tags
Expand All @@ -59,29 +60,17 @@ jobs:
# Run the patch release script
- name: Run Patch Release Script
if: ${{ github.event.inputs.release_type == 'patch' }}
if: ${{ inputs.release_type == 'patch' }}
env:
GITHUB_TOKEN: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
RELEASE_BRANCH: ${{ env.RELEASE_BRANCH }}
run: |
./scripts/patch_release.sh ${{ env.RELEASE_BRANCH }}
# Run the minor release script
- name: Run Minor Release Script
if: ${{ github.event.inputs.release_type == 'minor' }}
# Run the major/minor release script
- name: Run Major/Minor Release Script
if: ${{ inputs.release_type == 'major' || inputs.release_type == 'minor' }}
env:
GITHUB_TOKEN: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
run: |
# TODO: Implement the minor release script
echo "Minor release script not implemented."
exit 1
# Run the major release script
- name: Run Major Release Script
if: ${{ github.event.inputs.release_type == 'major' }}
env:
GITHUB_TOKEN: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
run: |
# TODO: Implement the major release script
echo "Major release script not implemented."
exit 1
./scripts/major_minor_release.sh ${{ inputs.release_type }}
79 changes: 79 additions & 0 deletions scripts/major_minor_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# Ensure the script exits if any command fails
set -e

# Check if one argument is passed
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <bump-type>"
echo "<bump-type>: 'minor' or 'major'"
exit 1
fi

# Assign the argument to a variable
BUMP_TYPE=$1

if [[ "$BUMP_TYPE" != "minor" && "$BUMP_TYPE" != "major" ]]; then
echo "Error: Bump type must be 'minor' or 'major'."
exit 1
fi

# Checkout main branch
git checkout main

# Pull the latest changes
git pull

# File containing the version
VERSION_FILE="ansys/api/geometry/VERSION"

if [ ! -f "$VERSION_FILE" ]; then
echo "Error: VERSION file not found at $VERSION_FILE"
exit 1
fi

# Extract the current version
CURRENT_DEV_VERSION=$(cat "$VERSION_FILE")
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_DEV_VERSION"

# Calculate new version for release and development
if [ "$BUMP_TYPE" == "major" ]; then
# VERSION file on main: 0.2.dev0
# New release VERSION file: 1.0.0
# New dev VERSION file: 1.1.dev0
NEW_RELEASE_VERSION="$((MAJOR + 1)).0.0"
NEW_DEV_VERSION="$((MAJOR + 1)).1.dev0"
NEW_RELEASE_BRANCH="release/v$((MAJOR + 1)).0"
elif [ "$BUMP_TYPE" == "minor" ]; then
# VERSION file on main: 0.2.dev0
# New release VERSION file: 0.2.0
# New dev VERSION file: 0.3.dev0
NEW_RELEASE_VERSION="$MAJOR.$MINOR.0"
NEW_DEV_VERSION="$MAJOR.$((MINOR + 1)).dev0"
NEW_RELEASE_BRANCH="release/v$MAJOR.$MINOR"
fi

# Create the release branch and bump the release version
git checkout -b "$NEW_RELEASE_BRANCH"
echo "$NEW_RELEASE_VERSION" > "$VERSION_FILE"
git add "$VERSION_FILE"
git commit -m "release: v$NEW_RELEASE_VERSION"

# Push the release branch
git push origin "$NEW_RELEASE_BRANCH"

# Tag the release
git tag "v$NEW_RELEASE_VERSION"
git push origin "v$NEW_RELEASE_VERSION"

# Return to main and bump the dev version
git checkout main
echo "$NEW_DEV_VERSION" > "$VERSION_FILE"
git add "$VERSION_FILE"
git commit -m "chore: bump dev version to $NEW_DEV_VERSION"

# Push the changes to main
git push origin main

echo "Release branch '$NEW_RELEASE_BRANCH' created with version $NEW_RELEASE_VERSION."
echo "Main branch bumped to development version $NEW_DEV_VERSION."

0 comments on commit ba82998

Please sign in to comment.