-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathold-workflows
executable file
·310 lines (283 loc) · 9.76 KB
/
old-workflows
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/usr/bin/env bash
set -e
source ./libexec/plugins/text
# bash versions
bash_3_2_57=3.2.57 # MACOS default
bash_4_4_23=4.4.23
bash_5_0_17=5.0.17
# python versions
python_3_8_3=3.8.3
# git versions
git_2_13_7=2.13.7
git_2_26_2=2.26.2
--worker-tag() {
# usege: --worker-tag <bash version> <git version>
echo ${1}-${2}
}
eg_docker_organization=beeshive
eg_documents_repository=${eg_docker_organization}/elegant-git-docs-worker
eg_documents_bash=${bash_5_0_17}
eg_documents_git=${git_2_26_2}
eg_documents_image=${eg_documents_repository}:$(--worker-tag ${eg_documents_bash} ${eg_documents_git})
eg_bats_repository=${eg_docker_organization}/elegant-git-bats-worker
bats_worker_tags=(
$(--worker-tag ${bash_3_2_57} ${git_2_13_7})
$(--worker-tag ${bash_4_4_23} ${git_2_13_7})
$(--worker-tag ${bash_5_0_17} ${git_2_13_7})
$(--worker-tag ${bash_3_2_57} ${git_2_26_2})
$(--worker-tag ${bash_4_4_23} ${git_2_26_2})
$(--worker-tag ${bash_5_0_17} ${git_2_26_2})
)
--publish-worker() {
info-text "Select image to push:"
select tag in $(docker image ls --filter reference=${1} --format "{{.Repository}}:{{.Tag}}") exit; do
if test ${tag} = "exit"; then break; fi
docker push ${tag}
done
}
# docs workflows
prepare-docs-worker() {
docker build --tag ${eg_documents_image} \
--build-arg bashversion=${eg_documents_bash} \
--build-arg gitversion=${eg_documents_git} \
--file .workflows/docs/Dockerfile .
}
publish-docs-worker() {
--publish-worker ${eg_documents_repository}
}
generate-docs() {
docker run --interactive --rm \
--mount type=bind,source=$(pwd),target=/elegant-git \
${eg_documents_image} generate
}
preview-docs() {
{ sleep 5 && open http://localhost & } || true
docker run --interactive --tty --rm \
--publish 80:80 \
--mount type=bind,source=$(pwd),target=/elegant-git \
${eg_documents_image} preview
}
serve-docs() {
generate-docs
preview-docs
}
# docs workflows
repository() {
info-text "Select worker:"
select worker in ${bats_worker_tags[*]} exit; do
if test ${worker} = "exit"; then break; fi
info-text "Start container..."
docker run --interactive --tty --detach --rm \
--name repository \
--workdir /tmp/elegant-git-repo \
--mount type=bind,source=$(pwd),target=/elegant-git \
${eg_bats_repository}:${worker} bash
info-text "Init repository..."
docker exec --interactive --tty repository bash -c "
cd /elegant-git
source tests/addons-repo.bash
source tests/addons-common.bash
repo-new
"
info-text "Install Elegant Git..."
docker exec --interactive --tty repository bash -c "
cd /elegant-git
.workflows/installation-workflows.bash install
"
info-text "Ready! Enjoy experiments..."
docker attach repository
done
}
# testing workflows
prepare-bats-worker() {
local batsversion=v1.2.0
info-text "Select worker:"
select worker in ${bats_worker_tags[*]} exit; do
if test ${worker} = "exit"; then break; fi
docker build --tag ${eg_bats_repository}:${worker} \
--build-arg bashversion=${worker%%-*} \
--build-arg gitversion=${worker##*-} \
--build-arg batsversion=${batsversion} \
.workflows/bats
done
}
publish-bats-worker() {
--publish-worker ${eg_bats_repository}
}
--bats-workers() {
# usage: --bats-workers <task-name> [<args> ...]
local task=${1}; shift
for tag in ${bats_worker_tags[*]}; do
docker run --detach \
--mount type=bind,source=$(pwd),target=/elegant-git \
--name elegant-git-${task}-${tag} \
${eg_bats_repository}:${tag} "${@}"
done
}
testing() {
--bats-workers some-bats some_tests "$@"
--report-containerized-jobs
}
test-commands-docs() {
docker run --detach \
--mount type=bind,source=$(pwd),target=/elegant-git \
--name elegant-git-test-commands-docs \
${eg_documents_image} ci
}
test-docs-site() {
docker run --detach \
--name elegant-git-test-docs-site \
--mount type=bind,source=$(pwd),target=/elegant-git \
${eg_documents_image} build
}
test-installation() {
--bats-workers installation bash -c "
.workflows/installation-workflows.bash install
.workflows/installation-workflows.bash smoke-tests
"
}
ci() {
--bats-workers all-bats all_tests
test-commands-docs
test-docs-site
test-installation
--report-containerized-jobs
}
--report-containerized-jobs() {
info-box "Waiting for containerized jobs are completed ..."
while test -n "$(docker container ls --filter name=elegant-git --format {{.Names}})"; do
local containers=($(docker container ls --filter name=elegant-git --format {{.Names}}))
info-text "${#containers[*]} jobs still working ..."
sleep 3
done
info-box "Reporting job statuses ..."
local passes=($(docker container ls --all --filter exited=0 --format {{.Names}}))
for passed in ${passes[*]} ; do
info-text "${passed} job is passed."
done
if test ${#passes[*]} -ne 0 ; then
info-text "Remove containers for passed jobs ..."
docker container rm -f ${passes[*]}
fi
local failures=($(docker container ls --all --filter name=elegant-git --format {{.Names}}))
for failed in ${failures[*]} ; do
error-text "${failed} job is failed."
docker logs ${failed}
done
if test ${#failures[*]} -ne 0 ; then
info-text "Remove containers for failed jobs ..."
docker container rm -f ${failures[*]}
fi
if test ${#failures[*]} -ne 0; then
error-box "${#passes[*]} jobs are passed and ${#failures[*]} are failed."
error-text "Failed jobs:"
for fail in ${failures[*]}; do
error-text "- ${fail}"
done
exit 1
else
info-box "${#passes[*]} jobs are passed."
fi
}
robot() {
# runs a
local smart_testing_status=""
local command_files=($(git ls-files --modified --other -- libexec/git-elegant*))
for command_file in ${command_files[@]}; do
local command_name=$(basename ${command_file})
if ! test -f tests/${command_name}.bats; then continue; fi
info-box "Run tests for ${command_file}"
( testing ${command_name} && info-text "'${command_file}' testing is passed." ) || {
error-text "'${command_name}' testing is failed."
smart_testing_status=failed
}
done
local tests_files=($(git ls-files --modified --other -- tests/git-elegant*.bats))
for test_file in ${tests_files[@]}; do
local file_name=$(basename ${test_file})
if [[ ${command_files[@]} =~ "${file_name/.bats/}" ]] ; then
continue # already tested
fi
if ! test -f tests/${file_name}; then continue; fi
info-box "Run tests in ${file_name}"
( testing ${file_name} && info-text "'${file_name}' testing is passed.") || {
error-text "'${file_name}' testing is failed."
smart_testing_status=failed
}
done
if test -z "${smart_testing_status}"; then
info-text "Everything is great!"
else
error-text "Something should be improved!"
exit 1
fi
}
# testing workflows
usage() {
cat <<MESSAGE
usage: ${BASH_SOURCE[0]} [command] [arg]...
Available commands:
developing documentation
prepare-docs-worker builds a new '${eg_documents_image}' image
publish-docs-worker pushes the '${eg_documents_image}' image
generate-docs generates fresh commands documentation
preview-docs runs a site with the current documentation (http://localhost)
serve-docs runs 'generate-docs' and 'preview-docs'
testing modifications
prepare-bats-worker builds a new '${eg_bats_repository}' image
publish-bats-worker pushes the '${eg_bats_repository}' image
testing runs bats tests; accepts a optional pattern for tests
filtering ("${BASH_SOURCE[0]} testing work" run all tests
which have the word in the test name)
test-commands-docs checks if the commands docs are up to date
test-docs-site checks if the docs site can be built
test-installation checks if installation works fine
ci runs CI quality assessment workflow
robot runs tests for updated "libexec/git-elegant*" or
"tests/git-elegant*.bats" files
other
help prints this message
repository creates a git repository and installs Elegant Git within
MESSAGE
}
commands=(
prepare-docs-worker
publish-docs-worker
generate-docs
preview-docs
serve-docs
prepare-bats-worker
publish-bats-worker
testing
test-commands-docs
test-docs-site
test-installation
usage
robot
repository
ci
)
main() {
local command=${1}
if [[ -z ${command} ]]; then
question-text "Please select a command:"
echo ""
select choise in ${commands[@]} exit; do
if test ${choise} = "exit"; then exit; fi
command=${choise}
if test ${command} = testing; then
question-text "Please give the tests pattern: "
read args
fi
break
done
else
shift
fi
info-box "Run:" ${command} ${args:-${@}}
${command} ${args:-${@}}
if [[ ${command} =~ "test-" ]]; then
--report-containerized-jobs
fi
}
main ${@}