initial blind implementation & documentation of a webhook

This commit is contained in:
Ulf Gebhardt 2023-10-04 17:35:12 +02:00
parent 142c9e42c9
commit 2d54fb24ca
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
3 changed files with 73 additions and 0 deletions

24
.github/webhooks/deploy.sh vendored Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
# Find current directory & configure paths
SCRIPT_PATH=$(realpath $0)
SCRIPT_DIR=$(dirname $SCRIPT_PATH)
PROJECT_ROOT=$SCRIPT_DIR/../..
DEPLOY_DIR=$i
BUILD_DIR=$PROJECT_ROOT/docs/.vuepress/dist
GIT_REF=$(git rev-parse --short HEAD)
DEPLOY_DIR_REF=$1-$GIT_REF
# Parameter is a proper directory?
if [ -d "$DEPLOY_DIR_REF" ]; then
return "Directory '$DEPLOY_DIR_REF' does already exist" 2>/dev/null || exit 1
fi
# Build the project
cd $PROJECT_ROOT
rm -R $BUILD_DIR
npm run build
# Copy files and Sym link
cp $BUILD_DIR $DEPLOY_DIR_REF
ln -sf $DEPLOY_DIR_REF $DEPLOY_DIR

37
.github/webhooks/webhook.conf.template vendored Normal file
View File

@ -0,0 +1,37 @@
[
{
"id": "github",
"execute-command": "$PROJECT_ROOT/.github/webhooks/deploy.sh",
"pass-arguments-to-command": [
{
"source": "string",
"name": "$DEPLOY_DIR"
}
],
"command-working-directory": "$PROJECT_ROOT",
"trigger-rule": {
"and": [
{
"match": {
"type": "payload-hash-sha1",
"secret": "$WEBHOOK_GITHUB_SECRET",
"parameter": {
"source": "header",
"name": "X-Hub-Signature"
}
}
},
{
"match": {
"type": "value",
"value": "refs/heads/$WEBHOOK_GITHUB_BRANCH",
"parameter": {
"source": "payload",
"name": "ref"
}
}
}
]
}
}
]

View File

@ -42,6 +42,18 @@ Run the tests to ensure everything is working as expected
npm test
```
## Deploy
You can use the webhook template `webhook.conf.template` and the `deploy.sh` script in `.github/webhooks/` to implement an automatic deployment from a (github) webhook.
To work follow these steps (using alpine):
```bash
apk add webhook
cp .github/webhooks/webhook.conf /etc/webhook.conf
# adjust content of /etc/webhook.conf accordingly
systemctl enable webhook
systemctl start webhook
```
## How it works
This repository utilizes `vuepress-deploy` to automatically deploy the current `master` branch to github pages.