Scalable automated testing and deployment of upstream (WordPress core), plugin and theme updates on Pantheon sites with help from Terminus, CircleCI, WP-CLI, BackstopJS and Slack.
This script will loop through all sites in sites-to-auto-update.json
and:
- Authenticate with Terminus via machine token
- Delete the multidev environment
update-wp
- Recreate the multidev environment
update-wp
- Deletion and recreation is done to clear any existing changes and pull the latest database/files from the live environment
- This is opt-out per site and should only be disabled if using Solr or multidev creation takes more than 10 minutes
- Switch the multidev environment
update-wp
to git mode - Check for and apply Pantheon upstream updates
- WordPress core updates are managed in the default upstream
- Custom upstream updates will be applied if using a custom upstream
- Switch the multidev environment
update-wp
to SFTP mode - Check for and apply WordPress plugin updates via WP-CLI, if available
- Check for and apply WordPress theme updates via WP-CLI, if available
- If no WordPress updates are available the script will stop here
- Use BackstopJS to run a visual regression test between the live environment and the multidev environment
- If the visual regression test fails the script will stop here and post a link to the visual regression report in Slack
- Merge the multidev environment with the dev environment
- Deploy the dev environment to the test environment
- Create a backup of the test environment
- This is opt-out per site and should only be disabled if backups take longer than 10 minutes and you have regularly backups scheduled via another method.
- Deploy the test environment to the live environment
- Post a success message to Slack
- Don't fork this repository, instead clone it and change the remote URL to your own fresh GitHub repository and push the code there
- Update
backstop.template.json
to meet your needs, tweaking things likeviewport
- Create a CircleCI project
- Add environment variables to CircleCI for the following:
MULTIDEV
: The multidev name to use for applying/testing updates. Defaults toupdate-wp
CIRCLE_TOKEN
: A Circle CI API token with access to the project created in step 3.TERMINUS_MACHINE_TOKEN
: A Pantheon Terminus machine token with access to the org above.SLACK_HOOK_URL
: The Slack incoming webhook URLSLACK_CHANNEL
: The Slack channel to post notifications toSLACK_USERNAME
: The username to post to Slack with
- Add an SSH key to Pantheon and to the CircleCI project
- Edit
sites-to-auto-update.json
and set the following key for each JSON object for sites you wish to auto update. The order is important do not change the order of the keys in the object or skip keys.SITE_UUID
: The site UUID, which can be acquired withterminus site:list
or is in the dashboard URL for the site.SITE_NAME
: The site machine name, which can be acquired withterminus site:list
.CREATE_BACKUPS
:0
or1
to determine if a backup of the live site is made before deployment. You may want to disable for sites where a backup takes longer than 10 minutes and you have regularly backups scheduled via another method.RECREATE_MULTIDEV
:0
or1
to determine if the multidev is deleted and recreated.LIVE_URL
: The preferred custom domain (full URL) for the live environment to use in visual regression testing or set to0
to use thelive-SITE_NAME
Pantheon hosted URL,
- Backups of sites with large a large database or media files are taking too long and timing out on Circle CI (10 mins)
- Sites with a Solr Index fail visual regression tests as the multidev created doesn't have items indexed in Solr
backstop-crawl
on sites with many (~100+) URLs are taking too long and timing out on Circle CI (10 mins).- If visual regression testing fails and
RECREATE_MULTIDEV
is set to0
then a multidev with updates applied will persist causing subsequent update checks to return no updates and prevent visual regression tests from running again. This cycle will break when there are further updates released to be applied.
backstop.template.json
is used as a generic template for backstop-crawl
when creating backstop.json
files dynamically.
For each site a custom template in the form of SITE_NAME.backstop.json
or SITE_NAME.backstop-config.js
, where SITE_NAME
is the machine name for the Pantheon site, can be also be created and will take precedence over the template above. The former is a hard coded Backstop JS file and the latter is a JavaScript file that must export valid JSON contents of a Backstop JS file.
The custom templates above are most useful for sites with many URLs where a crawl will timeout. In this case manually specifying which URLs to test is needed.
This workflow assumes that the Dev and Test environments on Pantheon are always in a shippable state as the script will automatically deploy changes from Dev to Test and Live if the visual regression tests of updates pass.
All work that isn't ready for deployment to production should be kept in a Pantheon multidev environment, on a separate git branch.
Scalability relies on the number of Circle CI workers available. If workers are available to process jobs in parallel this script will scale very well.