-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CICD-47] Add a basic e2e test (#17)
* add e2e test deploy workflow * TEST: introduce breaking change * Revert "TEST: introduce breaking change" This reverts commit d8dc96e.
- Loading branch information
1 parent
631eab2
commit 0d63fba
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |