Set up version management system with version 0.1.0

This commit is contained in:
colin 2025-07-03 10:43:29 -04:00
parent 375774594a
commit e92e4f1df8
3 changed files with 62 additions and 21 deletions

View File

@ -1 +1 @@
1.0.0 0.1.0

View File

@ -7,9 +7,14 @@ from datetime import datetime
import generate_test_data import generate_test_data
import locale import locale
# Get version from VERSION file # Get version from environment variable or VERSION file
with open(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'VERSION'), 'r') as f: VERSION = os.environ.get('APP_VERSION')
VERSION = f.read().strip() if not VERSION:
try:
with open(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'VERSION'), 'r') as f:
VERSION = f.read().strip()
except:
VERSION = "unknown"
# Initialize the Flask app # Initialize the Flask app
app = Flask(__name__) app = Flask(__name__)
@ -55,7 +60,7 @@ def get_db_connection():
cursor_factory=RealDictCursor cursor_factory=RealDictCursor
) )
conn.autocommit = True conn.autocommit = True
print(f"Connected to PostgreSQL at {host}:{port}") print(f"Ploughshares v{VERSION} - Connected to PostgreSQL at {host}:{port}")
return conn return conn
except psycopg2.OperationalError as e: except psycopg2.OperationalError as e:
print(f"Error connecting to PostgreSQL: {e}") print(f"Error connecting to PostgreSQL: {e}")
@ -196,7 +201,7 @@ def bootstrap_database():
""" """
Checks if the database is empty and populates it with test data if it is. Checks if the database is empty and populates it with test data if it is.
""" """
print("Checking database for existing data...") print(f"Ploughshares v{VERSION} - Checking database for existing data...")
conn = get_db_connection() conn = get_db_connection()
if conn is None: if conn is None:
print("Database connection failed. Exiting.") print("Database connection failed. Exiting.")
@ -206,7 +211,7 @@ def bootstrap_database():
cur.execute("SELECT COUNT(*) FROM transactions") cur.execute("SELECT COUNT(*) FROM transactions")
count = cur.fetchone()['count'] count = cur.fetchone()['count']
if count == 0: if count == 0:
print("Database is empty. Populating with test data...") print(f"Ploughshares v{VERSION} - Database is empty. Populating with test data...")
test_data = generate_test_data.get_test_transactions() test_data = generate_test_data.get_test_transactions()
for transaction in test_data: for transaction in test_data:
cur.execute( cur.execute(
@ -225,9 +230,10 @@ def bootstrap_database():
transaction transaction
) )
conn.commit() conn.commit()
print("Successfully inserted 10 test transactions.") print(f"Ploughshares v{VERSION} - Successfully inserted 10 test transactions.")
conn.close() conn.close()
if __name__ == '__main__': if __name__ == '__main__':
print(f"Starting Ploughshares v{VERSION}")
port = int(os.environ.get('FLASK_RUN_PORT', 5001)) port = int(os.environ.get('FLASK_RUN_PORT', 5001))
app.run(host='0.0.0.0', port=port) app.run(host='0.0.0.0', port=port)

View File

@ -1,11 +1,12 @@
#!/bin/bash #!/bin/bash
# versionbump.sh - Script to bump version numbers in the VERSION file # versionbump.sh - Script to bump version numbers in the VERSION file and update all relevant files
# Usage: ./versionbump.sh [major|minor|patch] # Usage: ./versionbump.sh [major|minor|patch|set VERSION]
set -e set -e
VERSION_FILE="VERSION" VERSION_FILE="VERSION"
DOCKER_COMPOSE_FILE="docker-compose.yml"
# Check if VERSION file exists # Check if VERSION file exists
if [ ! -f "$VERSION_FILE" ]; then if [ ! -f "$VERSION_FILE" ]; then
@ -17,6 +18,44 @@ fi
CURRENT_VERSION=$(cat "$VERSION_FILE") CURRENT_VERSION=$(cat "$VERSION_FILE")
echo "Current version: $CURRENT_VERSION" 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"
exit 1
fi
NEW_VERSION="$2"
echo "Setting version to: $NEW_VERSION"
update_version_everywhere "$NEW_VERSION"
exit 0
fi
# Split version into components # Split version into components
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
@ -35,21 +74,17 @@ case "$1" in
PATCH=$((PATCH + 1)) PATCH=$((PATCH + 1))
;; ;;
*) *)
echo "Usage: $0 [major|minor|patch]" echo "Usage: $0 [major|minor|patch|set VERSION]"
echo "Example: $0 minor" echo "Examples:"
echo " $0 minor # Bump minor version"
echo " $0 set 1.2.3 # Set specific version"
exit 1 exit 1
;; ;;
esac esac
# Create new version string # Create new version string
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "New version: $NEW_VERSION" echo "Bumping to version: $NEW_VERSION"
# Update VERSION file # Update version in all necessary files
echo "$NEW_VERSION" > "$VERSION_FILE" update_version_everywhere "$NEW_VERSION"
echo "Updated $VERSION_FILE to $NEW_VERSION"
# Optional: Update other files that might need version updates
# Add commands here to update version in other files if needed
echo "Version bump complete!"