Created
January 11, 2011 20:56
-
-
Save badsyntax/775125 to your computer and use it in GitHub Desktop.
An example PHP & BASH Post-Receive github web hook to package projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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!' '[email protected]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 &`; | |
} | |
?> |
Thank you @nicolae-olariu, your file_get_contents() tip helped me fix my webhook in https://github.com/marginallyclever/Robot-Overlord. Kudos!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @nicolae-olariu!