Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix release script, derive current version from pypi #1393

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/create_release_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ jobs:
run: |
curl -sSL https://install.python-poetry.org | python3 -

- name: Get current Truss version
Copy link
Contributor Author

@nnarayen nnarayen Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fetch the latest stable release (ignores rcs), regardless of yank status which is actually what we want. Therefore, it should be safe to rely on this as the current version number to bump from.

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: |
Expand All @@ -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 }}
28 changes: 13 additions & 15 deletions bin/bump_truss_version.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
#!/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 -> 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

# 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 <current_version> [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"
Expand Down
Loading