From ba82998eceebb6d1368b5c2614f0606c71bc9f33 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:24:59 +0100 Subject: [PATCH] feat: add major/minor releases script --- .github/workflows/autorelease.yml | 25 +++------- scripts/major_minor_release.sh | 79 +++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 scripts/major_minor_release.sh diff --git a/.github/workflows/autorelease.yml b/.github/workflows/autorelease.yml index aa48b82..5e28a8c 100644 --- a/.github/workflows/autorelease.yml +++ b/.github/workflows/autorelease.yml @@ -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 @@ -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 }} diff --git a/scripts/major_minor_release.sh b/scripts/major_minor_release.sh new file mode 100644 index 0000000..a0f7d9d --- /dev/null +++ b/scripts/major_minor_release.sh @@ -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 " + echo ": '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."