diff --git a/.changeset/cool-shirts-reflect.md b/.changeset/cool-shirts-reflect.md new file mode 100644 index 0000000..b8879ad --- /dev/null +++ b/.changeset/cool-shirts-reflect.md @@ -0,0 +1,5 @@ +--- +"@wpengine/site-deploy": patch +--- + +[CICD-761] Actually fix excludes.txt, removes out relative folder pathing diff --git a/Makefile b/Makefile index 6206910..2f785df 100644 --- a/Makefile +++ b/Makefile @@ -22,5 +22,11 @@ version: build docker image tag $(IMAGE) $(IMAGE_NAME):v$(MAJOR_VERSION).$(MINOR_VERSION) && \ docker image tag $(IMAGE) $(IMAGE_NAME):v$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION) -test: +test-unit: ./tests/test_functions.sh + +test-integration: + # TODO: Currently commenting out the integration tests as they are not ready yet + # this was setup for the relative remote work, and is not currently working with + # testing sync_files function. + # docker compose up test diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f48c92e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +services: + test: + build: + context: . + dockerfile: Dockerfile + image: wpengine/site-deploy:latest + platform: linux/amd64 + entrypoint: /tests/test-make-relative-remote/test.sh + #connects local directory to container directory + volumes: + - ./tests/workspace:/workspace + - ./tests:/tests + depends_on: + - build + + build: + image: wpengine/site-deploy:latest + build: + context: . + dockerfile: Dockerfile + command: /bin/true diff --git a/exclude.txt b/exclude.txt index 9d376d4..ddc9548 100644 --- a/exclude.txt +++ b/exclude.txt @@ -18,17 +18,17 @@ Thumbs.db # NOTE: # These files are excluded from the deploy so as to prevent unwanted errors from occurring, # such as accidentally deploying a local version of wp-config.php or accidentally deleting -# wp-content/uploads/ if a --delete flag is passed while deploying root. Most paths here +# uploads/ if a --delete flag is passed while deploying root. Most paths here # are ingnored in the WPE sample .gitignore per best practice. wp-config.php -wp-content/uploads/ -wp-content/blogs.dir/ -wp-content/upgrade/* -wp-content/backup-db/* -wp-content/advanced-cache.php -wp-content/wp-cache-config.php -wp-content/cache/* -wp-content/cache/supercache/* +uploads/ +blogs.dir/ +upgrade/* +backup-db/* +advanced-cache.php +wp-cache-config.php +cache/* +cache/supercache/* # WP Engine specific files # NOTE: @@ -44,20 +44,20 @@ wp-content/cache/supercache/* .wpe-devkit/ .wpengine-conf/ _wpeprivate -wp-content/object-cache.php -wp-content/mu-plugins/mu-plugin.php -wp-content/mu-plugins/slt-force-strong-passwords.php -wp-content/mu-plugins/wpengine-security-auditor.php -wp-content/mu-plugins/stop-long-comments.php -wp-content/mu-plugins/force-strong-passwords* -wp-content/mu-plugins/wpengine-common* -wp-content/mu-plugins/wpe-wp-sign-on-plugin* -wp-content/mu-plugins/wpe-elasticpress-autosuggest-logger* -wp-content/mu-plugins/wpe-cache-plugin* -wp-content/mu-plugins/wp-cache-memcached* -wp-content/drop-ins/ -wp-content/drop-ins/wp-cache-memcached* -wp-content/mysql.sql +object-cache.php +mu-plugin.php +slt-force-strong-passwords.php +wpengine-security-auditor.php +stop-long-comments.php +force-strong-passwords* +wpengine-common* +wpe-wp-sign-on-plugin* +wpe-elasticpress-autosuggest-logger* +wpe-cache-plugin* +wp-cache-memcached* +drop-ins/ +drop-ins/wp-cache-memcached* +mysql.sql # Local specific -wp-content/mu-plugins/local-by-flywheel-live-link-helper.php +local-by-flywheel-live-link-helper.php diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..b39f5aa --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +workspace/**/* diff --git a/tests/test-make-relative-remote/data/repository-3/mu-plugins/.gitkeep b/tests/test-make-relative-remote/data/repository-3/mu-plugins/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test-make-relative-remote/data/repository-3/plugins/sample_plugin.txt b/tests/test-make-relative-remote/data/repository-3/plugins/sample_plugin.txt new file mode 100644 index 0000000..34404e5 --- /dev/null +++ b/tests/test-make-relative-remote/data/repository-3/plugins/sample_plugin.txt @@ -0,0 +1 @@ +Sample plugin file diff --git a/tests/test-make-relative-remote/data/repository-3/themes/sample_theme.txt b/tests/test-make-relative-remote/data/repository-3/themes/sample_theme.txt new file mode 100644 index 0000000..b8ed081 --- /dev/null +++ b/tests/test-make-relative-remote/data/repository-3/themes/sample_theme.txt @@ -0,0 +1 @@ +Sample theme file diff --git a/tests/test-make-relative-remote/data/repository-3/uploads/sample_upload.txt b/tests/test-make-relative-remote/data/repository-3/uploads/sample_upload.txt new file mode 100644 index 0000000..e946a2e --- /dev/null +++ b/tests/test-make-relative-remote/data/repository-3/uploads/sample_upload.txt @@ -0,0 +1 @@ +Sample upload file diff --git a/tests/test-make-relative-remote/data/repository-4/themes/beautiful-pro/sample_theme.txt b/tests/test-make-relative-remote/data/repository-4/themes/beautiful-pro/sample_theme.txt new file mode 100644 index 0000000..b8ed081 --- /dev/null +++ b/tests/test-make-relative-remote/data/repository-4/themes/beautiful-pro/sample_theme.txt @@ -0,0 +1 @@ +Sample theme file diff --git a/tests/test-make-relative-remote/data/repository-5/my-awesome-plugins/elwood-plugin/dry-white-toast.txt b/tests/test-make-relative-remote/data/repository-5/my-awesome-plugins/elwood-plugin/dry-white-toast.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/test-make-relative-remote/data/repository-5/my-awesome-plugins/jake-plugin/four-whole-fried-chickens.txt b/tests/test-make-relative-remote/data/repository-5/my-awesome-plugins/jake-plugin/four-whole-fried-chickens.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/test-make-relative-remote/data/repository-6/my-awesome-plugins/blues-brothers/elwood-plugin/dry-white-toast.txt b/tests/test-make-relative-remote/data/repository-6/my-awesome-plugins/blues-brothers/elwood-plugin/dry-white-toast.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/test-make-relative-remote/data/repository-6/my-awesome-plugins/blues-brothers/jake-plugin/four-whole-fried-chickens.txt b/tests/test-make-relative-remote/data/repository-6/my-awesome-plugins/blues-brothers/jake-plugin/four-whole-fried-chickens.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/test-make-relative-remote/test.sh b/tests/test-make-relative-remote/test.sh new file mode 100755 index 0000000..7889511 --- /dev/null +++ b/tests/test-make-relative-remote/test.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# Get the directory of the current script +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${SCRIPT_DIR}/../common.sh" +source "${SCRIPT_DIR}/../../functions.sh" +source "${SCRIPT_DIR}/../../entrypoint.sh" + +setup() { + rm -rf /workspace/* + local test_data_dir="${SCRIPT_DIR}/data/repository-${1}/" + if [[ -d "${test_data_dir}" ]]; then + # Works like GitHub action, checking out the workspace directory + cp -r "${test_data_dir}"* /workspace/ + fi + ssh-keygen -t rsa -b 2048 -f /workspace/mock_ssh_key -N "" + chmod 600 /workspace/mock_ssh_key + + cd /workspace +} + +# Test resulting directory structure from calling sync_files +test_sync_files() { + setup "$1" + SRC_PATH=$2 + REMOTE_PATH=$3 + + WPE_SSHG_KEY_PRIVATE=$(cat /workspace/mock_ssh_key) + + echo -e "${GREEN}REMOTE_PATH='$REMOTE_PATH' SRC_PATH='$SRC_PATH'${NC}" + + # Assign flag values to FLAGS_ARRAY + FLAGS_ARRAY=("-azvr" "--dry-run" "--inplace" "--exclude='.*'") + + # Print the flags for debugging + echo "Using the following rsync flags:" + for flag in "${FLAGS_ARRAY[@]}"; do + echo "$flag" + done + + sync_files + + # Only compare the expected directory structure if REMOTE_PATH is not empty and REMOTE_PATH is not equal to SRC_PATH + if [[ -n "$REMOTE_PATH" && "$REMOTE_PATH" != "$SRC_PATH" ]]; then + # Verify that REMOTE_PATH and its folders exist in /workspace + if [ -d "/workspace/$REMOTE_PATH" ]; then + echo -e "${GREEN}REMOTE_PATH exists in /workspace${NC}" + + # Compare the contents of the moved REMOTE_PATH to the corresponding files in the data directory + EXPECTED_PATH="${SCRIPT_DIR}/data/repository-${1}/$SRC_PATH" + diff -r "/workspace/$REMOTE_PATH" "$EXPECTED_PATH" + + # Check the result of the diff command + if [[ $? -ne 0 ]]; then + echo -e "${RED}Verification failed: expected structure does not match.${NC}" + else + echo -e "${GREEN}Verification passed: expected structure matches.${NC}" + fi + else + echo -e "${RED}Verification failed: REMOTE_PATH does not exist in /workspace.${NC}" + fi + else + echo -e "${YELLOW}REMOTE_PATH is empty or equal to SRC_PATH, skipping comparison.${NC}" + fi +} + +# Test cases, make remote directory relative to to the tests directory +#test_sync_files "1" "." "" +#test_sync_files "2" "./wp-content" "./wp-content" +#test_sync_files "3" "." "wp-content/" +#test_sync_files "4" "." "wp-content/themes/beautiful-pro" +#test_sync_files "5" "my-awesome-plugins" "wp-content/plugins" +#test_sync_files "6" "my-awesome-plugins/blues-brothers" "wp-content/plugins"