upskill-event-manager/wordpress-dev/bin/deploy-plugin.sh
bengizmo fd79b22c9b feat: Successfully create test user on staging and update test setup
- Troubleshooted and fixed issues with the plugin deployment script (`deploy-plugin.sh`) to ensure all necessary plugin files, including the main plugin file, are correctly transferred to the staging environment.
- Corrected a role name mismatch in the test user creation script (`setup-staging-test-users.sh`) to successfully create a test user with the `hvac_trainer` role on staging.
- Updated the E2E test runner script (`run-tests.sh`) to replace deprecated Docker commands with SSH commands targeting the staging environment and explicitly pass the staging URL to Playwright.
- Increased the global timeout and enabled retries in the Playwright configuration (`playwright.config.ts`) to aid in debugging test failures on the staging environment.
- Updated documentation files (`docs/mvp-integration-testing-plan.md`, `wordpress-dev/README.md`, and `wordpress-dev/MIGRATION_GUIDE.md`) to include instructions on setting up the test user for the staging environment and corrected section numbering in the testing plan.
2025-04-24 04:15:43 -03:00

130 lines
No EOL
3.9 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..."
# Change to project root before rsync
cd ../..
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' \
--include 'composer.json' \
--include 'composer.lock' \
--include 'hvac-community-events.php' \
--include 'phpunit.xml.dist' \
--include 'wp-tests-config.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
# Change back to original directory (optional, but good practice)
# cd -
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