#!/bin/bash # Define the default increment type (patch if not provided) INCREMENT_TYPE=${1:-patch} # Read the current version from .env if ! grep -q "^APP_VERSION=" .env; then echo "APP_VERSION=$(date +'%y.%m')-0.1.0" >> .env fi CURRENT_VERSION=$(grep "^APP_VERSION=" .env | cut -d '=' -f2) # Extract parts of the version IFS='.-' read -r YY MM MAJOR MINOR PATCH <<< "$CURRENT_VERSION" # Get the current date-based prefix CURRENT_YY=$(date +'%y') CURRENT_MM=$(date +'%m') # If the month changes, reset the version if [[ "$YY" != "$CURRENT_YY" || "$MM" != "$CURRENT_MM" ]]; then MAJOR=0 MINOR=1 PATCH=0 else # Increment version based on type if [[ "$INCREMENT_TYPE" == "major" ]]; then ((MAJOR++)) MINOR=0 PATCH=0 elif [[ "$INCREMENT_TYPE" == "minor" ]]; then ((MINOR++)) PATCH=0 else ((PATCH++)) fi fi # Generate new version NEW_VERSION="$CURRENT_YY.$CURRENT_MM-$MAJOR.$MINOR.$PATCH" # Update the .env file sed -i "s/^APP_VERSION=.*/APP_VERSION=$NEW_VERSION/" .env echo "Updated .env APP_VERSION to $NEW_VERSION"