Created
September 9, 2022 17:30
-
-
Save VincentBean/ba571efd33ac8e2ec85a38aeba46db8d to your computer and use it in GitHub Desktop.
Laravel simple endpoint for github webhook to call deploy script
This file contains hidden or 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 | |
| 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