Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CICD-761] Actually fix excludes #39

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cool-shirts-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/site-deploy": patch
---

[CICD-761] Actually fix excludes.txt, removes out relative folder pathing
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
48 changes: 24 additions & 24 deletions exclude.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace/**/*
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample plugin file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample theme file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample upload file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample theme file
74 changes: 74 additions & 0 deletions tests/test-make-relative-remote/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash
Copy link
Member Author

@cseeman cseeman Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try removing this commit, delete tests/ structure and integration test and add the removal commit on a graveyward.md for future reference, including docker compose file.


# 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"
Loading