-
Notifications
You must be signed in to change notification settings - Fork 6
/
post-receive
64 lines (45 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
63
64
#!/usr/bin/env bash
#
# Author: Jake Zimmerman
# Created: Tue 01 Sep 2015
# Last modified: Tue 01 Sep 2015
#
#
# post-receive hook
#
# Deploys a this repository to the deployment directory by forcing a checkout
# every time that we receive a change to the master branch from a push.
indent() { awk '{sub(/^/," ");print}'; }
# Fail if errors
set -o errexit
echo -e "\n\n"
# Initialize constants
SEMESTER="f21"
ROOT_DIR="/afs/cs/academic/class/07131-f18"
STAGING_DIR="$ROOT_DIR/.tmp"
GEM_HOME="$ROOT_DIR/.gems"
DEPLOYMENT_DIR="$ROOT_DIR/www/$SEMESTER"
read from_commit to_commit ref_name
if [[ ! $ref_name =~ .*/master$ ]]; then
echo "Ref $ref_name is not master, skipping deployment."
exit 0
fi
# Deploy the project
echo "Deploying project to $DEPLOYMENT_DIR"
rm -rf "$STAGING_DIR"
mkdir -p "$STAGING_DIR" "$GEM_HOME"
GIT_WORK_TREE="$STAGING_DIR" git checkout -f master
cd $STAGING_DIR
# for more information on the interplay of these variables, see this article:
# http://blog.jez.io/2014/12/22/ruby-virtualenvs/
export GEM_HOME
unset GEM_PATH
export PATH="$GEM_HOME/bin:$PATH"
echo -e "\nInstalling bundler"
gem install bundler | indent
echo -e "\nInstalling requirements"
bundle install | indent
echo -e "\nCompiling project"
jekyll build --destination "$DEPLOYMENT_DIR" | indent
rm -rf $STAGING_DIR
echo -e "\n\nSuccessfully deployed branch master.\n\n"