Download the PHP package 8ctopus/git-hook without Composer
On this page you can find all versions of the php package 8ctopus/git-hook. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 8ctopus/git-hook
More information about 8ctopus/git-hook
Files in 8ctopus/git-hook
Package git-hook
Short Description Automate deployment for git pushes to GitHub and Gitea
License MIT
Homepage https://github.com/8ctopus/git-hook
Informations about the package git-hook
git hook
Automate deployment for git pushes to GitHub and Gitea using webhooks.
Automatically push your git repository changes to any website.
demo
- git clone the repository
- start a local php development server:
php -S localhost:80 demo.php - run the curl request which simulates the webhook request
install
composer require 8ctopus/git-hook
GitHub usage
-
Create a new page such as this one in a public part of your website (in this example
https://example.com/api/myhook/index.php) - In the GitHub project, go to
Settings>Webhooks>Add webhook. - Set
Payload URLtohttps://example.com/api/myhook/ - Set
Content typetoapplication/json - Set
Secretusing a strong password (same as in the scriptSAME_SECRET_KEY_AS_IN_GITHUB_ADMIN) - Set
Just the push event - Check
Active - Click
Add Webhook - Once added, click on it and scroll to the bottom to check the first delivery. If the first delivery succeeded you are all set. If it failed, review the response error and click
Redeliveronce you think you fixed it.
Note: Also read the important notes below.
Gitea usage
-
Create a new page such as this one in a public part of your website (in this example
https://example.com/api/myhook/index.php) -
update your gitea configuration in order to allow to send webhooks to your domain
- In the Gitea project, go to
Settings, selectGiteafromAdd webhook. - Set
Target URLtohttps://example.com/api/myhook/ - Set
HTTP MethodtoPOST - Set
Post Content Typetoapplication/json - Set
Secretusing a strong password (same as in the scriptSAME_SECRET_KEY_AS_IN_GITEA_ADMIN) - Set
Trigger OntoPush Events - Set
Branch filtertomasteror any branch you want to trigger the script - Check
Active - Click
Add Webhook - Once added, click on it and scroll to the bottom and click
Test Delivery - If the delivery succeeds you are all set. If it fails, go to the server and check the log.
important notes for both github and gitea
Note: for git pulls to work using user www-data (the apache typically runs under that user), you probably will need to:
-
make sure the upstream is set, so git knows where to pull from
- make sure user
www-datais the owner of the git repository. If not, you will get the error message
Note: If you are concerned about weaker security, you can consider giving user www-data permissions to run git as another user such as ubuntu. This way, your webserver files can be owned by ubuntu and www-data can only read them. I'm not security specialist, so be warned.
Note: for git pulls to work using user www-data (the apache processes typically run under that user), you probably will need to:
- include the user and password (must be url encoded) inside the git remote url
callbacks
Callbacks can be implemented per command or for every command:
Both callbacks have the same signature
Returning false aborts the deployment
debugging
The deployment script can be easily debugged locally using ngrok.
- run ngrok
ngrok http 80 - update the
Payload URLfor Github orTarget URLfor Gitea to the ngrok address, similar to this onehttps://6daf-31-218-13-51.ngrok-free.app - run the php local server
php -S localhost:80 demo.php - start visual studio code debugging and set a breakpoint in
demo.php - resend the webhook request
clean code
composer fix(-risky)
phpstan
composer phpstan
phpmd
composer phpmdAll versions of git-hook with dependencies
psr/http-message Version ^1.0|^2.0
psr/log Version ^1.1.4|^2.0|^3.0
ext-mbstring Version *