Push-to-Deploy is the feature of WP Pusher that will keep your WordPress websites up-to-date every time you push some fresh code to your Git repositories. In this post, we are going to take a look at what Push-to-Deploy is, how best to use it for an effective workflow.
[content_upgrade cu_id=”652″]Get the bonus video: A Solid Deployment Strategy With WP Pusher[content_upgrade_button]Watch it now[/content_upgrade_button][/content_upgrade]
What is Push-to-Deploy
Push-to-Deploy is the flagship feature of WP Pusher. When enabled, it will make sure that your WordPress websites always stays up-to-date with your Git repositories. If you installed a plugin or theme with WP Pusher and enabled Push-to-Deploy, whenever you push fresh code to GitHub or Bitbucket, your sites will be updated.
Push-to-Deploy is one of those features that should probably be labeled with a “use with care” sticker, since it’s quite powerful. Later in this post we’ll talk about when and where to use it.
The magic of webhooks
WP Pusher is possible because of something called webhooks that GitHub and Bitbucket offers. A webhook is simply an HTTP request that will be fired when various events occur. When using GitHub or Bitbucket, you get to configure which URLs to ping when a webhook is fired. For example, with WP Pusher there’s a unique URL for each plugin and theme called the Push-to-Deploy URL. Whenever this URL gets hit, WP Pusher will deploy the latest version of said theme or plugin. When you enable Push-to-Deploy for a theme or plugin, WP Pusher will tell GitHub or Bitbucket to hit that specific URL every time new code is pushed to the repository.
If you are curious to see this in action, you can check out the webhooks area for a repository on GitHub or Bitbucket:
You will be able to see exactly how the webhook HTTP request looked and what kind of response it got:
If a webhook results in a successful update of a theme or plugin, WP Pusher will make sure to return a 200 status code.
Setting up Push-to-Deploy with WP Pusher is very simple. Since we go through the Bitbucket and GitHub APIs to do this, you need to make sure that you have a valid token stored. Since version 2.1.0 of WP Pusher, getting a token is very simple. Just click the “Obtain a Bitbucket/GitHub token” button, copy and paste the token and save it in WP Pusher.
Once you have a valid token stored, all you need to do is check the “Push-to-Deploy” checkbox on the plugin/theme installation page. WP Pusher will then take care of all the details of setting up the necessary webhook on GitHub or Bitbucket.
When and where to enable automatic updates
As mentioned already, Push-to-Deploy is one of those features that should probably be labeled with a “use with care” sticker, since it’s quite powerful. Imagine if you enable Push-to-Deploy for a production website and accidentally push a bug to your Git repository. WP Pusher will then go ahead and deploy the buggy code and your production website will be broken. Generally, there are 2 ways to avoid this happening:
The first option is to not enable Push-to-Deploy in production. Simply enable it for your staging site (because surely you have one, right!) and then manually click the “Update plugin/theme” button within WP Pusher for the production website, when you are ready to deploy.
This first option is a bit of a downer, if you were counting on WP Pusher to do all the hard work of updating your websites. Here’s the setup I recommend instead:
First of all, you need 2 branches for this setup to work: A development branch and a master/production branch. While you work on a new version of your theme or plugin, you commit everything to your development branch. This is also the branch that’s deployed to your staging site – with Push-to-Deploy enabled. On the staging site you can test that everything works as expected in a realistic environment. When a new version is ready to be released to production, your merge your development branch with your master branch, which is deployed to your production site(s). With this setup, it’s safe to setup Push-to-Deploy on your production site, since the master branch will only be updated once you choose to merge the development branch. If you want to learn more about what branches and merging means, feel free to sign up for my free video course on Git for WordPress developers.[content_upgrade cu_id=”652″]Get the bonus video: A Solid Deployment Strategy With WP Pusher[content_upgrade_button]Watch it now[/content_upgrade_button][/content_upgrade]
Thanks for reading this far. I’d love to hear more about your current deployment setup – just post a comment below!