Skip to content

Commit c0663d4

Browse files
committed
chore: deps update automation command implemented
1 parent a9ce7d5 commit c0663d4

File tree

5 files changed

+140
-17
lines changed

5 files changed

+140
-17
lines changed

bin/ctl.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function start_services {
5555
for svc in "${services[@]}"; do
5656
cd "$dir/$svc" || exit 1
5757

58-
if [[ 1 -eq $update ]]; then
58+
if [[ 1 -eq ${update} ]]; then
5959
echo "Updating $svc..."
6060
git pull || exit 1
6161
fi
@@ -70,7 +70,7 @@ function start_services {
7070
wait_service "$svc"
7171
fi
7272

73-
printf ", master pid is %d...\n" $pid
73+
printf ", master pid is %d...\n" ${pid}
7474
touch "$pidfile"
7575
echo "$svc:$pid" >> "$pidfile"
7676

@@ -130,7 +130,7 @@ function stop_services {
130130
pid="${parts[1]}"
131131
present=$(in_services "$svc_name")
132132

133-
if [[ 0 -eq $present ]]; then
133+
if [[ 0 -eq ${present} ]]; then
134134
echo "$svc_name:$pid" >> "${pidfile}.lock"
135135
continue
136136
fi
@@ -183,12 +183,12 @@ function in_services {
183183
}
184184

185185
# parse command-line args
186-
while [ $# -gt 0 ]; do
186+
while [[ $# -gt 0 ]]; do
187187
unset OPTIND
188188
unset OPTARG
189189

190190
while getopts hucvp:s: options; do
191-
case $options in
191+
case ${options} in
192192
p) path="$OPTARG" ;;
193193
s) IFS=',' read -ra services <<< "$OPTARG" ;;
194194
h) usage ; exit 0 ;;
@@ -217,7 +217,7 @@ if [[ 0 -eq "${#services[@]}" ]]; then
217217
service_name="${file_path[0]}"
218218
present=$(in_services "$service_name")
219219

220-
if [[ 0 -eq $present ]]; then
220+
if [[ 0 -eq ${present} ]]; then
221221
services+=( "$service_name" )
222222
fi
223223
done

bin/log.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ function multitail {
4545
}
4646

4747
function usage {
48-
echo "Usage: $0 [-c] [service1, ...serviceN]" >&2
49-
echo " [service1, ...serviceN] - list of service repositories directories names to combile logs for, if omitted all existing logs are combined."
48+
echo "Usage: $0 [-hc] [service1, ...serviceN]" >&2
49+
echo " [service1, ...serviceN] - list of service repositories directories names to combine logs for, if omitted all existing logs are combined."
5050
echo " [-c] - clean previous logs" >&2
5151
echo " [-h] - print this usage information" >&2
5252
}
5353

5454
# parse command-line args
55-
while [ $# -gt 0 ]; do
55+
while [[ $# -gt 0 ]]; do
5656
unset OPTIND
5757
unset OPTARG
5858

5959
while getopts hc options; do
60-
case $options in
60+
case ${options} in
6161
h) usage ; exit 0 ;;
6262
c) find "$workdir" -type f -name "*.log" -delete ;;
6363
\?|*) usage ; exit 1 ;;

bin/updep.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
# Copyright (c) 2019, imqueue.com <[email protected]>
3+
#
4+
# Permission to use, copy, modify, and/or distribute this software for any
5+
# purpose with or without fee is hereby granted, provided that the above
6+
# copyright notice and this permission notice appear in all copies.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9+
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10+
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11+
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12+
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13+
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14+
# PERFORMANCE OF THIS SOFTWARE.
15+
argv=()
16+
services=()
17+
path="."
18+
cwd="$(pwd)"
19+
v_type="prerelease"
20+
do_commit=0
21+
do_not_update=0
22+
23+
function in_services {
24+
local service_name="$1"
25+
local service_list_lookup=" ${services[*]} "
26+
local service_name_lookup=" ${service_name} "
27+
28+
if [[ "$service_list_lookup" =~ $service_name_lookup ]]; then
29+
echo 1
30+
else
31+
echo 0
32+
fi
33+
}
34+
35+
function usage {
36+
echo "Usage: $0 [-hcu] [-p path] [-s services] [-v type]" >&2
37+
echo " Performs dependencies update on services located under given path" >&2
38+
echo " Before running this command, make sure services are not in dirty git state" >&2
39+
echo " [-h] - print this usage information" >&2
40+
echo " [-v type] - set new version using one of typed: major|minor|path|prerelease. By default is prerelease" >&2
41+
echo " [-c] - if specified it will try to do commit and push" >&2
42+
echo " [-u] - if specified will do not update update deps, and performs other tasks only" >&2
43+
echo " [-p path] - path to a directory with services repositories, by default is current directory" >&2
44+
echo " [-s services] - comma-separated services list (repositories names), if not passed will scan path for a services presence"
45+
}
46+
47+
# parse command-line args
48+
while [[ $# -gt 0 ]]; do
49+
unset OPTIND
50+
unset OPTARG
51+
52+
while getopts hucvp:s: options; do
53+
case ${options} in
54+
p) path="$OPTARG" ;;
55+
c) do_commit=1 ;;
56+
u) do_not_update=1 ;;
57+
s) IFS=',' read -ra services <<< "$OPTARG" ;;
58+
v) v_type="${OPTARG}" ;;
59+
h) usage ; exit 0 ;;
60+
\?|*) usage ; exit 1 ;;
61+
esac
62+
done
63+
64+
shift $((OPTIND-1))
65+
argv+=("$1")
66+
shift
67+
done
68+
69+
# load services from path if they were not provided by command-line option
70+
if [[ 0 -eq "${#services[@]}" ]]; then
71+
mapfile -t service_entries < <(find \
72+
"$path"/*/src \
73+
-type f \
74+
-name "*.ts" \
75+
-exec grep -lP 'extends\s+IMQ(Service|Client)\s*\{' {} +)
76+
77+
for file in "${service_entries[@]}"; do
78+
IFS='/' read -ra file_path <<< "${file#${path}/}"
79+
service_name="${file_path[0]}"
80+
present=$(in_services "$service_name")
81+
82+
if [[ 0 -eq ${present} ]]; then
83+
services+=( "$service_name" )
84+
fi
85+
done
86+
fi
87+
88+
if ! [[ -x "$(command -v npm-check-updates)" ]]; then
89+
npm i -g npm-check-updates || exit 1
90+
fi
91+
92+
if [[ do_commit -eq 0 && do_not_update -eq 1 ]]; then
93+
echo "Nothing to perform, suggest do update and/or commit." >&2
94+
usage
95+
exit 1
96+
fi
97+
98+
for svc in "${services[@]}"; do
99+
dir="${path}/${svc}"
100+
101+
cd ${dir}
102+
103+
if [[ do_not_update -ne 1 ]]; then
104+
git pull || exit 1
105+
ncu -u
106+
npm i
107+
fi
108+
109+
if [[ do_commit -eq 1 ]]; then
110+
git commit -am "chore: dependencies update"
111+
112+
case "${v_type}" in
113+
minor|major|patch|prerelease) ;;
114+
*) v_type="prerelease"
115+
esac
116+
117+
npm version "$v_type"
118+
git push --follow-tags
119+
fi
120+
121+
cd ${cwd}
122+
done

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"dependencies": {
4242
"@imqueue/core": "^1.7.3",
4343
"@imqueue/rpc": "^1.10.7",
44-
"@imqueue/travis": "^1.0.0",
44+
"@imqueue/travis": "^1.0.1",
4545
"@octokit/rest": "16.42.2",
4646
"chalk": "^3.0.0",
4747
"command-exists": "^1.2.8",
@@ -86,7 +86,8 @@
8686
"bin": {
8787
"imq": "index.js",
8888
"imqctl": "bin/ctl.sh",
89-
"imqlog": "bin/log.sh"
89+
"imqlog": "bin/log.sh",
90+
"imqup": "bin/updep.sh"
9091
},
9192
"typescript": {
9293
"definitions": "index.d.ts"

0 commit comments

Comments
 (0)