1 | #!/bin/sh |
2 |
|
3 | unset GIT_DIR |
4 | mkdir -p /opt/webapps/project |
5 | cd /opt/webapps/project || exit |
6 |
|
7 |
|
8 | CURR_BRANCH=$(git symbolic-ref --short -q HEAD) |
9 | echo "current branch: ${CURR_BRANCH}" |
10 | TARGET_BRANCH=$(echo "$1" | awk -F/ '{print $3}') |
11 | echo "target branch: ${TARGET_BRANCH}" |
12 |
|
13 |
|
14 | git init |
15 | git remote add origin /opt/webapps/project-bare.git |
16 |
|
17 | git reset --hard |
18 | git clean -df |
19 |
|
20 |
|
21 | git fetch origin |
22 |
|
23 | if [ ! -f "/opt/webapps/project-bare.git/refs/heads/${TARGET_BRANCH}" ] |
24 | then |
25 | echo "target branch ${TARGET_BRANCH} has been deleted" |
26 | |
27 | if [ "${TARGET_BRANCH}" = "${CURR_BRANCH}" ] |
28 | then |
29 | git checkout master |
30 | fi |
31 | |
32 | git branch -D "${TARGET_BRANCH}" |
33 | else |
34 | if [ "${TARGET_BRANCH}" = "${CURR_BRANCH}" ] |
35 | then |
36 | echo "same branch! rebase origin/${TARGET_BRANCH}." |
37 | git rebase origin/"${TARGET_BRANCH}" |
38 | else |
39 | echo "different branch! checkout to ${TARGET_BRANCH}." |
40 | git branch -D "${TARGET_BRANCH}" |
41 | git checkout -b "${TARGET_BRANCH}" origin/"${TARGET_BRANCH}" |
42 | fi |
43 | fi |
44 |
|
45 | echo "pull done" |
46 |
|
47 |
|
48 | npm install |
49 |
|
50 | rm -rf dist |
51 | npm run build |
52 |
|
53 | pm2 restart project |
54 | echo "deployment done" |