-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a7daffb
Showing
17 changed files
with
416 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Path-based git attributes | ||
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html | ||
|
||
# Ignore all test and documentation with "export-ignore". | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.travis.yml export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/.scrutinizer.yml export-ignore | ||
/tests export-ignore | ||
/.editorconfig export-ignore |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build | ||
composer.lock | ||
docs | ||
vendor | ||
coverage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
C:37:"PHPUnit\Runner\DefaultTestResultCache":425:{a:2:{s:7:"defects";a:1:{s:59:"SchantlDev\GitWebhook\Tests\WebhookTest::try_with_signature";i:3;}s:5:"times";a:4:{s:62:"SchantlDev\GitWebhook\Tests\WebhookTest::deploy_scripts_exists";d:0.51;s:53:"SchantlDev\GitWebhook\Tests\WebhookTest::route_exists";d:0.412;s:73:"SchantlDev\GitWebhook\Tests\WebhookTest::try_with_signature_no_secret_set";d:0.315;s:59:"SchantlDev\GitWebhook\Tests\WebhookTest::try_with_signature";d:0.305;}}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
filter: | ||
excluded_paths: [tests/*] | ||
|
||
checks: | ||
php: | ||
remove_extra_empty_lines: true | ||
remove_php_closing_tag: true | ||
remove_trailing_whitespace: true | ||
fix_use_statements: | ||
remove_unused: true | ||
preserve_multiple: false | ||
preserve_blanklines: true | ||
order_alphabetically: true | ||
fix_php_opening_tag: true | ||
fix_linefeed: true | ||
fix_line_ending: true | ||
fix_identation_4spaces: true | ||
fix_doc_comments: true | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
preset: laravel | ||
|
||
disabled: | ||
- single_class_element_per_statement |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
language: php | ||
|
||
php: | ||
- 7.1 | ||
- 7.2 | ||
- 7.3 | ||
|
||
env: | ||
matrix: | ||
- COMPOSER_FLAGS="--prefer-lowest" | ||
- COMPOSER_FLAGS="" | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source | ||
|
||
script: | ||
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover | ||
|
||
after_script: | ||
- php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Schantl Web Development & Services | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Laravel - Git Webhook | ||
|
||
[![Latest Version on Packagist](https://img.shields.io/packagist/v/schantldev/git-webhook.svg?style=flat-square)](https://packagist.org/packages/schantldev/git-webhook) | ||
[![Build Status](https://img.shields.io/travis/schantldev/git-webhook/master.svg?style=flat-square)](https://travis-ci.org/schantldev/git-webhook) | ||
[![Quality Score](https://img.shields.io/scrutinizer/g/schantldev/git-webhook.svg?style=flat-square)](https://scrutinizer-ci.com/g/schantldev/git-webhook) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/schantldev/git-webhook.svg?style=flat-square)](https://packagist.org/packages/schantldev/git-webhook) | ||
|
||
An easy way to update your application using Github's webhooks. No manual deploy required. | ||
|
||
This package sets up a route that you can use for your github webhooks. You can set your secret and define the URL of the route. The pacakge will publish a deploy script that you can customize to fit your needs. It will be executed to fit | ||
|
||
## Installation | ||
|
||
You can install the package via composer: | ||
|
||
```bash | ||
composer require schantldev/git-webhook | ||
``` | ||
|
||
After that, publish the files using | ||
|
||
```bash | ||
php artisan vendor:publish | ||
``` | ||
|
||
Ensure the deployment script is executable by running | ||
|
||
```bash | ||
chmod +x /storage/git-webhook/git_deploy.sh | ||
``` | ||
|
||
The package will queue the command and run it in the background. Ensure you have a proper queue (eg. database driver) set up, otherwise the deployment script might not work. | ||
|
||
## Usage | ||
|
||
1. Define the webhook URL you want to use in the ``git-webhook.php`` config file | ||
2. Define a secret if necessary | ||
3. Activate the webhook inside your repository settings | ||
|
||
|
||
## Contributing | ||
|
||
Everybody is welcome to contribute towards this git webhook package. | ||
|
||
### Security | ||
|
||
If you discover any security related issues, please email [email protected] instead of using the issue tracker. | ||
|
||
## Credits | ||
|
||
- [Schantl Web Development & Services](https://github.com/schantldev) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "schantldev/git-webhook", | ||
"description": "An easy way to update your application using Github's webhooks. No manual deploy required.", | ||
"keywords": [ | ||
"schantldev", | ||
"git-webhook" | ||
], | ||
"homepage": "https://github.com/schantldev/git-webhook", | ||
"license": "MIT", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "Schantl Web Development & Services", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.1", | ||
"illuminate/support": "^7.0" | ||
}, | ||
"require-dev": { | ||
"orchestra/testbench": "^5.0", | ||
"phpunit/phpunit": "^8.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SchantlDev\\GitWebhook\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"SchantlDev\\GitWebhook\\Tests\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit", | ||
"test-coverage": "vendor/bin/phpunit --coverage-html coverage" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"SchantlDev\\GitWebhook\\GitWebhookServiceProvider" | ||
] | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
/* | ||
* You can place your custom package configuration in here. | ||
*/ | ||
return [ | ||
'route' => '/webhooks/github', | ||
'secret' => '' | ||
]; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="tap" target="build/report.tap"/> | ||
<log type="junit" target="build/report.junit.xml"/> | ||
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/> | ||
<log type="coverage-text" target="build/coverage.txt"/> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
</phpunit> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
Route::post(config('git-webhook.route', '/webhooks/github'), function () { | ||
$github_hash = request()->header('X-Hub-Signature'); | ||
$github_payload = request()->getContent(); | ||
|
||
$secret = config('git-webhook.secret'); | ||
$sent_hash = 'sha1=' . hash_hmac('sha1', $github_payload, $secret, false); | ||
|
||
if ($github_hash === null || hash_equals($github_hash, $sent_hash)) { | ||
Artisan::queue('github:deploy'); | ||
return response('', 200); | ||
} else { | ||
return response('', 403); | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace SchantlDev\GitWebhook\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Log; | ||
use Symfony\Component\Process\Process; | ||
|
||
class DefaultGithubDeploy extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'github:deploy'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Pull changes from git and deploy.'; | ||
|
||
|
||
public function handle() | ||
{ | ||
$process = new Process([storage_path('/git-webhook/git_deploy.sh')], base_path()); | ||
$process->run(); | ||
|
||
Log::info('====================== DEPLOY ======================'); | ||
Log::info($process->getOutput()); | ||
Log::info('===================== END DEPLOY ====================='); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace SchantlDev\GitWebhook; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use SchantlDev\GitWebhook\Commands\DefaultGithubDeploy; | ||
use Symfony\Component\Process\Process; | ||
|
||
class GitWebhookServiceProvider extends ServiceProvider | ||
{ | ||
|
||
/** | ||
* Bootstrap the application services. | ||
*/ | ||
public function boot() | ||
{ | ||
$this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); | ||
|
||
if ($this->app->runningInConsole()) { | ||
$this->publishes([ | ||
__DIR__ . '/../config/config.php' => config_path('git-webhook.php'), | ||
], 'config'); | ||
|
||
$this->publishes([ | ||
__DIR__ . '/../storage/deploy_stub.sh' => storage_path('git-webhook/git_deploy.sh'), | ||
], 'scripts'); | ||
} | ||
|
||
// Registering package commands. | ||
$this->commands([DefaultGithubDeploy::class]); | ||
} | ||
|
||
/** | ||
* Register the application services. | ||
*/ | ||
public function register() | ||
{ | ||
// Automatically apply the package configuration | ||
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'git-webhook'); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
|
||
# activate maintenance mode | ||
php artisan down | ||
|
||
# update source code | ||
git pull | ||
|
||
# update PHP dependencies | ||
composer install --no-interaction --no-dev --prefer-dist | ||
# --no-interaction Do not ask any interactive question | ||
# --no-dev Disables installation of require-dev packages | ||
# --prefer-dist Forces installation from package dist even for dev versions | ||
# --with-all-dependencies Allow upgrades, downgrades and removals for currently locked to specific versions | ||
|
||
# update database | ||
php artisan migrate --force | ||
# --force Required to run when in production. | ||
|
||
# stop maintenance mode | ||
php artisan up |
Oops, something went wrong.