- Add HVAC_Test_User_Factory class with: * User creation with specific roles * Multiple role support * Persona management system * Account cleanup integration - Create comprehensive test suite in HVAC_Test_User_Factory_Test.php - Update testing improvement plan documentation - Add implementation decisions to project memory bank - Restructure .gitignore with: * Whitelist approach for better file management * Explicit backup exclusions * Specific bin directory inclusions Part of the Account Management component from the testing framework improvement plan.
121 lines
No EOL
3.6 KiB
Bash
Executable file
121 lines
No EOL
3.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Deploy WordPress plugin to staging server with safety measures
|
|
# Enhanced version with path validation and dry-run option
|
|
|
|
# Load configuration file
|
|
if [ -z "$1" ]; then
|
|
echo "Usage: $0 --config <config_file> [--dry-run]"
|
|
exit 1
|
|
fi
|
|
|
|
DRY_RUN=false
|
|
|
|
while [ "$1" != "" ]; do
|
|
case $1 in
|
|
--config )
|
|
shift
|
|
if [ -z "$1" ]; then
|
|
echo "Error: --config requires a value"
|
|
exit 1
|
|
fi
|
|
CONFIG_FILE="$1"
|
|
shift
|
|
;;
|
|
--dry-run )
|
|
DRY_RUN=true
|
|
shift
|
|
;;
|
|
* )
|
|
echo "Error: Invalid argument: $1"
|
|
exit 1
|
|
esac
|
|
done
|
|
|
|
if [ ! -f "$CONFIG_FILE" ]; then
|
|
echo "Error: Configuration file not found: $CONFIG_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
source "$CONFIG_FILE"
|
|
|
|
# Check required variables
|
|
if [ -z "$REMOTE_HOST" ] || [ -z "$REMOTE_USER" ] || [ -z "$REMOTE_PATH_BASE" ] || [ -z "$PLUGIN_SLUG" ] || [ -z "$REMOTE_PLUGIN_PATH" ] || [ -z "$LOCAL_PLUGIN_PATH" ]; then
|
|
echo "Error: Missing required variables in configuration file."
|
|
exit 1
|
|
fi
|
|
|
|
# Validate paths to ensure we're only modifying plugin directory
|
|
if [[ "$REMOTE_PLUGIN_PATH" != *"/wp-content/plugins/$PLUGIN_SLUG"* ]]; then
|
|
echo "Error: Remote plugin path does not appear to be within the WordPress plugins directory."
|
|
echo "Expected path pattern: */wp-content/plugins/$PLUGIN_SLUG*"
|
|
echo "Actual path: $REMOTE_PLUGIN_PATH"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "$LOCAL_PLUGIN_PATH" != *"/wp-content/plugins/$PLUGIN_SLUG"* ]]; then
|
|
echo "Error: Local plugin path does not appear to be within the WordPress plugins directory."
|
|
echo "Expected path pattern: */wp-content/plugins/$PLUGIN_SLUG*"
|
|
echo "Actual path: $LOCAL_PLUGIN_PATH"
|
|
exit 1
|
|
fi
|
|
|
|
# Create backup of plugin directory on staging server
|
|
echo "Creating backup of plugin directory on staging server..."
|
|
if [ "$DRY_RUN" = false ]; then
|
|
ssh "$REMOTE_USER@$REMOTE_HOST" "if [ -d \"$REMOTE_PLUGIN_PATH\" ]; then cp -r \"$REMOTE_PLUGIN_PATH\" \"${REMOTE_PLUGIN_PATH}_backup_$(date +%Y%m%d%H%M%S)\"; fi"
|
|
if [ $? -ne 0 ]; then
|
|
echo "Warning: Failed to create backup on staging server."
|
|
fi
|
|
else
|
|
echo "[DRY RUN] Would execute: ssh \"$REMOTE_USER@$REMOTE_HOST\" \"if [ -d \\\"$REMOTE_PLUGIN_PATH\\\" ]; then cp -r \\\"$REMOTE_PLUGIN_PATH\\\" \\\"${REMOTE_PLUGIN_PATH}_backup_$(date +%Y%m%d%H%M%S)\\\"; fi\""
|
|
fi
|
|
|
|
# Rsync the plugin files
|
|
echo "Deploying plugin $PLUGIN_SLUG to staging server..."
|
|
RSYNC_CMD="rsync -avz --delete \
|
|
--exclude '.git' \
|
|
--exclude 'node_modules' \
|
|
--include 'tests/' \
|
|
--include 'tests/unit/' \
|
|
--include 'tests/unit/*.php' \
|
|
--include 'tests/test-doubles.php' \
|
|
--include 'tests/bootstrap.php' \
|
|
\"$LOCAL_PLUGIN_PATH\" \
|
|
\"$REMOTE_USER@$REMOTE_HOST:$REMOTE_PLUGIN_PATH\""
|
|
|
|
if [ "$DRY_RUN" = true ]; then
|
|
echo "[DRY RUN] Would execute: $RSYNC_CMD"
|
|
else
|
|
eval $RSYNC_CMD
|
|
if [ $? -ne 0 ]; then
|
|
echo "Error: rsync failed."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo "Plugin deployment completed successfully."
|
|
|
|
# Optional: Install Composer dependencies on staging
|
|
echo "Installing Composer dependencies on staging server..."
|
|
if [ "$DRY_RUN" = true ]; then
|
|
echo "[DRY RUN] Would execute: ssh \"$REMOTE_USER@$REMOTE_HOST\" \"cd $REMOTE_PLUGIN_PATH && composer install\""
|
|
else
|
|
ssh "$REMOTE_USER@$REMOTE_HOST" "cd $REMOTE_PLUGIN_PATH && composer install"
|
|
if [ $? -ne 0 ]; then
|
|
echo "Warning: Composer installation failed."
|
|
fi
|
|
fi
|
|
|
|
# Verify deployment
|
|
echo "Verifying deployment..."
|
|
if [ "$DRY_RUN" = true ]; then
|
|
echo "[DRY RUN] Would execute: ssh \"$REMOTE_USER@$REMOTE_HOST\" \"ls -la $REMOTE_PLUGIN_PATH\""
|
|
else
|
|
ssh "$REMOTE_USER@$REMOTE_HOST" "ls -la $REMOTE_PLUGIN_PATH"
|
|
if [ $? -ne 0 ]; then
|
|
echo "Warning: Verification failed."
|
|
fi
|
|
fi
|
|
|
|
exit 0 |