# git-build-triggers Provides webhooks to deploy from git repositories. * Setup `git-build-triggers.py` with config, providing a http backend * Put some reverse proxy in front (apache, nginx) * Configure webhook URL with bearer token in your favorite git hosting to trigger when a certain branch is pushed Only one build per configured repository will run at a time; when more builds are triggered while a build is already running, it will only trigger a single further build after the current one. A rebuild will first update the repository: ``` git clean force -d -x git remote update origin git reset --hard origin/$(git rev-parse --abbrev-ref HEAD) ``` If the top commit (`git rev-parse HEAD`) is the same as for the last build it won't trigger the build script. Otherwise it will run the build script and store its output. For consistency `git clean force -d -x` is run after the build again (a "recheck" would do that too without necessarily building anything, so this must not break your build results). You can visit the webhook URL in a browser to get the output of the last finished run (this also triggers a check for new commits); it won't wait for the current build to finish. `git-build-triggers.py` uses `http.server.HTTPServer` (https://docs.python.org/3/library/http.server.html), which isn't recommended for production, but should be good enough for this. But you might want to restrict access to somewhat trusted IP ranges. ## Install Dependencies: * python3 (probably >= 3.11) * pyyaml (https://github.com/yaml/pyyaml) * trio (https://github.com/python-trio/trio) * git Put the script `git-build-triggers.py` where you want (e.g. `~/bin` or `/usr/local/bin`). ## Config See `example.yaml` in this repo for basic structure. The configured repositories correspond to (different!) git checkouts on the local disk. The repository name is used with the `base-path` to build the full URL. A `base-path` of "/trigger-it", a repository name of "example" and `port: 8000` would provide `http://127.0.0.1:8000/trigger-it/example` as webhook. Tokens must be at least 16 characters long. A reverse proxy should be configured to add https. ## mypy linting ``` virtualenv --system-site-packages venv ./venv/bin/pip install trio-typing # and perhaps other dependencies ./venv/bin/python3 -m mypy git-build-triggers.py ```