|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Ensure the script exits if any command fails |
| 4 | +set -e |
| 5 | + |
| 6 | +# Check if one argument is passed |
| 7 | +if [ "$#" -ne 1 ]; then |
| 8 | + echo "Usage: $0 <bump-type>" |
| 9 | + echo "<bump-type>: 'minor' or 'major'" |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +# Assign the argument to a variable |
| 14 | +BUMP_TYPE=$1 |
| 15 | + |
| 16 | +if [[ "$BUMP_TYPE" != "minor" && "$BUMP_TYPE" != "major" ]]; then |
| 17 | + echo "Error: Bump type must be 'minor' or 'major'." |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +# Checkout main branch |
| 22 | +git checkout main |
| 23 | + |
| 24 | +# Pull the latest changes |
| 25 | +git pull |
| 26 | + |
| 27 | +# File containing the version |
| 28 | +VERSION_FILE="ansys/api/geometry/VERSION" |
| 29 | + |
| 30 | +if [ ! -f "$VERSION_FILE" ]; then |
| 31 | + echo "Error: VERSION file not found at $VERSION_FILE" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +# Extract the current version |
| 36 | +CURRENT_DEV_VERSION=$(cat "$VERSION_FILE") |
| 37 | +IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_DEV_VERSION" |
| 38 | + |
| 39 | +# Calculate new version for release and development |
| 40 | +if [ "$BUMP_TYPE" == "major" ]; then |
| 41 | + # VERSION file on main: 0.2.dev0 |
| 42 | + # New release VERSION file: 1.0.0 |
| 43 | + # New dev VERSION file: 1.1.dev0 |
| 44 | + NEW_RELEASE_VERSION="$((MAJOR + 1)).0.0" |
| 45 | + NEW_DEV_VERSION="$((MAJOR + 1)).1.dev0" |
| 46 | + NEW_RELEASE_BRANCH="release/$((MAJOR + 1)).0" |
| 47 | +elif [ "$BUMP_TYPE" == "minor" ]; then |
| 48 | + # VERSION file on main: 0.2.dev0 |
| 49 | + # New release VERSION file: 0.2.0 |
| 50 | + # New dev VERSION file: 0.3.dev0 |
| 51 | + NEW_RELEASE_VERSION="$MAJOR.$MINOR.0" |
| 52 | + NEW_DEV_VERSION="$MAJOR.$((MINOR + 1)).dev0" |
| 53 | + NEW_RELEASE_BRANCH="release/$MAJOR.$MINOR" |
| 54 | +fi |
| 55 | + |
| 56 | +# Create the release branch and bump the release version |
| 57 | +git checkout -b "$NEW_RELEASE_BRANCH" |
| 58 | +echo "$NEW_RELEASE_VERSION" > "$VERSION_FILE" |
| 59 | +git add "$VERSION_FILE" |
| 60 | +git commit -m "release: v$NEW_RELEASE_VERSION" |
| 61 | + |
| 62 | +# Push the release branch |
| 63 | +git push origin "$NEW_RELEASE_BRANCH" |
| 64 | + |
| 65 | +# Tag the release |
| 66 | +git tag "v$NEW_RELEASE_VERSION" |
| 67 | +git push origin "v$NEW_RELEASE_VERSION" |
| 68 | + |
| 69 | +# Return to main and bump the dev version |
| 70 | +git checkout main |
| 71 | +echo "$NEW_DEV_VERSION" > "$VERSION_FILE" |
| 72 | +git add "$VERSION_FILE" |
| 73 | +git commit -m "chore: bump dev version to $NEW_DEV_VERSION" |
| 74 | + |
| 75 | +# Push the changes to main |
| 76 | +git push origin main |
| 77 | + |
| 78 | +echo "Release branch '$NEW_RELEASE_BRANCH' created with version $NEW_RELEASE_VERSION." |
| 79 | +echo "Main branch bumped to development version $NEW_DEV_VERSION." |
0 commit comments