Skip to content

Instantly share code, notes, and snippets.

@VincentBean
Created September 9, 2022 17:30
Show Gist options
  • Select an option

  • Save VincentBean/ba571efd33ac8e2ec85a38aeba46db8d to your computer and use it in GitHub Desktop.

Select an option

Save VincentBean/ba571efd33ac8e2ec85a38aeba46db8d to your computer and use it in GitHub Desktop.
Laravel simple endpoint for github webhook to call deploy script
<?php
Route::post('/deploy', function(Request $request) {
if (($signature = $request->headers->get('X-Hub-Signature')) == null) {
abort(400, 'Signature header is not set.');
}
$signatureData = explode('=', $signature);
if (count($signatureData) !== 2) {
abort(400, 'Signature format is invalid.');
}
$webhookSignature = hash_hmac('sha1', $request->getContent(), config('services.deploy_key'));
if (!hash_equals($webhookSignature, $signatureData[1])) {
abort(401, 'Could not verify request signature ' . $signatureData[1]);
}
exec("sh " . base_path() . "/deploy.sh &");
return response('deploying');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment