-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathpublish.sh
executable file
·80 lines (66 loc) · 1.86 KB
/
publish.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
75
76
77
78
79
80
#!/bin/bash
#GIT_PATH=/home/stt/datacore
GIT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
pushd $GIT_PATH
if [[ -f ".git/index.lock" ]]; then
echo "ERROR: Git repository is locked, waiting to unlock." >&2
sleep 5
continue
fi
# use as "./publish.sh -f" to force rebuilding even if git is up to date
if [ $# -eq 0 ] || [ $1 != "-f" ]
then
git fetch
repo_name=$(basename -s .git "$(git config --get remote.origin.url)")
upstream="$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>/dev/null)"
# upstream was not configured
if [[ -z "$upstream" ]]; then
echo "ERROR: Git repository does not have an upstream source."
exit 1
fi
git_local=$(git rev-parse @)
git_remote=$(git rev-parse "$upstream")
git_base=$(git merge-base @ "$upstream")
if [[ "$git_local" == "$git_remote" ]]; then
echo "No update to pull."
exit 1
elif [[ "$git_local" == "$git_base" ]]; then
echo "Update found, pulling update and rebuilding website."
elif [[ "$git_remote" == "$git_base" ]]; then
echo "ERROR: Local git repo is ahead of remote. You may need to push or revert changes."
exit 1
else
echo "ERROR: Local git repo has diverged from remote. Unable to fix."
exit 1
fi
fi
# This would be more thorough but would also require re-installing all dependencies in node_modules
#git clean -x
rm -rf ./public/
rm -rf ./public_old/
rm -rf ./.cache/
rm schema.json
rm schema.graphql
git pull 2>&1
if [ $? -ne 0 ]
then
echo "Failed during git pull"
exit 1
fi
yarn install 2>&1
if [ $? -ne 0 ]
then
echo "Failed during yarn install"
exit 2
fi
yarn run build
if [ $? -ne 0 ]
then
echo "Failed during yarn build"
exit 3
fi
mv public_web public_old
mv public public_web
rm -rf ./public_old/
popd
# sudo systemctl restart nginx