diff --git a/.github/webhooks/deploy.sh b/.github/webhooks/deploy.sh new file mode 100755 index 0000000..f15df0a --- /dev/null +++ b/.github/webhooks/deploy.sh @@ -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 \ No newline at end of file diff --git a/.github/webhooks/webhook.conf.template b/.github/webhooks/webhook.conf.template new file mode 100644 index 0000000..84b25a4 --- /dev/null +++ b/.github/webhooks/webhook.conf.template @@ -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" + } + } + } + ] + } + } + ] \ No newline at end of file diff --git a/README.md b/README.md index 6554e3a..c4e7990 100644 --- a/README.md +++ b/README.md @@ -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.