Note: Most of the code here is specific to my environment on Webfaction, github and for use with WordPress plugins. You can make it work for other setups (i.e. different hosts, local gits, or even SVN) but will involve some tweaking.
Scott recently had a great idea to run the bleeding edge release of Edit Flow on our official site. I usually do this for most of my plugins before releasing, though, it’s a manual process: FTP up the latest code and give it a test run. That’s not fun.
Here’s a far better, automatized way to keep your repo up-to-date. You can either use cron or githooks. Pick your poison.
Step #1: Clone-ify
On the server, where Edit Flow would be installed, delete it (if it exists), and clone the github repo. (You have to install a git instance, if you don’t already have one.)
Step #2: Cron-ify
Set up a cron job to run every so often so that you don’t have to manually run “git pull” to stay up-to-date.
This job runs daily at 1:01am and does a git pull on the repo. On my site, the cron job is set to run daily; the Edit Flow site is set to update every couple of hours. Go with what works for you. Check out other options for cron jobs.
(Alternate) Step #2: Hook-ify
If you’re really adventurous, an update once (or even several) times a day isn’t enough for you. You want to live on the bleeding edge and update as soon changs are made! Thanks to githooks, you can do this fairly easily. Github takes it a step further and makes it even easier with Post-Receive URLs:
We’ll hit these URLs with POST requests when you push to us, passing along information about the push.
Here’s a quick-and-dirty PHP script I cooked up that works with github’s Post-Recieve URLs.
Upload this to your server and change the BASE_PATH, GIT_PATH, and $repository_paths to match your environment. On github, go to your Repo > Admin > Service Hooks > Post-Receive URLs and add the URL to the script. You can click on “Test Hook” to have github send you a test payload.
And you’ll probably want to delete the cron job, as that’s now redundant.
If you want to keep a log of what these scripts are doing behind-the-scenes for troubleshooting, just append the following to the cron job or Post-Receive script after the “git pull” call. This appends all output (errors and all) to a git.log file. Keep in mind that this file will grow over time, so prune early, prune often.
Closing Caveat: I am, by no means, an expert on this topic. I’ve cooked up something that works for me, and it may or may not be The Right Way. Use at your own discretion.