-
Notifications
You must be signed in to change notification settings - Fork 19
/
do-batch
executable file
·172 lines (145 loc) · 4.78 KB
/
do-batch
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
#!/bin/bash -e
#
# A tactical tool to submit batch charm changes. This is an example which
# represents a point-in-time need, and it can be re-used and adjusted for
# similar future tactical needs.
#
# REQUIRED: Update the following gerrit topic and commit message contents
# to fit the specific goal of your batch.
basedir="$(pwd)"
usage="usage: batch-example <master||stable/nn.nn> <commit-message> <topic> [arguments]
Arguments:
--sync-helpers Sync charm helpers and ceph helpers
--update-tox Update tox files from globals
--update-reqs Update requirements files from globals
--amend Amend the local commit
--force-review Force a review even if no changes are detected.
--do-clone Do the git clone
--do-commit Do the commit.
--do-review Do the gerrit review.
--rebase-master NOT IMPLEMENTED
Usage examples:
Clone all charms, do a charm-helpers sync and a ceph sync where applicable,
update the tox.ini files and *requirements.txt files throughout, and propose
the change as a gerrit review.
./batch-example master some_file.txt topic-name --sync-helpers --update-tox --update-reqs --do-clone --do-commit --do-review
Useful for iterating over the whole set of charms as a developer:
Note no clone, no commit, no review
./batch-example master --update-tox --update-reqs
Pile another patchset onto an existing local batch:
Note, no clone
./batch-example master some_file.txt topic-name --do-commit --do-review --amend --sync-helpers --update-tox --update-reqs"
charms=$(cd charms && ls -d1 *)
branch="$1"
commit_msg_file="$2"
gerrit_topic="$3"
all_params="$@"
echo "branch: $branch"
echo "commit msg file: $commit_msg_file"
echo "gerrit_topic: $gerrit_topic"
if [ -z "$branch" ]; then
echo -e "$usage"
echo "No branch name supplied"
exit 1
fi
if [ -z "$commit_msg_file" ]; then
echo -e "$usage"
echo "No commit_msg_file name supplied"
exit 1
fi
if [ -z "$gerrit_topic" ]; then
echo -e "$usage"
echo "No gerrit_topic supplied"
exit 1
fi
# Expect user to have git config ready for gerrit use
git config --get gitreview.username || ( echo " ! Not set: gitreview.username git config option"; echo -e "$usage"; exit 1 )
commit_msg="$(cat $commit_msg_file ||:)"
if [ -z "$commit_msg" ]; then
echo " ! $commit_msg_file not found or empty." && exit 1
fi
function git_get(){
(
if [[ "$all_params" == *--amend* ]] && [[ ! -d $2 ]]; then
echo " + Clone $1 -> $2"
git clone $1 $2
cd $2
git checkout $3
elif [[ "$all_params" != *--amend* ]] && [[ -d $2 ]]; then
echo " ! Dir exists: $2. Consider running 'make clean' or using --amend."
exit 1
else
echo " . Re-using checkout dir $2"
cd $2
git branch -v
fi
)
}
function git_review(){
if [[ "$all_params" != *--do-review* ]]; then
echo " . Skipping gerrit review for $charm."
elif [[ "$all_params" != *--force-review* ]]; then
echo " . Submitting gerrit review for $charm."
git review
elif [[ "$all_params" == *--force-review* ]]; then
echo " . Submitting gerrit review for $charm (non-fatal on failure)."
git review ||:
else
echo " ! Unknown condition in git_review"
exit 1
fi
}
# Get charms
if [[ "$all_params" == *--do-clone* ]]; then
./get-charms $branch
fi
# Do stuff
if [[ "$all_params" == *--update-tox* ]]; then
pwd
./_update-tox-files
fi
if [[ "$all_params" == *--update-reqs* ]]; then
./_update-requirements
fi
if [[ "$all_params" == *--sync-helpers* ]]; then
./do-batch-with _do-single-charm-sync
fi
# fix up the commit message
if [[ ! "$commit_msg_file" =~ ^// ]]; then
commit_msg_file="$basedir/$commit_msg_file"
echo "absolute for commit_msg_file is: $commit_msg_file"
fi
# Commit
for charm in $charms; do
echo "===== $charm ====="
(
cd "charms/$charm"
git_status="$(git status -s)"
if [[ "$all_params" == *--force-review* ]]; then
git_status="The Force is strong."
fi
if [[ "$all_params" != *--amend* ]] && [[ "$all_params" == *--do-commit* ]] && [[ -n "$git_status" ]]; then
git checkout -b $gerrit_topic
git add .
git commit -F $commit_msg_file
elif [[ "$all_params" == *--amend* ]] && [[ "$all_params" == *--do-commit* ]] && [[ -n "$git_status" ]]; then
git checkout $gerrit_topic || git checkout -b $gerrit_topic
git add .
git commit --amend -F $commit_msg_file
elif [[ "$all_params" == *--do-review* ]]; then
git_review || true
else
echo " - No changes for $charm, skipping commit and git review."
fi
)
done
# TODO: NOT IMPLEMENTED
# Optionally rebase with master
# if [[ "${REBASE_MASTER^^}" == "TRUE" ]]; then
# (
# git checkout master
# git pull
# git checkout $gerrit_topic || git checkout -b $gerrit_topic
# git rebase master
# )
# fi