#!/bin/bash # versionbump.sh - Script to bump version numbers in the VERSION file and update all relevant files # Usage: ./versionbump.sh [major|minor|patch|set VERSION|--help|-h] set -e VERSION_FILE="VERSION" DOCKER_COMPOSE_FILE="docker-compose.yml" # Function to display help information show_help() { cat << EOF Ploughshares Version Management Tool =================================== USAGE: ./versionbump.sh [COMMAND] COMMANDS: major Bump the major version (X.y.z -> X+1.0.0) minor Bump the minor version (x.Y.z -> x.Y+1.0) patch Bump the patch version (x.y.Z -> x.y.Z+1) set VERSION Set the version to a specific value (e.g., set 1.2.3) --help, -h Display this help message DESCRIPTION: This script manages the version number for the Ploughshares application. It updates the version in multiple locations: 1. The VERSION file (source of truth) 2. Console log messages in app.py 3. Docker Compose environment variables After running this script, you need to rebuild and restart the application for the changes to take effect. EXAMPLES: ./versionbump.sh major # 1.2.3 -> 2.0.0 ./versionbump.sh minor # 1.2.3 -> 1.3.0 ./versionbump.sh patch # 1.2.3 -> 1.2.4 ./versionbump.sh set 1.5.0 # Set to specific version 1.5.0 VERSION HISTORY: The script maintains a log of version changes in version_history.log EOF } # Check if help is requested or no arguments provided if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ -z "$1" ]; then show_help exit 0 fi # Check if VERSION file exists if [ ! -f "$VERSION_FILE" ]; then echo "Error: $VERSION_FILE does not exist." echo "Run with --help for usage information." exit 1 fi # Read current version CURRENT_VERSION=$(cat "$VERSION_FILE") echo "Current version: $CURRENT_VERSION" # Function to update version in all necessary files update_version_everywhere() { NEW_VERSION=$1 # 1. Update VERSION file echo "$NEW_VERSION" > "$VERSION_FILE" echo "Updated $VERSION_FILE to $NEW_VERSION" # 2. Log the version change echo "$(date): Version changed from $CURRENT_VERSION to $NEW_VERSION" >> version_history.log # 3. Update version in console log messages # This ensures the version is visible in logs when the app starts sed -i.bak "s/print(f\"Connected to PostgreSQL at/print(f\"Ploughshares v$NEW_VERSION - Connected to PostgreSQL at/" docker/ploughshares/app.py rm -f docker/ploughshares/app.py.bak echo "Updated version in app.py console logs" # 4. Update version in docker-compose.yml sed -i.bak "s/APP_VERSION=.*/APP_VERSION=$NEW_VERSION/" "$DOCKER_COMPOSE_FILE" rm -f "$DOCKER_COMPOSE_FILE.bak" echo "Updated version in $DOCKER_COMPOSE_FILE" echo "Version update complete! New version: $NEW_VERSION" echo "Remember to rebuild and restart the application for changes to take effect." } # Process command if [ "$1" = "set" ]; then if [ -z "$2" ]; then echo "Error: No version specified. Usage: $0 set VERSION" echo "Run with --help for usage information." exit 1 fi NEW_VERSION="$2" echo "Setting version to: $NEW_VERSION" update_version_everywhere "$NEW_VERSION" exit 0 fi # Split version into components IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" # Check which part to bump case "$1" in major) MAJOR=$((MAJOR + 1)) MINOR=0 PATCH=0 ;; minor) MINOR=$((MINOR + 1)) PATCH=0 ;; patch) PATCH=$((PATCH + 1)) ;; *) echo "Error: Unknown command '$1'" echo "Run with --help for usage information." exit 1 ;; esac # Create new version string NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" echo "Bumping to version: $NEW_VERSION" # Update version in all necessary files update_version_everywhere "$NEW_VERSION"