Skip to content

Set automatic deployments to WPEngine using an SSH private key and rsync.

License

Notifications You must be signed in to change notification settings

IlanVivanco/wpe-deployment-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Automatic WordPress deployment to WP Engine

This GitHub Action can be used to set automatic deployments using an SSH private key and rsync.

By default, the action will deploy the repository root directory, but you can optionally deploy a theme, plugin, or any other directory using the SOURCE_PATH. Likewise, if you need to specify a different destination directory, you can do so using PUBLISH_PATH.

After the deployment, this action will also purge your WP Engine cache and flush permalinks to ensure all changes are visible.

GitHub Action workflow

  1. Set up your SSH key on WP Engine.

  2. Create a new YML file in the directory .github/workflows/ in the root of your repository. You can choose any name, e.g., deploy.yml.

  3. Add the following code to this new file, replacing values for PRD_BRANCH and PRD_ENV accordingly.

    > .github/workflows/deploy.yml

    name: 📦 Deploy to WP Engine
    on:
       push:
       workflow_dispatch:
    
    jobs:
       build:
          name: 🚩 Starting deployment job
          runs-on: ubuntu-latest
          steps:
             - name: 🚚 Getting latest code
             uses: actions/checkout@v2
    
             - name: 🔁 Deploying to WP Engine
             uses: IlanVivanco/wpe-deployment-action@main
             env:
                # Deployment options.
                WPE_SSH_KEY: ${{ secrets.WPE_SSH_KEY }}
                SOURCE_PATH: ''
                PUBLISH_PATH: ''
    
                # You must, at least, set the production environment.
                PRD_BRANCH: main
                PRD_ENV: prodinstall
    
                # Uncomment this for setting a staging environment.
                # STG_BRANCH: staging
                # STG_ENV: stageinstall
    
                # Uncomment this for setting a development environment.
                # DEV_BRANCH: dev
                # DEV_ENV: devinstall
  4. Finally, push the latest changes to the repository, the action will do the rest.

    Magic

ℹ You can have multiple branches deploying to the same install by separating them with a comma, e.g., PRD_BRANCH: main, dev, staging will deploy all three branches to the WP Engine production environment. Using regex here, well help you to extend this to even more branches, e.g., main, feature(/.*)? will deploy the main banch and also the feature or feature/anything branches.

Setting up your SSH key

  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. Add the public SSH key to your WP Engine SSH Keys configuration panel.

  3. Store the private key in the GitHub repository as new GitHub encrypted secret using the name WPE_SSH_KEY save it —this can be customized if you change the secret name in the yml file to call it correctly—.

Ignoring files

If you want some files to be ignored upon deployment, you can create a .deployignore file on your source directory, adding the exclude patterns —one per line—. Blank lines and lines starting with # will be ignored.

> .deployignore

# Exclude rules
bin
composer*
dist
gulp*
node_modules
package*
phpcs*
src
vendor

Environment variables

Required

Name Type Usage
WPE_SSH_KEY secrets Authorized SSH private key for deployment. See SSH key usage.
PRD_BRANCH string Name of the branch you would like to deploy from, e.g., "main".
PRD_ENV string Name of the WP Engine Prod environment you want to deploy to.

Optional

Name Type Usage
STG_BRANCH string Name of the staging branch you would like to deploy from.
STG_ENV string Name of the the WP Engine Stage environment you want to deploy to.
DEV_BRANCH string Name of the a development branch you would like to deploy from.
DEV_ENV string Name of the the WP Engine Dev environment you want to deploy to.
SOURCE_PATH string Path to specify a theme, plugin, or any other directory source to deploy from. Defaults to the repository root.
PUBLISH_PATH string Path to specify a theme, plugin, or any other directory destination to deploy to. Defaults to the WordPress root directory.
FAIL_CODE number Code number to be used if the action fails (0 = success and 1 = error). Defaults to 1.

Additional Resources

Contributing

Contributions to this action are always welcome and highly encouraged.

License & Attribution