-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-folder.sh
113 lines (84 loc) · 2.78 KB
/
git-folder.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
#set -e
# latest commit
LATEST_COMMIT=$(git rev-parse HEAD)
echo "======== CHANGE LIST ========="
echo "${LATEST_COMMIT}"
git log -m -1 --pretty=%B
git diff-tree --no-commit-id -m --name-only -r "$LATEST_COMMIT"
echo ""
echo "============ Web ============="
WEB_FILES=$(git diff-tree --no-commit-id -m --name-only -r "$LATEST_COMMIT" web | xargs)
HAS_WEB_CHANGES=false
if [[ ${WEB_FILES} ]]; then
echo "${WEB_FILES}"
HAS_WEB_CHANGES=true
else
echo "No Changes"
fi
echo ""
echo "============ API ============="
API_FILES=$(git diff-tree --no-commit-id -m --name-only -r "$LATEST_COMMIT" functions | xargs)
HAS_API_CHANGES=false
if [[ ${API_FILES} ]]; then
echo "${API_FILES}"
HAS_API_CHANGES=true
else
echo "No changes"
fi
echo ""
echo "=========== SHARED ==========="
SHARED_FILES=$(git diff-tree --no-commit-id -m --name-only -r "$LATEST_COMMIT" shared | xargs)
HAS_SHARED_CHANGES=false
if [[ ${SHARED_FILES} ]]; then
echo "${SHARED_FILES}"
HAS_SHARED_CHANGES=true
else
echo "No changes"
fi
echo ""
echo "=========== SCRIPTS ==========="
SCRIPTS_FILES=$(git diff-tree --no-commit-id -m --name-only -r "$LATEST_COMMIT" scripts | xargs)
HAS_SCRIPTS_CHANGES=false
if [[ ${SCRIPTS_FILES} ]]; then
echo "${SCRIPTS_FILES}"
HAS_SCRIPTS_CHANGES=true
else
echo "No Changes"
fi
echo "==============================="
echo ""
#echo ${API_FILES}
#git diff-tree --no-commit-id -m --name-only -r "$LATEST_COMMIT" functions && HAS_API_CHANGES=true || HAS_API_CHANGES=false
#echo "Has Functions Changes = ${HAS_API_CHANGES}"
SHARED_FOLDER_COMMIT=$(git log -m --name-only -1 --format=format:%H --full-diff shared)
SCRIPTS_FOLDER_COMMIT=$(git log -m --name-only -1 --format=format:%H --full-diff scripts)
FIREBASE_COMMANDS=()
function join_by { local IFS="$1"; shift; echo "$*"; }
if ${HAS_WEB_CHANGES} || ${HAS_SHARED_CHANGES}; then
echo "Adding hosting to deploy list"
FIREBASE_COMMANDS+=('hosting')
fi
if ${HAS_API_CHANGES} || ${HAS_SHARED_CHANGES}; then
echo "Adding functions to deploy list"
FIREBASE_COMMANDS+=('functions')
fi
if ${HAS_SHARED_CHANGES} ; then
echo "files in SHARED has changed - not doing anything special"
fi
if ${HAS_SCRIPTS_CHANGES} ; then
echo "files in SCRIPTS has changed - need to run tests"
fi
if ! [[ ${HAS_WEB_CHANGES} && ${HAS_API_CHANGES} && ${HAS_SHARED_CHANGES} && ${HAS_SCRIPTS_CHANGES} ]]; then
echo "NO changes at all. "
fi
FIREBASE_MODULES=$(join_by , ${FIREBASE_COMMANDS[@]})
echo "Modules: $FIREBASE_MODULES"
echo
if [[ ${FIREBASE_MODULES} ]]; then
echo "Will execute firebase command \"firebase deploy --debug --only ${FIREBASE_MODULES}\""
echo ${FIREBASE_MODULES} > modules_to_deploy.txt
else
echo "Nothing to deploy"
echo "NONE" > modules_to_deploy.txt
fi