-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgradle-each.sh
executable file
·189 lines (152 loc) · 4.09 KB
/
gradle-each.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
#!/bin/bash
#
# This shell script executes the given Gradle tasks on a range of commits.
show_help() {
echo "Usage: $0 --gradle-tasks assembleDebug --from-hash master --till-hash feature-branch --reverse-order false"
}
print_header() {
echo
echo "=============================================================================="
echo "${1}/${2}: Running Gradle task on \"$($3)\" ..."
echo "=============================================================================="
echo
}
print_success_footer() {
echo "Gradle task \"$1\" succeeded."
}
print_failure_footer() {
echo "Gradle task \"$1\" failed."
echo "Commit: \"$($2)\" ..."
}
print_java_version() {
echo "JAVA_HOME = $JAVA_HOME"
}
print_hash_values() {
echo
echo GRADLE_TASKS = "${GRADLE_TASKS}"
echo FROM_HASH = "${FROM_HASH}"
echo TILL_HASH = "${TILL_HASH}"
echo REVERSE_ORDER = "${REVERSE_ORDER}"
echo
}
build_commit() {
commit_index=$1
commits_count=$2
commit=$3
gradle_tasks=$4
# Check parameters
if [[ -z "${commit_index// }" ]]; then
echo "Error: Missing 'commit_index' argument in build_commit()."
exit 1
fi
if [[ -z "${commits_count// }" ]]; then
echo "Error: Missing 'commits_count' argument in build_commit()."
exit 1
fi
if [[ -z "${commit// }" ]]; then
echo "Error: Missing 'commit' argument in build_commit()."
exit 1
fi
if [[ -z "${gradle_tasks// }" ]]; then
echo "Error: Missing 'gradle_tasks' argument in build_commit()."
exit 1
fi
# Commands
git_short_log_cmd="git log --abbrev-commit --format=oneline -n 1 $commit"
gradlew_cmd="./gradlew $gradle_tasks"
print_header "${commit_index}" "${commits_count}" "$git_short_log_cmd"
git checkout "$commit"
git submodule update
chmod +x gradlew
# Execute Gradle command; store its exit code
$gradlew_cmd; gradlew_exit_code=$?
echo
echo "Gradle task exit code = $gradlew_exit_code"
if [ "$gradlew_exit_code" -eq "0" ]; then
print_success_footer "$gradle_tasks"
else
print_failure_footer "$gradle_tasks" "$git_short_log_cmd"
exit 1
fi
}
build_commits() {
gradle_tasks=$1
from_hash=$2
till_hash=$3
reverse_order=$4
# Check parameters
if [[ -z "${gradle_tasks// }" ]] || [[ -z "${from_hash// }" ]] || [[ -z "${till_hash// }" ]]; then
echo "Error: Missing arguments in build_commits()."
exit 1
fi
# Commmands
git_list_commits_hashes_cmd="git rev-list --reverse $from_hash..$till_hash"
git_list_commits_hashes_reversed_cmd="git rev-list $from_hash..$till_hash"
git_count_commit_hashes_cmd="git rev-list --count $from_hash..$till_hash"
print_java_version
# Iterating all commits
commits=$($git_list_commits_hashes_cmd)
commits_reversed=$($git_list_commits_hashes_reversed_cmd)
commits_count=$($git_count_commit_hashes_cmd)
if [ "$reverse_order" = false ]; then
index=1
for commit in ${commits}
do
build_commit "${index}" "${commits_count}" "${commit}" "${gradle_tasks}"
((index++))
done
else
index=$commits_count
for commit in ${commits_reversed}
do
build_commit "${index}" "${commits_count}" "${commit}" "${gradle_tasks}" "${reverse_order}"
((index--))
done
fi
}
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-g|--gradle-tasks)
GRADLE_TASKS="$2"
shift # past argument
;;
-f|--from-hash)
FROM_HASH="$2"
shift # past argument
;;
-t|--till-hash)
TILL_HASH="$2"
shift # past argument
;;
-r|--reverse-order)
REVERSE_ORDER="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
if [[ -z "${GRADLE_TASKS// }" ]] || [[ -z "${FROM_HASH// }" ]] || [[ -z "${TILL_HASH// }" ]]; then
if [[ "${GRADLE_TASKS// }" ]] && [[ -z "${FROM_HASH// }" ]] && [[ -z "${TILL_HASH// }" ]]; then
# Run with default branch names / references.
FROM_HASH="master"
TILL_HASH="HEAD"
elif [[ -z "${FROM_HASH// }" ]] || [[ -z "${TILL_HASH// }" ]]; then
print_hash_values
show_help
exit 0
fi
fi
# Optional "--reverse-order" parameter
if [[ "${REVERSE_ORDER// }" ]]; then
REVERSE_ORDER=true
else
REVERSE_ORDER=false
fi
print_hash_values
build_commits "${GRADLE_TASKS}" "${FROM_HASH}" "${TILL_HASH}" "${REVERSE_ORDER}"
exit 0