#!/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. Docker Compose environment variables The web UI and application will automatically read the version from the VERSION file at the root of the repository. 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 docker-compose.yml # Add APP_VERSION environment variable if it doesn't exist if ! grep -q "APP_VERSION=" "$DOCKER_COMPOSE_FILE"; then # Find the environment section for the app service LINE_NUM=$(grep -n "environment:" "$DOCKER_COMPOSE_FILE" | head -1 | cut -d: -f1) if [ -n "$LINE_NUM" ]; then # Insert APP_VERSION after the environment line sed -i.bak "${LINE_NUM}a\\ - APP_VERSION=$NEW_VERSION" "$DOCKER_COMPOSE_FILE" echo "Added APP_VERSION=$NEW_VERSION to $DOCKER_COMPOSE_FILE" else echo "Warning: Could not find environment section in $DOCKER_COMPOSE_FILE" fi else # Update existing APP_VERSION sed -i.bak "s/APP_VERSION=.*/APP_VERSION=$NEW_VERSION/" "$DOCKER_COMPOSE_FILE" echo "Updated APP_VERSION in $DOCKER_COMPOSE_FILE" fi rm -f "$DOCKER_COMPOSE_FILE.bak" 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"