git-webhook-ci/README.md

79 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

2023-02-26 10:58:32 +01:00
# git-webhook-ci
2024-04-29 21:19:03 +02:00
2023-02-26 10:58:32 +01:00
Tool to automatize your deploy based on file write changes
2024-04-29 21:19:03 +02:00
2023-02-26 11:07:21 +01:00
## Description
2024-04-29 21:19:03 +02:00
2024-05-02 08:46:36 +02:00
After some change is made in our listener file the script placed on path set on `.yaml` configuration falled placed on `./configs/app.yaml` variable called **webhook_script_path** will be executed.
2023-02-26 10:58:32 +01:00
## Context
2024-04-29 21:19:03 +02:00
2023-02-26 10:58:32 +01:00
As a security risk that could be allow a webhook listener on a VPS for your git repository, I've decided
to create this package which is a listener to file changes on write. This will trigger a bash script which
you shold place on your server to run desired tasks. In my case I've done this to run a bash deploy command like
2024-04-29 21:19:03 +02:00
- git pull
- build
- move build to desired dir
- restart services like nginx or whatever
2023-02-26 10:58:32 +01:00
## Installation
2024-04-29 21:19:03 +02:00
2023-02-26 10:58:32 +01:00
### Requirements
2024-04-29 21:19:03 +02:00
2024-04-29 21:52:15 +02:00
- [Go version > 1.22](https://go.dev/dl/)
2023-02-26 10:58:32 +01:00
- [GNU Make 4.3](https://www.gnu.org/software/make/)
- [goreportcard-cli](https://github.com/gojp/goreportcard)
- [golangci-lint](https://golangci-lint.run/)
2024-04-29 21:19:03 +02:00
2023-02-26 11:07:21 +01:00
### Environment Vars
2024-04-29 21:19:03 +02:00
2024-04-29 21:52:15 +02:00
As shown in app.example.yml you have to configure this variables in order to make your binary works right:
2024-04-29 21:19:03 +02:00
2023-02-26 11:07:21 +01:00
```.env
2024-04-29 21:52:15 +02:00
script_binary_path: "/bin/bash"
webhook_script_path: "./test-script.sh"
file_to_watch_path: "./test_monitor.txt"
2023-02-26 11:07:21 +01:00
```
## How to use
2024-04-29 21:19:03 +02:00
2023-02-26 11:07:21 +01:00
### Build
2024-04-29 21:19:03 +02:00
2023-02-26 11:07:21 +01:00
To build you can only just `make build` command
2024-04-29 21:19:03 +02:00
2023-02-26 11:07:21 +01:00
```bash
make build
2023-02-26 19:00:02 +01:00
```
## Tests
2024-04-29 21:19:03 +02:00
2023-02-26 19:00:02 +01:00
```bash
make test-coverage
```
2024-04-29 21:19:03 +02:00
2023-02-26 19:00:02 +01:00
output:
2024-04-29 21:19:03 +02:00
2023-02-26 19:00:02 +01:00
```terminal
coverage: 80.0% of statements
ok gitea.urkob.com/urko/git-webhook-ci/internal/watcher 2.024s coverage: 80.0% of statements
coverage: 100.0% of statements
ok gitea.urkob.com/urko/git-webhook-ci/pkg/watcher 0.017s coverage: 100.0% of statements
```
## goreportcard
2024-04-29 21:19:03 +02:00
2023-02-26 19:00:02 +01:00
```bash
➜ git-webhook-ci git:(main) ✗ make goreportcard
oreportcard-cli -v
Grade .......... A+ 100.0%
Files .................. 6
Issues ................. 0
gofmt ............... 100%
go_vet .............. 100%
gocyclo ............. 100%
ineffassign ......... 100%
license ............. 100%
misspell ............ 100%
2024-04-29 21:19:03 +02:00
```