Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
wpengine

GitHub Action

Deploy WordPress to WP Engine

v2.3.1 Pre-release

Deploy WordPress to WP Engine

wpengine

Deploy WordPress to WP Engine

Deploy WordPress projects to a WP Engine account using SSH Gateway

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Deploy WordPress to WP Engine

uses: wpengine/[email protected]

Learn more about this action in wpengine/github-action-wpe-site-deploy

Choose a version

GitHub Action for WP Engine Site Deployments

This GitHub Action may be used to deploy code from Github repo to a WP Engine environment of your choosing. Deploy a full site directory, or optionally a theme, plugin or other directory with the TPO options. Optionally lint your php pre-deployment. Post deploy, this action will automatically purge your WP Engine cache to ensure all changes are visible.

V2.3.1 NOW AVAILABLE!

Changelog: v.2.3.1 Restricted paths are excluded from the rsync deploy such as wp-config.php as well as platform specific files that customers do not have permissions to edit. No action required. This should enhance expected behavior of the toolkit for users. Inspect exclude.txt for reference.

v2.3 CACHE_CLEAR has been added as an option to the toolkit. Default is TRUE but users can disable by setting to FALSE. This may decrease the execution time of deploys. All planned options are now built into the toolkit. All feedback welcome via issues or pull requests!

v2.2 includes optional FLAGS variable for users to customize their own rsync deploy protocol. This is completely optional and the toolkit will work without any FLAGS variable by relying on the flags historically built into the tool.

NOTE: v2.2 WILL REQUIRE an update to the main.yml configuration to enable optional flags if you are using a previous version. Replacing env: for with: to follow Github Action best practice and to utilize new options of the tool moving forward.

Example GitHub Action workflow

  1. Create a .github/workflows/main.yml file in your root of your WordPress project/repo, if one doesn't exist already.

  2. Add the following to the main.yml file, replacing values for PRD_BRANCH, PRD_ENV and WPE_SSHG_KEY_PRIVATE if they are anything other than what is below. Optional vars can be specified as well. Consult "Further Reading" on how to setup keys in repo Secrets.

  3. Git push your site repo. The action will do the rest

Simple main.yml:

name: Deploy to WP Engine
on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest  
    steps: 
    - uses: actions/checkout@v2
    - name: GitHub Action Deploy to WP Engine
      uses: wpengine/[email protected]
      with:
      
      # Deploy vars
        WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_SSHG_KEY_PRIVATE }} 
      
      # Branches & Environments 
        PRD_BRANCH: main
        PRD_ENV: prodsitehere

Extended main.yml

name: Deploy to WP Engine
on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest  
    steps: 
    - uses: actions/checkout@v2
    - name: GitHub Action Deploy to WP Engine
      uses: wpengine/[email protected]
      with:
      
      # Deploy vars 
        WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_SSHG_KEY_PRIVATE }} 
        PHP_LINT: TRUE
        FLAGS: -azvr --inplace --delete --exclude=".*"
        CACHE_CLEAR: TRUE
        TPO_SRC_PATH: "wp-content/themes/genesis-child-theme/"
        TPO_PATH: "wp-content/themes/genesis-child-theme/"
      
      # Branches & Environments 
        PRD_BRANCH: main
        PRD_ENV: prodsitehere
        
        STG_BRANCH: feature/stage
        STG_ENV: stagesitehere
        
        DEV_BRANCH: feature/dev
        DEV_ENV: devsitehere

Environment Variables & Secrets

Required

Name Type Usage
PRD_BRANCH string Insert the name of the Github branch you would like to deploy from, example; main.
PRD_ENV string Insert the name of the WP Engine environment you want to deploy to.
WPE_SSHG_KEY_PRIVATE secrets Private SSH Key for the SSH Gateway and deployment. See below for SSH key usage.

Optional

Name Type Usage
STG_BRANCH string Insert the name of a staging Github branch you would like to deploy from. Note: exclude leading / from branch names.
STG_ENV string Insert the name of the WP Engine Stage environment you want to deploy to.
DEV_BRANCH string Insert the name of a development Github branch you would like to deploy from. Note: exclude leading / in branch names.
DEV_ENV string Insert the name of the WP Engine Dev environment you want to deploy to.
PHP_LINT bool Set to TRUE to execute a php lint on your branch pre-deployment. Set to FALSE to bypass lint.
FLAGS string Set optional rsync flags such as --delete. This action defaults to a non-destructive deploy using the flags in the example above.
CACHE_CLEAR bool Optionally clear cache post deploy. This takes a few seconds. Default is TRUE.
TPO_SRC_PATH string Optional path to specify a theme, plugin, or other directory source to deploy from. Ex. "wp-content/themes/genesis-child-theme/" . Defaults to "." Dir.
TPO_PATH string Optional path to specify a theme, plugin, or other directory destination to deploy to. Ex. "wp-content/themes/genesis-child-theme/" . Defaults to WordPress root directory.

Setting up your SSH keys for repo

  1. Generate a new SSH key pair as a special deploy key between your Github Repo and WP Engine. The simplest method is to generate a key pair with a blank passphrase, which creates an unencrypted private key.

  2. Store your private key in the GitHub repository of your website as new 'Secrets' (under your repository settings) using the names WPE_SSHG_KEY_PRIVATE with the name in your specfic files. These can be customized, just remember to change the var in the yml file to call them correctly.

  3. Add the Public SSH key to your WP Engine SSH Gateway configuration. https://wpengine.com/support/ssh-gateway/#addsshkey

Further reading