This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
report-changed-services
executable file
·145 lines (126 loc) · 3.84 KB
/
report-changed-services
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# this depends on bash >= 4 as it uses associative arrays to handle
# lists of filenames that may contain spaces
set -e
USAGE='report-changed-services'
DESCRIPTION='
Deploy helper to figure out what services were changed in a merge
commit. Long term it would be better to use something like bazel,
but this is good enough for now.
This does not figure out when docker image base layers have changed,
it only looks at the files in our monorepo to guess at which services
have changes.
We first get a list of all files changed in the merge commit or the
branch being tested.
Then, we run a list of checks for each service to see if that service
has any patterns that match the file list in order to determine if the
service needs to be deployed.
Dependencies: requires git to be installed, requires bash >= 4'
function usage() {
echo "$USAGE" "$DESCRIPTION" >&2
}
type git >/dev/null 2>&1 || {
echo >&2 "Error: git must be installed. Aborting."
usage
exit 1
}
[ $# -eq 0 ] || {
usage
exit 1
}
if [ "${BASH_VERSINFO:-0}" -lt 4 ]; then
echo "This version of bash does not support associative arrays, cannot run"
usage
exit 1
fi
CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
echo "Current branch is ${CURRENT_BRANCH}"
CURRENT_REV=$(git rev-parse HEAD)
declare -A changed_files
if [[ "$CURRENT_BRANCH" == "master" ]]; then
# If we are on master, calculate the changes in the merge commit.
for filename in $(git diff --name-only HEAD^! 2>/dev/null); do
changed_files["$filename"]=$filename
done
else
# If we are not on master, calculate the differences on this branch that are not yet in master
for filename in $(git diff origin/master... --name-only 2>/dev/null); do
changed_files["$filename"]=$filename
done
fi
CHANGE_COUNT=${#changed_files[@]}
if [ "$CHANGE_COUNT" -eq 0 ]; then
echo 'Did not detect any changed files'
else
echo "Found $CHANGE_COUNT changed files"
printf " * %s\n" "${changed_files[@]}"
fi
# in order to minimize gratuitous rebuilds and publishing container
# revisions with no meaningful changes, we use the current shipped container
# when a service hasn't changed. The origin/master revision will be the tag
# for the currently shipped version of any service.
export DEPLOY_GATEKEEPER=false
export GATEKEEPER_REV=latest
export DEPLOY_WEBUI=false
export WEBUI_REV=latest
export DEPLOY_KEYCLOAK=false
export KEYCLOAK_REV=latest
export DEPLOY_WORKER=false
export WORKER_REV=latest
export DEPLOY_HAVENAPI=false
export HAVENAPI_REV=latest
export DEPLOY_FLYWAY=false
export FLYWAY_REV=latest
export DEPLOY_FAKTORY=false
export FAKTORY_REV=latest
for filename in "${changed_files[@]}"; do
case $filename in
gatekeeper/*)
DEPLOY_GATEKEEPER=true
GATEKEEPER_REV=${CURRENT_REV}
;;
webui/*)
DEPLOY_WEBUI=true
WEBUI_REV=${CURRENT_REV}
;;
keycloak/*)
DEPLOY_KEYCLOAK=true
KEYCLOAK_REV=${CURRENT_REV}
;;
keycloak-service-providers/*)
DEPLOY_KEYCLOAK=true
KEYCLOAK_REV=${CURRENT_REV}
;;
worker/*)
DEPLOY_WORKER=true
WORKER_REV=${CURRENT_REV}
;;
havenapi/*)
DEPLOY_HAVENAPI=true
HAVENAPI_REV=${CURRENT_REV}
;;
flyway/*)
DEPLOY_FLYWAY=true
FLYWAY_REV=${CURRENT_REV}
;;
faktory/*)
DEPLOY_FAKTORY=true
FAKTORY_REV=${CURRENT_REV}
;;
*)
echo "$filename did not trigger a service deploy"
;;
esac
done
printf "\n"
echo "***********************************"
echo "* Services that need deployment *"
echo "***********************************"
printf "\n"
echo "DEPLOY_GATEKEEPER=${DEPLOY_GATEKEEPER}"
echo "DEPLOY_WEBUI=${DEPLOY_WEBUI}"
echo "DEPLOY_KEYCLOAK=${DEPLOY_KEYCLOAK}"
echo "DEPLOY_WORKER=${DEPLOY_WORKER}"
echo "DEPLOY_HAVENAPI=${DEPLOY_HAVENAPI}"
echo "DEPLOY_FLYWAY=${DEPLOY_FLYWAY}"
echo "DEPLOY_FAKTORY=${DEPLOY_FAKTORY}"