-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.sh
executable file
·74 lines (54 loc) · 1.65 KB
/
build.sh
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
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
set -o errexit
repo="origin"
build_dir="build"
deploy_branch="gh-pages"
main() {
bundle exec middleman build --clean
prev_branch=`git rev-parse --abbrev-ref HEAD`
commit_hash=`git log -n 1 --format="%H" HEAD`
if git ls-remote --exit-code "${repo}" "refs/heads/${deploy_branch}"; then
git fetch --force "${repo}" "${deploy_branch}:${deploy_branch}"
fi
if git show-ref --verify --quiet "refs/heads/${deploy_branch}"; then
deploy_incremental
else
deploy_initial
fi
if [[ "${pre_branch}" = "HEAD" ]]; then
git update-ref --no-deref HEAD "${commit_hash}" "${deploy_branch}"
else
git symbolic-ref HEAD "refs/heads/${prev_branch}"
fi
git reset --mixed
}
deploy_initial() {
git --work-tree "${build_dir}" checkout --orphan "${deploy_branch}"
git --work-tree "${build_dir}" add --all
commit
}
deploy_incremental() {
git symbolic-ref HEAD "refs/heads/${deploy_branch}"
git --work-tree "${build_dir}" reset --mixed --quiet
git --work-tree "${build_dir}" add --all
set +o errexit
diff=$(git --work-tree "${build_dir}" diff --exit-code --quiet HEAD --)$?
set -o errexit
case "${diff}" in
0)
echo "No changes found, no need to deploy."
;;
1)
commit
;;
*)
echo "Diff exited with code ${diff}. No idea what that means. Just gonna leave you here to figure it out."
return $diff
;;
esac
}
commit() {
git --work-tree "${build_dir}" commit -m "Publish updated docs"
git push --quiet "${repo}" "${deploy_branch}"
}
main