Skip to content

Instantly share code, notes, and snippets.

@fumikito
Last active August 23, 2017 04:26
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 fumikito/ce87f8819e893359432b41f449f25bfa to your computer and use it in GitHub Desktop.
Save fumikito/ce87f8819e893359432b41f449f25bfa to your computer and use it in GitHub Desktop.
BacklogのWebフックを受け取って、テーマをビルドする
<?php
// パスを設定。なぜかこれがないと動かず。
putenv('PATH=/home/ec2-user/.nvm/versions/node/v6.11.0/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin');
//リリースするブランチの指定
$deploy_ref = 'refs/heads/master';
//logファイルの指定
$log_path = '/var/www/wordpress/wp-content/git.log';
//backlogからのpayloadを取得
$request_body = file_get_contents('php://input');
$request_body = urldecode($request_body);
$request_body = str_replace("payload=", "", $request_body);
$payload = json_decode($request_body);
//指定されたブランチかどうかの確認
$checkout = false;
if( $payload ){
$ref = $payload->ref;
if( $ref == $deploy_ref ){
$checkout = true;
}
}
//指定されたブランチの場合、fetch+checkoutを実行して、最終コミットをlogファイルに保存する
if( $checkout ){
exec( 'bash /home/ec2-user/bin/deploy-wp.sh' );
error_log('Theme is updated:'.$request_body);
}else{
error_log('Nothing to update: '.$request_body);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment