Skip to content

Commit 1a7b7a4

Browse files
committed
docs: create readme
1 parent 7f05134 commit 1a7b7a4

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# GRHooks - Webhook Server Configuration
2+
3+
GRHooks is a configurable webhook server that can execute commands or scripts in response to incoming webhook events. It supports multiple webhook configurations with flexible command execution options.
4+
5+
## Install prebuilt binaries via shell script
6+
7+
```sh
8+
bash <(curl -sSL https://raw.githubusercontent.com/RustLangES/grhooks/main/scripts/install.sh)
9+
```
10+
11+
## Install prebuilt binaries via powershell script
12+
13+
```sh
14+
powershell -ExecutionPolicy Bypass -c "$ProgressPreference='SilentlyContinue'; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/RustLangES/grhooks/main/scripts/install.ps1'))"
15+
```
16+
17+
## Configuration File
18+
19+
GRHooks uses a configuration file in TOML, YAML, or JSON format. The file should contain the server settings and webhook definitions.
20+
21+
### Example Configuration (TOML)
22+
23+
```toml
24+
port = 8080
25+
26+
[[webhooks]]
27+
path = "deploy"
28+
secret = "mysecret123" # or "${{ env(\"MY_SECRET_FROM_ENV\") }}"
29+
events = ["push", "pull_request"]
30+
command = "echo 'Deployment triggered by ${{event.action}}'"
31+
32+
[[webhooks]]
33+
path = "build"
34+
shell = ["/bin/bash", "-c"]
35+
script = "scripts/build.sh"
36+
events = ["create"]
37+
```
38+
39+
## Configuration Options
40+
41+
### Server Configuration
42+
43+
| Field | Type | Description | Default | Required |
44+
| ------- | ------ | ----------------------------- | ------- | -------- |
45+
| port | u16 | Port to listen on | - | Yes |
46+
| verbose | String | Logging verbosity level (0-4) | "0" | No |
47+
48+
### Webhook Configuration
49+
50+
Each webhook is defined in the `webhooks` array with the following options:
51+
52+
| Field | Type | Description | Required |
53+
| ------- | ------------------- | ---------------------------------------------------------------------- | ------------------------------------ |
54+
| path | String | URL path for the webhook | No (defaults to /) |
55+
| secret | Option<String> | Secret for validating webhook signatures | No |
56+
| events | Vec<String> | List of events this webhook should handle (use `["*"]` for all events) | Yes |
57+
| shell | Option<Vec<String>> | Custom shell and arguments to use for command execution | No (defaults to `/bin/sh -c`) |
58+
| command | Option<String> | Command to execute when webhook is triggered | Either command or script must be set |
59+
| script | Option<PathBuf> | Path to script file to execute when webhook is triggered | Either command or script must be set |
60+
61+
## Template Variables
62+
63+
Commands and scripts can use template variables that will be replaced with values from the webhook payload. Variables use the syntax `${{path.to.value}}`.
64+
65+
> [!NOTE]
66+
> The template is redered using the [srtemplate](https://github.com/SergioRibera/srtemplate) template engine.
67+
68+
### Common Variables
69+
70+
- `${{event.type}}`: The event type that triggered the webhook
71+
72+
## Running GRHooks
73+
74+
### Command Line Usage
75+
76+
```bash
77+
grhooks [-v...] /path/to/config.[toml|yaml|json]
78+
```
79+
80+
Options:
81+
82+
- `-v`: Increase verbosity (can be used multiple times)
83+
84+
### Environment Variables
85+
86+
- `GRHOOKS_MANIFEST_DIR`: Path to configuration file
87+
- `GRHOOKS_LOG`: Set logging verbosity (0-4 or trace, info, debug, warning, error)
88+
89+
## Webhook Security
90+
91+
When a `secret` is configured in the webhook:
92+
93+
1. GRHooks will validate the `X-Hub-Signature-256` header
94+
2. Only requests with valid signatures will be processed
95+
3. The secret should match what's configured in your Git provider
96+
97+
## Example Use Cases
98+
99+
1. **Deployment Automation**:
100+
101+
```toml
102+
[[webhooks]]
103+
path = "deploy-prod"
104+
events = ["deployment"]
105+
command = "kubectl set image deployment/myapp app=${{event.deployment.payload.image}}"
106+
```
107+
108+
2. **CI/CD Pipeline**:
109+
110+
```toml
111+
[[webhooks]]
112+
path = "build"
113+
script = "scripts/ci-pipeline.sh"
114+
events = ["push"]
115+
```
116+
117+
3. **Notification System**:
118+
```toml
119+
[[webhooks]]
120+
path = "notify"
121+
events = ["*"]
122+
command = "curl -X POST -d '{\"text\":\"Event ${{event.type}} received\"}' $SLACK_WEBHOOK"
123+
```
124+
125+
## Supported Webhook Providers
126+
127+
GRHooks currently supports webhooks from:
128+
129+
- GitHub
130+
131+
Plans to support:
132+
133+
- GitLab
134+
- Bitbucket

0 commit comments

Comments
 (0)