From 33a1624bc26d3a44a0eefa8a49d2cdea0a7dfa8b Mon Sep 17 00:00:00 2001 From: Nikhil Narayen Date: Thu, 13 Feb 2025 10:59:57 -0500 Subject: [PATCH 1/3] Fix release script, derive current version from pypi --- .github/workflows/create_release_pr.yml | 10 +++++-- bin/bump_truss_version.sh | 38 ++++++++++++------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.github/workflows/create_release_pr.yml b/.github/workflows/create_release_pr.yml index e1013d650..501a569d0 100644 --- a/.github/workflows/create_release_pr.yml +++ b/.github/workflows/create_release_pr.yml @@ -25,9 +25,15 @@ jobs: run: | curl -sSL https://install.python-poetry.org | python3 - + - name: Get current Truss version + id: get-version + run: | + CURR_VERSION=$(curl -s https://pypi.org/pypi/truss/json | jq -r ".info.version") + echo "curr_version=$CURR_VERSION" >> "$GITHUB_OUTPUT" + - name: Bump version in pyproject.toml id: bump-version - run: ./bin/bump_truss_version.sh ${{ github.event.inputs.release_type }} + run: ./bin/bump_truss_version.sh ${{ steps.get-version.outputs.curr_version }} ${{ github.event.inputs.release_type }} - name: Commit changes run: | @@ -48,9 +54,9 @@ jobs: - name: Make PR run: | - CURR_VERSION=$(curl -s https://pypi.org/pypi/truss/json | jq -r ".info.version") PR_BODY="Updating Truss from [$CURR_VERSION](https://pypi.org/pypi/truss/json) to $TARGET_VERSION. **PLEASE ENSURE YOU MERGE, NOT SQUASH**" gh pr create --base release --head bump-version-$TARGET_VERSION --title "Release $TARGET_VERSION" --body "$PR_BODY" env: + CURR_VERSION: ${{ steps.get-version.outputs.curr_version }} TARGET_VERSION: ${{ steps.bump-version.outputs.version }} GH_TOKEN: ${{ secrets.BASETENBOT_GITHUB_TOKEN }} diff --git a/bin/bump_truss_version.sh b/bin/bump_truss_version.sh index bfe3a4e36..e8c99446d 100755 --- a/bin/bump_truss_version.sh +++ b/bin/bump_truss_version.sh @@ -1,44 +1,42 @@ #!/bin/bash -# This script bumps the project version using Poetry. -# It extracts the current version from `poetry version`, strips any non-semver suffix, -# and then increments the major, minor, or patch version as specified. +# This script bumps the project version based on an input version number. +# It takes an existing version number as an argument instead of extracting it via Poetry +# and increments the major, minor, or patch version as specified. # # Usage: -# ./bump_version.sh # bumps the patch (micro) version by default -# ./bump_version.sh major # bumps the major version (resets minor and patch to 0) -# ./bump_version.sh minor # bumps the minor version (resets patch to 0) +# ./bump_version.sh 0.9.60 # bumps the patch (micro) version by default +# ./bump_version.sh 0.9.60 major # bumps the major version (resets minor and patch to 0) +# ./bump_version.sh 0.9.60 minor # bumps the minor version (resets patch to 0) set -euo pipefail -# Default bump type is "patch" (micro) -BUMP_TYPE="${1:-patch}" - -# Get the current version using Poetry. -# Expected output format: "truss 0.9.60rc006" -version_output=$(poetry version) +if [[ $# -lt 1 ]]; then + echo "Usage: $0 [major|minor|patch]" + exit 1 +fi -# Extract the version (second field) -current_version=$(echo "$version_output" | awk '{print $2}') +CURRENT_VERSION="$1" +BUMP_TYPE="${2:-patch}" # Default bump type is "patch" (micro) # Strip any suffix beyond the semver (retain only X.Y.Z) -semver=$(echo "$current_version" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/') +semver=$(echo "$CURRENT_VERSION" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/') # Split the semver into major, minor, and patch -IFS='.' read -r major minor patch <<< "$semver" +IFS='.' read -r major minor path <<< "$semver" # Bump the version based on the bump type argument case "$BUMP_TYPE" in major) major=$((major + 1)) minor=0 - patch=0 + path=0 ;; minor) minor=$((minor + 1)) - patch=0 + path=0 ;; patch) - patch=$((patch + 1)) + path=$((path + 1)) ;; *) echo "Invalid bump type: $BUMP_TYPE. Use 'major', 'minor', or 'patch'." @@ -47,7 +45,7 @@ case "$BUMP_TYPE" in esac # Construct the new version string -new_version="${major}.${minor}.${patch}" +new_version="${major}.${minor}.${path}" # Set the new version using Poetry poetry version "$new_version" From 54bf9418ccd929b45ff5f2a8102e8a746e74a80d Mon Sep 17 00:00:00 2001 From: Nikhil Narayen Date: Thu, 13 Feb 2025 12:42:32 -0500 Subject: [PATCH 2/3] Fix typo --- bin/bump_truss_version.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/bump_truss_version.sh b/bin/bump_truss_version.sh index e8c99446d..4a6881fa7 100755 --- a/bin/bump_truss_version.sh +++ b/bin/bump_truss_version.sh @@ -22,21 +22,21 @@ BUMP_TYPE="${2:-patch}" # Default bump type is "patch" (micro) semver=$(echo "$CURRENT_VERSION" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/') # Split the semver into major, minor, and patch -IFS='.' read -r major minor path <<< "$semver" +IFS='.' read -r major minor patch <<< "$semver" # Bump the version based on the bump type argument case "$BUMP_TYPE" in major) major=$((major + 1)) minor=0 - path=0 + patch=0 ;; minor) minor=$((minor + 1)) - path=0 + patch=0 ;; patch) - path=$((path + 1)) + patch=$((patch + 1)) ;; *) echo "Invalid bump type: $BUMP_TYPE. Use 'major', 'minor', or 'patch'." @@ -45,7 +45,7 @@ case "$BUMP_TYPE" in esac # Construct the new version string -new_version="${major}.${minor}.${path}" +new_version="${major}.${minor}.${patch}" # Set the new version using Poetry poetry version "$new_version" From b61f584c5ac8a885cce8d646debe233ba8615884 Mon Sep 17 00:00:00 2001 From: Nikhil Narayen Date: Thu, 13 Feb 2025 12:56:16 -0500 Subject: [PATCH 3/3] Add expected version numbers --- bin/bump_truss_version.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/bump_truss_version.sh b/bin/bump_truss_version.sh index 4a6881fa7..838a0f527 100755 --- a/bin/bump_truss_version.sh +++ b/bin/bump_truss_version.sh @@ -4,9 +4,9 @@ # and increments the major, minor, or patch version as specified. # # Usage: -# ./bump_version.sh 0.9.60 # bumps the patch (micro) version by default -# ./bump_version.sh 0.9.60 major # bumps the major version (resets minor and patch to 0) -# ./bump_version.sh 0.9.60 minor # bumps the minor version (resets patch to 0) +# ./bump_version.sh 0.9.60 # bumps the patch (micro) version by default -> 0.9.61 +# ./bump_version.sh 0.9.60 major # bumps the major version (resets minor and patch to 0) -> 1.0.0 +# ./bump_version.sh 0.9.60 minor # bumps the minor version (resets patch to 0) -> 0.10.0 set -euo pipefail