Skip to content

Commit c5bff71

Browse files
committed
feat: add version management and integration checks for PHP Booster
1 parent ce3c30c commit c5bff71

File tree

2 files changed

+159
-3
lines changed

2 files changed

+159
-3
lines changed

booster/integrate_booster.sh

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,67 @@ export COMPOSER_MEMORY_LIMIT=-1
3030
# This automatically accepts all recipes from both main and contrib repositories
3131
export SYMFONY_FLEX_RECIPES_AUTO_ACCEPT=1
3232

33+
# --- Version Management ---
34+
35+
# Extract version from booster composer.json
36+
function get_booster_version() {
37+
local booster_composer="${BOOSTER_INTERNAL_PATH}/composer.json"
38+
if [ -f "$booster_composer" ]; then
39+
jq -r '.version // "unknown"' "$booster_composer"
40+
else
41+
echo "unknown"
42+
fi
43+
}
44+
45+
# Get the currently installed booster version
46+
function get_installed_version() {
47+
local version_file=".booster-version"
48+
if [ -f "$version_file" ]; then
49+
grep "^VERSION=" "$version_file" 2>/dev/null | cut -d'=' -f2 || echo ""
50+
else
51+
echo ""
52+
fi
53+
}
54+
55+
# Create or update the version stamp file
56+
function create_version_stamp() {
57+
local version="$1"
58+
local version_file=".booster-version"
59+
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
60+
61+
cat > "$version_file" << EOF
62+
# PHP Booster Version Stamp
63+
# This file tracks which booster version was integrated into this project
64+
# Generated by integrate_booster.sh
65+
66+
VERSION=$version
67+
INSTALLED_DATE=$timestamp
68+
INTEGRATION_METHOD=script
69+
EOF
70+
71+
log "Created version stamp: $version (installed $timestamp)"
72+
}
73+
74+
# Show version information and upgrade status
75+
function show_version_info() {
76+
local current_version="$1"
77+
local installed_version
78+
installed_version=$(get_installed_version)
79+
80+
if [ -n "$installed_version" ]; then
81+
echo -e "${GREEN}[INFO]${NC} Previous booster installation detected: $installed_version"
82+
echo -e "${GREEN}[INFO]${NC} Current booster version: $current_version"
83+
84+
if [ "$installed_version" != "$current_version" ]; then
85+
echo -e "${YELLOW}[UPGRADE]${NC} This will upgrade your booster from $installed_version to $current_version"
86+
else
87+
echo -e "${GREEN}[INFO]${NC} Re-integrating same version (idempotent operation)"
88+
fi
89+
else
90+
echo -e "${GREEN}[INFO]${NC} Installing PHP Booster version: $current_version"
91+
fi
92+
}
93+
3394
# --- Helper Functions ---
3495

3596
function log() {
@@ -847,15 +908,78 @@ EOF
847908
success "Nginx configuration updated with XDEBUG_TRIGGER."
848909
}
849910

911+
# Display help information
912+
function show_help() {
913+
echo "PHP Booster Integration Script"
914+
echo ""
915+
echo "USAGE:"
916+
echo " $0 [OPTIONS]"
917+
echo ""
918+
echo "OPTIONS:"
919+
echo " -v Enable verbose logging"
920+
echo " -c Skip cleanup (preserve temporary files for debugging)"
921+
echo " -i Show version information and exit"
922+
echo " -h Show this help message and exit"
923+
echo ""
924+
echo "DESCRIPTION:"
925+
echo " Integrates PHP Booster tooling into an existing PHP project."
926+
echo " Supports both standard PHP projects and DDEV environments."
927+
echo ""
928+
echo "EXAMPLES:"
929+
echo " $0 # Run integration with default settings"
930+
echo " $0 -v # Run with verbose output"
931+
echo " $0 -i # Show version information"
932+
echo ""
933+
echo "ENVIRONMENT VARIABLES:"
934+
echo " BOOSTER_LOCAL_DEV=1 # Use local booster directory instead of GitHub"
935+
echo " BOOSTER_LOCAL_PATH # Path to local booster (default: ../booster)"
936+
}
937+
938+
# Show version information and exit
939+
function show_version_info_and_exit() {
940+
echo "PHP Booster Integration Script"
941+
echo ""
942+
943+
# Try to get installed version first
944+
local installed_version
945+
installed_version=$(get_installed_version)
946+
947+
if [ -n "$installed_version" ]; then
948+
echo "Installed version: $installed_version"
949+
if [ -f ".booster-version" ]; then
950+
echo "Installation details:"
951+
grep -E "^(INSTALLED_DATE|INTEGRATION_METHOD)=" ".booster-version" 2>/dev/null | sed 's/^/ /' || true
952+
fi
953+
else
954+
echo "No booster installation detected in current directory"
955+
fi
956+
957+
echo ""
958+
# Try to get available version, but handle errors gracefully
959+
local available_version
960+
available_version=$(get_booster_version 2>/dev/null || echo "unknown")
961+
if [ "$available_version" = "unknown" ]; then
962+
echo "Available version: unknown (booster not downloaded yet)"
963+
echo "Run without -i to integrate and see available version"
964+
else
965+
echo "Available version (will be installed): $available_version"
966+
fi
967+
echo ""
968+
echo "To integrate or upgrade, run: $0"
969+
exit 0
970+
}
971+
850972
# --- Main Execution ---
851973

