Set up version management system with version 0.1.0
This commit is contained in:
parent
375774594a
commit
e92e4f1df8
|
@ -7,9 +7,14 @@ from datetime import datetime
|
|||
import generate_test_data
|
||||
import locale
|
||||
|
||||
# Get version from VERSION file
|
||||
with open(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'VERSION'), 'r') as f:
|
||||
VERSION = f.read().strip()
|
||||
# Get version from environment variable or VERSION file
|
||||
VERSION = os.environ.get('APP_VERSION')
|
||||
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
|
||||
app = Flask(__name__)
|
||||
|
@ -55,7 +60,7 @@ def get_db_connection():
|
|||
cursor_factory=RealDictCursor
|
||||
)
|
||||
conn.autocommit = True
|
||||
print(f"Connected to PostgreSQL at {host}:{port}")
|
||||
print(f"Ploughshares v{VERSION} - Connected to PostgreSQL at {host}:{port}")
|
||||
return conn
|
||||
except psycopg2.OperationalError as 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.
|
||||
"""
|
||||
print("Checking database for existing data...")
|
||||
print(f"Ploughshares v{VERSION} - Checking database for existing data...")
|
||||
conn = get_db_connection()
|
||||
if conn is None:
|
||||
print("Database connection failed. Exiting.")
|
||||
|
@ -206,7 +211,7 @@ def bootstrap_database():
|
|||
cur.execute("SELECT COUNT(*) FROM transactions")
|
||||
count = cur.fetchone()['count']
|
||||
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()
|
||||
for transaction in test_data:
|
||||
cur.execute(
|
||||
|
@ -225,9 +230,10 @@ def bootstrap_database():
|
|||
transaction
|
||||
)
|
||||
conn.commit()
|
||||
print("Successfully inserted 10 test transactions.")
|
||||
print(f"Ploughshares v{VERSION} - Successfully inserted 10 test transactions.")
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f"Starting Ploughshares v{VERSION}")
|
||||
port = int(os.environ.get('FLASK_RUN_PORT', 5001))
|
||||
app.run(host='0.0.0.0', port=port)
|
|
@ -1,11 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
# versionbump.sh - Script to bump version numbers in the VERSION file
|
||||
# Usage: ./versionbump.sh [major|minor|patch]
|
||||
# versionbump.sh - Script to bump version numbers in the VERSION file and update all relevant files
|
||||
# Usage: ./versionbump.sh [major|minor|patch|set VERSION]
|
||||
|
||||
set -e
|
||||
|
||||
VERSION_FILE="VERSION"
|
||||
DOCKER_COMPOSE_FILE="docker-compose.yml"
|
||||
|
||||
# Check if VERSION file exists
|
||||
if [ ! -f "$VERSION_FILE" ]; then
|
||||
|
@ -17,6 +18,44 @@ fi
|
|||
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"
|
||||
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"
|
||||
|
||||
|
@ -35,21 +74,17 @@ case "$1" in
|
|||
PATCH=$((PATCH + 1))
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [major|minor|patch]"
|
||||
echo "Example: $0 minor"
|
||||
echo "Usage: $0 [major|minor|patch|set VERSION]"
|
||||
echo "Examples:"
|
||||
echo " $0 minor # Bump minor version"
|
||||
echo " $0 set 1.2.3 # Set specific version"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Create new version string
|
||||
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
|
||||
echo "New version: $NEW_VERSION"
|
||||
echo "Bumping to version: $NEW_VERSION"
|
||||
|
||||
# Update VERSION file
|
||||
echo "$NEW_VERSION" > "$VERSION_FILE"
|
||||
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!"
|
||||
# Update version in all necessary files
|
||||
update_version_everywhere "$NEW_VERSION"
|
Loading…
Reference in New Issue