diff --git a/.github/scripts/get_version.py b/.github/scripts/get_version.py deleted file mode 100755 index 1a03419..0000000 --- a/.github/scripts/get_version.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 -import json -import subprocess -import sys - - -def get_latest_release_tag() -> str: - """Return the tag name of the latest release.""" - try: - result = subprocess.run( - ["gh", "release", "view", "--json", "tagName"], - check=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - json_string = result.stdout.decode("utf8").strip() - except subprocess.CalledProcessError as err: - error_message = err.stderr.decode("utf8").strip() - if "release not found" in error_message: - return "0.0.0" - else: - print(f"Error executing 'gh release view': {error_message}") - sys.exit(1) - - try: - return json.loads(json_string)["tagName"] - except json.JSONDecodeError as json_err: - print(f"Error decoding JSON: {json_err}") - print(f"JSON string received: {json_string}") - sys.exit(1) - - -def generate_next_patch_version(current_version: str) -> str: - """Generate the next patch version.""" - major, minor, patch = current_version.split(".") - return f"{major}.{minor}.{int(patch) + 1}" - - -def main(): - """Generate a new release tag and name without creating a GitHub release.""" - try: - latest_release_tag = get_latest_release_tag() - except Exception as e: - print(f"Unexpected error: {e}") - sys.exit(1) - - new_version = generate_next_patch_version(latest_release_tag) - - # Print the new release tag and name to stdout - print(new_version, end="") - - -if __name__ == "__main__": - main() diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a79a0b0..7747c2f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,11 @@ -name: Create a new patch release -on: workflow_dispatch +name: Create a new release +on: + workflow_dispatch: + inputs: + release_type: + description: 'Type of release: patch, minor, or major' + required: true + jobs: create-release: runs-on: ubuntu-latest @@ -9,12 +15,45 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Run Python script - id: version_step + - name: Get Last Release Tag + id: last_release + run: | + # Get the last release tag + LAST_RELEASE_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") + echo "Last Release Tag: $LAST_RELEASE_TAG" + + # Extract the version components + IFS='.' read -r -a version_parts <<< "${LAST_RELEASE_TAG:1}" + MAJOR="${version_parts[0]}" + MINOR="${version_parts[1]}" + PATCH="${version_parts[2]}" + + echo "::set-output name=last_release_tag::$LAST_RELEASE_TAG" + echo "::set-output name=major_version::$MAJOR" + echo "::set-output name=minor_version::$MINOR" + echo "::set-output name=patch_version::$PATCH" + + - name: Bump Version + id: bump_version run: | - new_version=$(./.github/scripts/get_version.py) - echo "New version: $new_version" - echo "::set-output name=new_version::$new_version" + release_type="${{ github.event.inputs.release_type }}" + if [ "$release_type" == "patch" ]; then + ((PATCH++)) + elif [ "$release_type" == "minor" ]; then + ((MINOR++)) + PATCH=0 + elif [ "$release_type" == "major" ]; then + ((MAJOR++)) + MINOR=0 + PATCH=0 + else + echo "Invalid release_type. Use 'patch', 'minor', or 'major'." + exit 1 + fi + + NEW_VERSION="$MAJOR.$MINOR.$PATCH" + echo "New Version: $NEW_VERSION" + echo "::set-output name=new_version::$NEW_VERSION" - name: Create Tag and Release id: create_release @@ -22,7 +61,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: v${{ steps.version_step.outputs.new_version }} - release_name: v${{ steps.version_step.outputs.new_version }} + tag_name: v${{ steps.bump_version.outputs.new_version }} + release_name: v${{ steps.bump_version.outputs.new_version }} draft: false prerelease: false