-
Notifications
You must be signed in to change notification settings - Fork 19
/
batch-example
executable file
·147 lines (123 loc) · 4.14 KB
/
batch-example
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
#!/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)"
gerrit_topic="batch-update"
commit_msg_file="$basedir/commit-message-foo.txt"
usage="usage: batch-example <master||stable/nn.nn> [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.
--skip-clone Skip the git clone, useful for local iterations.
--skip-commit Skip the commit.
--skip-review Skip 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 --sync-helpers --update-tox --update-reqs
Useful for iterating over the whole set of charms as a developer:
./batch-example master --skip-clone --skip-commit --skip-review --update-tox --update-reqs
Pile another patchset onto an existing local batch:
./batch-example master --skip-clone --amend --sync-helpers --update-tox --update-reqs"
charms="$(cat charms.txt)"
branch="$1"
all_params="$@"
if [ -z "$branch" ]; then
echo -e "$usage" && 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" == *--skip-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" != *--skip-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
# 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" != *--skip-commit* ]] && [[ -n "$git_status" ]]; then
git checkout -b $gerrit_topic
git add .
git commit -F $commit_msg_file
git_review
elif [[ "$all_params" == *--amend* ]] && [[ "$all_params" != *--skip-commit* ]] && [[ -n "$git_status" ]]; then
git checkout $gerrit_topic || git checkout -b $gerrit_topic
git add .
git commit --amend --no-edit
git_review
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