Last active
December 11, 2015 22:18
-
-
Save p4ul/4668743 to your computer and use it in GitHub Desktop.
This is a script that will update a Drupal site from git (github), clear the cache and send a deployment notice to New Relic.
This can be called from github service hooks, CI server or browser. This is not recommended for a production environment unless you add some security / firewall rules etc.
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
<pre> | |
<?php | |
/** | |
Modify the capitalised variables with your info. | |
Call this from your github webservice hook / CI server. | |
If you are not using new relic you need to remove that cruft. | |
(the last 3 lines) | |
**/ | |
// ---------------------- CONFIG DETAILS ---------------------- | |
//branch in git | |
$BRANCH = 'master'; | |
//App name is name on new relic site | |
$APP_NAME = 'xxxxxxxxxxxx'; | |
//new relic api key | |
$API_KEY='xxxxxxxxxxx'; | |
//host user and description don't really mater but show up on new relic | |
$HOST='amazon'; | |
$USER='www-data'; | |
$DESCRIPTION='github auto deploy'; | |
// --------- You should not need to edit below here ------------ | |
$current_sha1 = `git rev-parse $BRANCH`; | |
$status_of_branch = `git ls-remote origin -h refs/heads/$BRANCH`; | |
if( strpos(trim($status_of_branch), trim($current_sha1)) !== false) { | |
echo "no changes on branch $BRANCH \n"; | |
return; | |
} | |
echo "Pulling\n"; | |
$pull = `git pull`; | |
echo ".\n"; | |
echo "Clearing Cache\n"; | |
$cache = `drush cc all`; | |
echo ".\n"; | |
echo "Finished \n"; | |
echo "pull:". $pull , "\n"; | |
echo "cache:".$cache , "\n"; | |
$sha1 = `git rev-parse $BRANCH`; | |
$changelog = `git log $BRANCH -1 --format="%s"`; | |
echo "sha1:". $sha1 , "\n"; | |
echo "changelog:".$changelog , "\n"; | |
//echo "command:curl -H \"x-api-key:$API_KEY\" -d \"deployment[app_name]=$APP_NAME\" -d \"deployment[host]=$HOST\" -d \"deployment[description]=$DESCRIPTION\" -d \"deployment[revision]=$sha1\" -d \"deployment[changelog]=$changelog\" -d \"deployment[user]=$USER\" https://rpm.newrelic.com/deployments.xml \n"; | |
$output = `curl -H "x-api-key:$API_KEY" -d "deployment[app_name]=$APP_NAME" -d "deployment[host]=$HOST" -d "deployment[description]=$DESCRIPTION" -d "deployment[revision]=$sha1" -d "deployment[changelog]=$changelog" -d "deployment[user]=$USER" https://rpm.newrelic.com/deployments.xml`; | |
//echo $output; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment