Skip to content

Commit

Permalink
[CICD-47] Add a basic e2e test (#17)
Browse files Browse the repository at this point in the history
* add e2e test deploy workflow

* TEST: introduce breaking change

* Revert "TEST: introduce breaking change"

This reverts commit d8dc96e.
  • Loading branch information
apmatthews authored Jul 8, 2022
1 parent 631eab2 commit 0d63fba
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/e2e-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test e2e Deploy to WP Engine
on:
push:
branches:
- main
pull_request:
branches:
- main


jobs:
run_action:
runs-on: ubuntu-latest
outputs:
status: ${{ steps.deploy.outputs.status }}
steps:
- uses: actions/checkout@v3
- name: Bump test plugin version number
run: sed -i 's/0.0.1/0.0.2/' tests/data/plugins/test-plugin/test-plugin.php
- name: GitHub Action Deploy to WP Engine
id: deploy
uses: ./
with:
# Deploy vars
WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_SSHG_KEY_PRIVATE }}
WPE_ENV: ghae2e
# Deploy Options
SRC_PATH: "tests/data/plugins/test-plugin"
REMOTE_PATH: "wp-content/plugins/"
PHP_LINT: TRUE
FLAGS: -r --backup --backup-dir=/tmp --itemize-changes
SCRIPT: "tests/data/post-deploy/test-plugin.sh"
CACHE_CLEAR: TRUE
validate_result:
runs-on: ubuntu-latest
needs: run_action
steps:
- name: Validate deploy results
run: |
[ ${{needs.run_action.outputs.status}} = "pass" ] || exit 1
15 changes: 15 additions & 0 deletions tests/data/plugins/test-plugin/test-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Plugin Name: Deploy WordPress to WP Engine - e2e Test
* Plugin URI: https://github.com/wpengine/github-action-wpe-site-deploy
* Description: Sample code to test the Site Deployment GitHub Action by WP Engine.
* Version: 0.0.1
*/

add_action('init', 'register_my_cpt');

function register_my_cpt() {
register_post_type('my-cpt', array(
'public' => true
));
}
32 changes: 32 additions & 0 deletions tests/data/post-deploy/test-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

BACKUP_DIR=/tmp
PLUGINS_DIR=wp-content/plugins
PLUGIN_NAME=test-plugin

cleanup() {
rm tests/data/post-deploy/test-plugin.sh
}
trap cleanup EXIT

# Get the the new plugin version
AFTER_PLUGIN_VERSION=$(wp plugin get $PLUGIN_NAME | sed -n "/version/p" | cut -f2)
echo "New test plugin version: $AFTER_PLUGIN_VERSION"

# Revert to backup created by rsync if it exists
if [ -d $BACKUP_DIR/$PLUGIN_NAME ]; then
rm -rf $PLUGINS_DIR/$PLUGIN_NAME && mv $BACKUP_DIR/$PLUGIN_NAME $PLUGINS_DIR/
fi

# Get the old plugin version
BEFORE_PLUGIN_VERSION=$(wp plugin get $PLUGIN_NAME | sed -n "/version/p" | cut -f2)
echo "Old test plugin version: $BEFORE_PLUGIN_VERSION"

# Check that the expected update was made
if [ -z "$BEFORE_PLUGIN_VERSION" ] || [ -z "$AFTER_PLUGIN_VERSION" ] || [ "$BEFORE_PLUGIN_VERSION" = "$AFTER_PLUGIN_VERSION" ]; then
echo "Failure: Test plugin was not updated!"
echo "::set-output name=status::fail"
else
echo "Success: Test plugin successfully updated from $BEFORE_PLUGIN_VERSION to $AFTER_PLUGIN_VERSION!"
echo "::set-output name=status::pass"
fi

0 comments on commit 0d63fba

Please sign in to comment.