GitHub Action for WP Engine Site Deployments

If you need to deploy code from a GitHub repo to WP Engine, this is a great option using GitHub Actions. Deploy a full site directory, a theme, plugin, or other directory with the TPO options. Other options include performing a PHP Lint, custom rsync flags, or clearing cache.

This configuration uses WP Engine’s SSH Gateway, instead of WP Engine’s GitPush feature.

View the full guide on GitHub here.


Setup Instructions

Configuration requires three main steps: Connect Github and WP Engine, save the private and public SSH keys, and set up the local yml configuration to orchestrate the deploy.

  1. SSH PRIVATE KEY SETUP IN GITHUB

NOTE

If using a GitHub Organization, adding the SSH key to the Organization Secrets will allow all repos to reference the same SSH key for deploys using the method in the sample main.yml. The SSH Key also connects to all installs made available to its WP Engine User. One key can then effectively be used to deploy all projects to their respective sites on WP Engine. Less work. More deploys!

  1. SSH PUBLIC KEY SETUP IN WP ENGINE

NOTE

This Action DOES NOT utilize WP Engine GitPush or the GitPush SSH keys found here.

  1. YML SETUP
  • Create .github/workflows/main.yml directory and file locally. Copy and paste the configuration from below, replacing the value under branches: and the value for WPE_ENV:.
  • To deploy from another branch, simply create another yml file locally for that branch, such as .github/workflows/stage.yml and replace the values for branches: and WPE_ENV: for that workflow.

This provides the ability to perform a different workflow for different branches/environments. Consult “Environment Variable & Secrets” for more available options.

  1. Git push your site GitHub repo. The action will do the rest!

View your actions progress and logs by navigating to the “Actions” tab in your repo.


Example GitHub Action Workflow

Simple main.yml:

name: Deploy to WP Engine
on:
  push:
    branches:
     - main
jobs:
  build:
    runs-on: ubuntu-latest  
    steps: 
    - uses: actions/[email protected]
    - name: GitHub Action Deploy to WP Engine
      uses: wpengine/[email protected]
      with:
        WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_SSHG_KEY_PRIVATE }} 
        WPE_ENV: <your_install_name_here>

Extended Sample main.yml:

name: Deploy to WP Engine
on:
  push:
    branches:
     - main
jobs:
  build:
    runs-on: ubuntu-latest  
    steps: 
    - uses: actions/[email protected]
    - name: GitHub Action Deploy to WP Engine
      uses: wpengine/[email protected]
      with:
      # Deploy vars 
        WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_SSHG_KEY_PRIVATE }} 
        WPE_ENV: <your_install_name_here>
        # Deploy Options
        SRC_PATH: "wp-content/themes/genesis-child-theme/"
        REMOTE_PATH: "wp-content/themes/genesis-child-theme/"
        PHP_LINT: TRUE
        FLAGS: -azvr --inplace --delete --exclude=".*" --exclude-from=.deployignore
        SCRIPT: "path/yourscript.sh"
        CACHE_CLEAR: TRUE

Environment Variables and Secrets

Required

NameTypeUsage
WPE_SSHG_KEY_PRIVATEsecretsPrivate SSH Key for the SSH Gateway and deployment. See below for SSH key usage.

Deploy Options

NameTypeUsage
WPE_ENVstringInsert the name of the WP Engine environment you want to deploy to. This also has an alias of PRD_ENVSTG_ENV, or DEV_ENV for multistep workflows.
SRC_PATHstringOptional path to specify a directory within the repo to deploy from. Ex. "wp-content/themes/genesis-child-theme/". Defaults to root of repo filesystem as source.
REMOTE_PATHstringOptional path to specify a directory destination to deploy to. Ex. "wp-content/themes/genesis-child-theme/" . Defaults to WordPress root directory on WP Engine.
PHP_LINTboolSet to TRUE to execute a php lint on your branch pre-deployment. Default is FALSE.
FLAGSstringSet optional rsync flags such as --delete or --exclude-from. The example is excluding paths specified in a .deployignore file in the root of the repo. This action defaults to a non-destructive deploy using the flags in the example above.
SCRIPTstringRemote bash file to execute post-deploy. This can include WP_CLI commands for example. Path is relative to the WP root and file executes on remote. This file can be included in your repo, or be a persistent file that lives on your server.
CACHE_CLEARboolOptionally clear cache post deploy. This takes a few seconds. Default is TRUE.

Further Reading


NEXT STEP: Check out our best practices for deploying when using version control

Still need help? Contact support!

We offer support 24 hours a day, 7 days a week, 365 days a year. Log in to your account to get expert one-on-one help.

The best in WordPress hosting.

See why more customers prefer WP Engine over the competition.