852974
function main() {
853975

854-
while getopts ":vc" opt; do
976+
while getopts ":vchi" opt; do
855977
case $opt in
856978
v) VERBOSE=true ;;
857979
c) NO_CLEANUP=true ;;
858-
\?) error "Invalid option: -$OPTARG" ;;
980+
h) show_help; exit 0 ;;
981+
i) show_version_info_and_exit ;;
982+
\?) error "Invalid option: -$OPTARG. Use -h for help." ;;
859983
:) error "Option -$OPTARG requires an argument." ;;
860984
esac
861985
done
@@ -877,6 +1001,11 @@ function main() {
8771001
check_dependencies
8781002
download_php_booster
8791003

1004+
# --- Version Management ---
1005+
local current_version
1006+
current_version=$(get_booster_version)
1007+
show_version_info "$current_version"
1008+
8801009
copy_files
8811010
update_package_json
8821011
update_readme
@@ -904,6 +1033,10 @@ function main() {
9041033
fi
9051034

9061035
add_code_quality_tools # Merges composer scripts & installs deps
1036+
1037+
# --- Create Version Stamp ---
1038+
create_version_stamp "$current_version"
1039+
9071040
success "Integration process completed."
9081041

9091042
if [ $IS_DDEV_PROJECT -eq 1 ]; then

tools/internal-test/test-integration.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,29 @@ def is_ddev_running(self) -> bool:
137137

138138
def is_booster_integrated(self) -> bool:
139139
"""Check if booster has been integrated"""
140+
# Primary check: version stamp file (most reliable indicator)
141+
version_stamp = self.config.target_dir / ".booster-version"
142+
if version_stamp.exists():
143+
return True
144+
145+
# Fallback check: essential booster files
140146
return (self.config.target_dir / "tools/commit-utils.py").exists() and (
141147
self.config.target_dir / "tools/runner.sh"
142148
).exists()
143149

150+
def get_integrated_version(self) -> Optional[str]:
151+
"""Get the currently integrated booster version"""
152+
version_stamp = self.config.target_dir / ".booster-version"
153+
if version_stamp.exists():
154+
try:
155+
content = version_stamp.read_text()
156+
for line in content.splitlines():
157+
if line.startswith("VERSION="):
158+
return line.split("=", 1)[1]
159+
except Exception as e:
160+
self.log.warn(f"Failed to read version stamp: {e}")
161+
return None
162+
144163
def has_git_hooks(self) -> bool:
145164
"""Check if git hooks are installed"""
146165
# Check for both traditional git hooks and Husky hooks
@@ -178,7 +197,11 @@ def show_status(self):
178197
self.log.warn("⚠️ DDEV not running")
179198

180199
if self.is_booster_integrated():
181-
self.log.success("✅ Booster integrated")
200+
version = self.get_integrated_version()
201+
if version:
202+
self.log.success(f"✅ Booster integrated (version {version})")
203+
else:
204+
self.log.success("✅ Booster integrated")
182205
else:
183206
self.log.warn("⚠️ Booster not integrated")
184207

0 commit comments

Comments
 (0)