|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Script to bump version in pyproject.toml |
| 4 | +# Usage: ./bump_version.sh <new_version> |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +# Check if version argument is provided |
| 9 | +if [ $# -eq 0 ]; then |
| 10 | + echo "Error: No version specified" |
| 11 | + echo "Usage: $0 <new_version>" |
| 12 | + echo "Examples: $0 1.2.3, $0 1.2.3a1, $0 1.2.3b2, $0 1.2.3rc1, $0 1.2.3.post1, $0 1.2.3.dev1" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +NEW_VERSION="$1" |
| 17 | + |
| 18 | +# Validate version format (Python PEP 440 compliant) |
| 19 | +if ! echo "$NEW_VERSION" | grep -E '^[0-9]+(\.[0-9]+)*((a|b|rc)[0-9]+)?(\.post[0-9]+)?(\.dev[0-9]+)?$' > /dev/null; then |
| 20 | + echo "Error: Invalid version format" |
| 21 | + echo "Version should follow PEP 440 (e.g., 1.2.3, 1.2.3a1, 1.2.3b2, 1.2.3rc1, 1.2.3.post1, 1.2.3.dev1)" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +# Get the directory where the script is located |
| 26 | +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 27 | +PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )" |
| 28 | +PYPROJECT_FILE="$PROJECT_ROOT/pyproject.toml" |
| 29 | + |
| 30 | +# Check if pyproject.toml exists |
| 31 | +if [ ! -f "$PYPROJECT_FILE" ]; then |
| 32 | + echo "Error: pyproject.toml not found at $PYPROJECT_FILE" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +# Get current version |
| 37 | +CURRENT_VERSION=$(grep '^version = ' "$PYPROJECT_FILE" | sed 's/version = "\(.*\)"/\1/') |
| 38 | + |
| 39 | +if [ -z "$CURRENT_VERSION" ]; then |
| 40 | + echo "Error: Could not find current version in pyproject.toml" |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | + |
| 44 | +echo "Current version: $CURRENT_VERSION" |
| 45 | +echo "New version: $NEW_VERSION" |
| 46 | + |
| 47 | +# Update version in pyproject.toml |
| 48 | +sed -i.bak "s/^version = \".*\"/version = \"$NEW_VERSION\"/" "$PYPROJECT_FILE" |
| 49 | + |
| 50 | +# Remove backup file |
| 51 | +rm -f "$PYPROJECT_FILE.bak" |
| 52 | + |
| 53 | +echo "Successfully bumped version from $CURRENT_VERSION to $NEW_VERSION" |
| 54 | + |
| 55 | +# Update __init__.py if it exists with version |
| 56 | +INIT_FILE="$PROJECT_ROOT/agentlightning/__init__.py" |
| 57 | +if [ -f "$INIT_FILE" ]; then |
| 58 | + if grep -q "__version__" "$INIT_FILE"; then |
| 59 | + sed -i.bak "s/__version__ = \".*\"/__version__ = \"$NEW_VERSION\"/" "$INIT_FILE" |
| 60 | + rm -f "$INIT_FILE.bak" |
| 61 | + echo "Updated version in $INIT_FILE" |
| 62 | + fi |
| 63 | +fi |
| 64 | + |
| 65 | +echo "Version bump complete!" |
0 commit comments