Skip to content
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 Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libsqlite3-dev \
libonig-dev \
locales \
nodejs \
npm \
unzip \
git \
&& sed -i 's/# en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen \
Expand All @@ -20,6 +22,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# Install Composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

# Install Playground CLI for WordPress integration smoke tests.
RUN npm install -g @wp-playground/cli@latest

WORKDIR /app

# Install dependencies first (cached layer for faster rebuilds)
Expand Down
3 changes: 2 additions & 1 deletion bin/run-server-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ npx @wp-playground/cli@latest \
--mount=`pwd`/plugins/static-files-editor:/wordpress/wp-content/plugins/static-files-editor \
--mount=`pwd`/plugins/url-updater:/wordpress/wp-content/plugins/url-updater \
--mount=`pwd`/plugins/git-repo:/wordpress/wp-content/plugins/git-repo \
--mount=`pwd`/plugins/wp-origin:/wordpress/wp-content/plugins/wp-origin \
--mount=`pwd`/.my-notes-git:/wordpress/wp-content/uploads \
--blueprint=./blueprint-dev.json
--blueprint=./blueprint-dev.json
4 changes: 4 additions & 0 deletions bin/test-git-cli-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eu

docker compose run --rm sandbox vendor/bin/phpunit components/Git/Tests/GitCliEndToEndTest.php
118 changes: 118 additions & 0 deletions bin/test-wp-origin-git-actions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env bash
set -eu

ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
PORT="${WP_ORIGIN_E2E_PORT:-9409}"
PLAYGROUND_LOG="$ROOT_DIR/.context/wp-origin-playground.log"
CREDENTIALS_FILE="$ROOT_DIR/.context/wp-origin-e2e.json"
WORK_DIR="$(mktemp -d)"

if command -v wp-playground >/dev/null 2>&1; then
PLAYGROUND_CMD="wp-playground"
else
PLAYGROUND_CMD="npx @wp-playground/cli"
fi

cleanup() {
if [ -n "${PLAYGROUND_PID:-}" ] && kill -0 "$PLAYGROUND_PID" 2>/dev/null; then
kill "$PLAYGROUND_PID" 2>/dev/null || true
wait "$PLAYGROUND_PID" 2>/dev/null || true
fi
rm -rf "$WORK_DIR"
}
trap cleanup EXIT INT TERM

mkdir -p "$ROOT_DIR/.context"
rm -f "$PLAYGROUND_LOG" "$CREDENTIALS_FILE"

cd "$ROOT_DIR"

$PLAYGROUND_CMD server \
--port="$PORT" \
--blueprint="$ROOT_DIR/plugins/wp-origin/blueprint-e2e.json" \
--mount="$ROOT_DIR:/workspace" \
--mount="$ROOT_DIR/vendor:/wordpress/wp-content/vendor" \
--mount="$ROOT_DIR/components:/wordpress/wp-content/components" \
--mount="$ROOT_DIR/plugins/wp-origin:/wordpress/wp-content/plugins/wp-origin" \
>"$PLAYGROUND_LOG" 2>&1 &
PLAYGROUND_PID=$!

for _ in $(seq 1 120); do
if [ -f "$CREDENTIALS_FILE" ]; then
break
fi
sleep 1
done

if [ ! -f "$CREDENTIALS_FILE" ]; then
cat "$PLAYGROUND_LOG"
echo "WP Origin e2e setup did not produce credentials." >&2
exit 1
fi

USERNAME="$(php -r 'echo json_decode(file_get_contents($argv[1]), true)["username"];' "$CREDENTIALS_FILE")"
PASSWORD="$(php -r 'echo json_decode(file_get_contents($argv[1]), true)["password"];' "$CREDENTIALS_FILE")"

AUTH_HEADER="$(php -r 'echo base64_encode($argv[1] . ":" . $argv[2]);' "$USERNAME" "$PASSWORD")"
BASE_URL="http://127.0.0.1:$PORT"
REMOTE_AUTH_URL="http://$USERNAME:$PASSWORD@127.0.0.1:$PORT/wp-json/git/v1/md.git"
REMOTE_URL="$BASE_URL/wp-json/git/v1/md.git"
CLONE_DIR="$WORK_DIR/clone"

git -c protocol.version=2 clone "$REMOTE_AUTH_URL" "$CLONE_DIR"

test -f "$CLONE_DIR/post/hello-world.md"
test -f "$CLONE_DIR/page/sample-page.md"
grep -q 'Hello from WordPress' "$CLONE_DIR/post/hello-world.md"

cd "$CLONE_DIR"
git config user.name "WP Origin E2E"
git config user.email "wp-origin-e2e@example.com"

php -r '
$path = $argv[1];
$contents = file_get_contents($path);
$contents = str_replace("Hello from WordPress", "Updated from Git", $contents);
file_put_contents($path, $contents);
' "$CLONE_DIR/post/hello-world.md"

git add post/hello-world.md
git commit -m "Update hello world from Git"
git push origin trunk

POST_ID="$(curl -sS -H "Authorization: Basic $AUTH_HEADER" "$BASE_URL/wp-json/wp/v2/posts?slug=hello-world&context=edit" | php -r '
$posts = json_decode(stream_get_contents(STDIN), true);
echo $posts[0]["id"];
')"

UPDATED_CONTENT="$(curl -sS -H "Authorization: Basic $AUTH_HEADER" "$BASE_URL/wp-json/wp/v2/posts/$POST_ID?context=edit" | php -r '
$post = json_decode(stream_get_contents(STDIN), true);
echo $post["content"]["raw"];
')"
printf '%s' "$UPDATED_CONTENT" | grep -q 'Updated from Git'

php -r '
$path = $argv[1];
$contents = file_get_contents($path);
$contents = str_replace("Updated from Git", "Stale local edit", $contents);
file_put_contents($path, $contents);
' "$CLONE_DIR/post/hello-world.md"

git add post/hello-world.md
git commit -m "Create stale local edit"

UPDATE_PAYLOAD='{"content":"<!-- wp:paragraph --><p>Updated in WordPress</p><!-- /wp:paragraph -->"}'
curl -sS \
-X POST \
-H "Authorization: Basic $AUTH_HEADER" \
-H "Content-Type: application/json" \
-d "$UPDATE_PAYLOAD" \
"$BASE_URL/wp-json/wp/v2/posts/$POST_ID?context=edit" >/dev/null

if git push origin trunk; then
echo "Expected stale push to fail." >&2
exit 1
fi

git pull --rebase origin trunk
grep -q 'Updated in WordPress' "$CLONE_DIR/post/hello-world.md"
Loading
Loading