Skip to content

Instantly share code, notes, and snippets.

@chrisabrams
Forked from badsyntax/build.sh
Created February 20, 2012 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisabrams/1871069 to your computer and use it in GitHub Desktop.
Save chrisabrams/1871069 to your computer and use it in GitHub Desktop.
An example PHP & BASH Post-Receive github web hook to package projects
#! /usr/bin/env bash
#clone the repo
git clone -q "${1}" "clones/${2}"
cd "clones/${2}"
#update the submodules (how do we handle errors here?)
git submodule --quiet update --init --recursive
cd ../../
#tar up the directory
tar --exclude=.git -cf "archives/${2}-master.tar" "clones/${2}"
#remove the cloned repo
rm -rf "clones/${2}"
echo "A new archive has been created at /archives/${2}-master.tar" | mail -s 'Github project build successul!' 'your@email.com'
<?php
error_reporting(0);
try
{
// Decode the payload json string
$payload = json_decode($_REQUEST['payload']);
}
catch(Exception $e)
{
exit(0);
}
// Pushed to master?
if ($payload->ref === 'refs/heads/master')
{
// Log the payload object
file_put_contents('logs/github.txt', print_r($payload, TRUE), FILE_APPEND);
// Prep the URL - replace https protocol with git protocol to prevent 'update-server-info' errors
$url = str_replace('https://', 'git://', $payload->repository->url);
// Run the build script as a background process
`./build.sh {$url} {$payload->repository->name} > /dev/null 2>&1 &`;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment