forked from openedx-unsupported/devstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo.sh
executable file
·265 lines (240 loc) · 8.99 KB
/
repo.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env bash
set -e
set -o pipefail
# Script for Git repos housing edX services. These repos are mounted as
# data volumes into their corresponding Docker containers to facilitate development.
# Repos are cloned to/removed from the directory above the one housing this file.
if [ -z "$DEVSTACK_WORKSPACE" ]; then
echo "need to set workspace dir"
exit 1
elif [ -d "$DEVSTACK_WORKSPACE" ]; then
cd "$DEVSTACK_WORKSPACE"
else
echo "Workspace directory $DEVSTACK_WORKSPACE doesn't exist"
exit 1
fi
# When you add new services should add them to both repos and ssh_repos
# (or non_release_repos and non_release_ssh_repos if they are not part
# of Open edX releases).
repos=(
"https://github.com/openedx/course-discovery.git"
"https://github.com/openedx/credentials.git"
"https://github.com/openedx/cs_comments_service.git"
"https://github.com/edx/ecommerce.git"
"https://github.com/openedx/edx-notes-api.git"
"https://github.com/openedx/edx-platform.git"
"https://github.com/openedx/xqueue.git"
"https://github.com/edx/edx-analytics-dashboard.git"
"https://github.com/openedx/frontend-app-gradebook.git"
"https://github.com/openedx/frontend-app-learner-dashboard.git"
"https://github.com/openedx/frontend-app-learner-record.git"
"https://github.com/edx/frontend-app-payment.git"
"https://github.com/openedx/frontend-app-publisher.git"
"https://github.com/edx/edx-analytics-dashboard.git"
"https://github.com/edx/edx-analytics-data-api.git"
)
non_release_repos=(
"https://github.com/openedx/frontend-app-authn.git"
"https://github.com/openedx/frontend-app-course-authoring.git"
"https://github.com/openedx/frontend-app-learning.git"
"https://github.com/openedx/frontend-app-library-authoring.git"
"https://github.com/edx/registrar.git"
"https://github.com/edx/frontend-app-program-console.git"
"https://github.com/openedx/frontend-app-account.git"
"https://github.com/openedx/frontend-app-profile.git"
"https://github.com/openedx/frontend-app-ora-grading.git"
)
ssh_repos=(
"[email protected]:openedx/course-discovery.git"
"[email protected]:openedx/credentials.git"
"[email protected]:openedx/cs_comments_service.git"
"[email protected]:edx/ecommerce.git"
"[email protected]:openedx/edx-notes-api.git"
"[email protected]:openedx/edx-platform.git"
"[email protected]:openedx/xqueue.git"
"[email protected]:edx/edx-analytics-dashboard.git"
"[email protected]:openedx/frontend-app-gradebook.git"
"[email protected]:openedx/frontend-app-learner-dashboard.git"
"[email protected]:openedx/frontend-app-learner-record.git"
"[email protected]:edx/frontend-app-payment.git"
"[email protected]:openedx/frontend-app-publisher.git"
"[email protected]:edx/edx-analytics-dashboard.git"
"[email protected]:edx/edx-analytics-data-api.git"
)
non_release_ssh_repos=(
"[email protected]:openedx/frontend-app-authn.git"
"[email protected]:openedx/frontend-app-course-authoring.git"
"[email protected]:openedx/frontend-app-learning.git"
"[email protected]:openedx/frontend-app-library-authoring.git"
"[email protected]:edx/registrar.git"
"[email protected]:edx/frontend-app-program-console.git"
"[email protected]:openedx/frontend-app-account.git"
"[email protected]:openedx/frontend-app-profile.git"
"[email protected]:openedx/frontend-app-ora-grading.git"
)
if [ -n "${OPENEDX_RELEASE}" ]; then
OPENEDX_GIT_BRANCH=open-release/${OPENEDX_RELEASE}
else
repos+=("${non_release_repos[@]}")
ssh_repos+=("${non_release_ssh_repos[@]}")
fi
name_pattern=".*/(.*).git$"
_checkout ()
{
repos_to_checkout=("$@")
for repo in "${repos_to_checkout[@]}"
do
# Use Bash's regex match operator to capture the name of the repo.
# Results of the match are saved to an array called $BASH_REMATCH.
if [[ ! $repo =~ $name_pattern ]]; then
echo "Cannot perform checkout on repo; URL did not match expected pattern: $repo"
exit 1
fi
name="${BASH_REMATCH[1]}"
# If a directory exists and it is nonempty, assume the repo has been cloned.
if [ -d "$name" ] && [ -n "$(ls -A "$name" 2>/dev/null)" ]; then
cd "$name"
_checkout_and_update_branch "${repo}"
cd ..
fi
done
}
checkout ()
{
_checkout "${repos[@]}"
}
_clone ()
{
repos_to_clone=("$@")
for repo in "${repos_to_clone[@]}"
do
# Use Bash's regex match operator to capture the name of the repo.
# Results of the match are saved to an array called $BASH_REMATCH.
if [[ ! $repo =~ $name_pattern ]]; then
echo "Cannot clone repo; URL did not match expected pattern: $repo"
exit 1
fi
name="${BASH_REMATCH[1]}"
# If a directory exists and it is nonempty, assume the repo has been checked out
# and only make sure it's on the required branch
if [ -d "$name" ] && [ -n "$(ls -A "$name" 2>/dev/null)" ]; then
if [ ! -d "$name/.git" ]; then
printf "ERROR: [%s] exists but is not a git repo.\n" "$name"
exit 1
fi
printf "The [%s] repo is already checked out. Checking for updates.\n" "$name"
cd "${DEVSTACK_WORKSPACE}/${name}"
_checkout_and_update_branch "${repo}"
cd ..
else
if [ -n "${OPENEDX_GIT_BRANCH:-}" ]; then
CLONE_BRANCH="-b ${OPENEDX_GIT_BRANCH}"
elif [[ "${repo}" == *"edx/ecommerce"* ]]; then
CLONE_BRANCH="-b 2u/main"
else
CLONE_BRANCH=""
fi
if [ "${SHALLOW_CLONE}" == "1" ]; then
git clone ${CLONE_BRANCH} -c core.symlinks=true --depth=1 "${repo}"
else
git clone ${CLONE_BRANCH} -c core.symlinks=true "${repo}"
fi
fi
done
cd - &> /dev/null
}
_checkout_and_update_branch ()
{
local current_repo=$1
GIT_SYMBOLIC_REF="$(git symbolic-ref HEAD 2>/dev/null)"
BRANCH_NAME=${GIT_SYMBOLIC_REF##refs/heads/}
if [ -n "${OPENEDX_GIT_BRANCH}" ]; then
CHECKOUT_BRANCH=${OPENEDX_GIT_BRANCH}
elif [[ "${current_repo}" == *"edx/ecommerce"* ]]; then
CHECKOUT_BRANCH="2u/main"
else
CHECKOUT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
fi
echo "Checking out branch ${CHECKOUT_BRANCH}"
if [ "${BRANCH_NAME}" == "${CHECKOUT_BRANCH}" ]; then
git pull origin ${CHECKOUT_BRANCH}
else
git fetch origin ${CHECKOUT_BRANCH}:${CHECKOUT_BRANCH}
git checkout ${CHECKOUT_BRANCH}
fi
find . -name '*.pyc' -not -path './.git/*' -delete
}
clone ()
{
_clone "${repos[@]}"
}
clone_ssh ()
{
_clone "${ssh_repos[@]}"
}
reset ()
{
read -p "This will switch to the default branch and pull changes in your local git checkouts. Would you like to proceed? [y/n] " -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Cancelling."
exit 1
fi
for repo in ${repos[*]}
do
if [[ ! $repo =~ $name_pattern ]]; then
echo "Cannot reset repo; URL did not match expected pattern: $repo"
exit 1
fi
name="${BASH_REMATCH[1]}"
if [ -d "$name" ]; then
DEFAULT_BRANCH=$(cd ${name}; git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
# Try to switch branch and pull, but fail if there are uncommitted changes.
if (cd "$name"; git checkout -q ${DEFAULT_BRANCH} && git pull -q --ff-only);
then
# Echo untracked files to simplify debugging and make it easier to see that resetting does not remove everything
untracked_files="$(cd ${name} && git ls-files --others --exclude-standard)"
if [[ $untracked_files ]];
then
echo "The following untracked files are in ${name} repository:"
echo "$untracked_files"
fi
else
echo >&2 "Failed to reset $name repo. Exiting."
echo >&2 "Please go to the repo and clean up any issues that are keeping 'git checkout $DEFAULT_BRANCH' and 'git pull' from working."
exit 1
fi
else
printf "The [%s] repo is not cloned. Skipping.\n" "$name"
fi
done
}
status ()
{
currDir=$(pwd)
for repo in ${repos[*]}
do
if [[ ! $repo =~ $name_pattern ]]; then
echo "Cannot check repo status; URL did not match expected pattern: $repo"
exit 1
fi
name="${BASH_REMATCH[1]}"
if [ -d "$name" ]; then
printf "\nGit status for [%s]:\n" "$name"
cd "$name";git status;cd "$currDir"
else
printf "The [%s] repo is not cloned. Skipping.\n" "$name"
fi
done
cd - &> /dev/null
}
if [ "$1" == "checkout" ]; then
checkout
elif [ "$1" == "clone" ]; then
clone
elif [ "$1" == "clone_ssh" ]; then
clone_ssh
elif [ "$1" == "reset" ]; then
reset
elif [ "$1" == "status" ]; then
status
fi