-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-receive
executable file
·62 lines (55 loc) · 1.41 KB
/
post-receive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
# Deployment of Jekyll-Sites via Git Bare Repository and post-receive hook.
#
# https://github.com/fl3a/jekyll_deployment
#
# USAGE:
# - git hook: Place this script as .hooks/post-receive within your git repository
# - standalone: ${SCRIPT} /path/to/git-bare-repository
set -o errexit
set -o xtrace
function is_bare_repo () {
cd $1 && test $(git rev-parse --is-bare-repository) == "true" \
&& return 0 || return 1
}
function check_parameter() {
if [ -z "$1" ]; then
read oldrev newrev ref
pushed_branch=${ref#refs/heads/}
elif is_bare_repo $1; then
pushed_branch=
else
exit
fi
}
function configure() {
config=$(mktemp)
git show ${pushed_branch:-HEAD}:deploy.conf > $config || exit
source $config
if [ -z "$pushed_branch" ]; then
pushed_branch=$build_branch
fi
test "$pushed_branch" != "$build_branch" && exit
if [ -f "$extra_vars" ]; then
source $extra_vars
fi
}
function build() {
tmp=$(mktemp -d)
git clone --single-branch --branch $build_branch $git_repo $tmp
cd $tmp
bundle install || bundle install --redownload
JEKYLL_ENV=${env:-production} \
JEKYLL_BUILD_REVISION=$rev \
JEKYLL_GITHUB_TOKEN=$JEKYLL_GITHUB_TOKEN \
bundle exec jekyll build --source $tmp --destination $www $build_suffix
}
function cleanup() {
rm -rf $tmp $config
}
trap cleanup ERR SIGINT SIGKILL
check_parameter $1
configure
build
cleanup
eval $post_exec