-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpack-all.sh
executable file
·96 lines (85 loc) · 2.7 KB
/
pack-all.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
#!/bin/bash
# script that runs bash operations across all packs
SIGINT_STOP=
_stop() {
SIGINT_STOP=stop
}
trap _stop SIGINT
_exit() {
[[ -n "$2" ]] && echo "$2" 2>$STDERR_LOGFILE
exit $1
}
FAIL_FAST=true
SKIPIF=
STDOUT_LOGFILE=/dev/stdout
STDERR_LOGFILE=/dev/stderr
while [[ -n "$1" ]]; do
if [[ "${1:0:2}" = "--" ]]; then
# TODO: Add skipifbranch to skip if the git branch matches
if [[ "${1:2:6}" = "skipif" ]]; then
SKIPIF="${1:9}"
elif [[ "${1:2}" == "continue-on-error" ]]; then
FAIL_FAST=
elif [[ "${1:2}" == verbose* ]]; then
if [[ "${1:2}" == verbose=* ]]; then
VERBOSE="${1:10}"
else
VERBOSE=1
fi
elif [[ "${1:2}" = "help" ]]; then
echo >&2 "Usage: pack-all.sh --skipif='[[ <condition> ]]' <command> <command-arguments>"
echo >&2 ""
echo >&2 "This script is used for performing Bash operations across all packs."
echo >&2 ""
echo >&2 "Examples:"
echo >&2 ""
echo >&2 "pack-all.sh --skipif='[[ \\$(git branch) ]]' yq"
echo >&2 "pack-all.sh --skipif='_gh_is_merged_in_default||_gh_pr_created' yq"
echo >&2 ""
exit 1
elif [[ "${1:2}" = "quiet" ]]; then
VERBOSE=0
STDOUT_LOGFILE=/dev/null
elif [[ "${1:2}" = "silent" ]]; then
VERBOSE=0
STDOUT_LOGFILE=/dev/null
STDERR_LOGFILE=/dev/null
else
echo >&2 "Unrecognized flag: $1. Exiting"
exit 1
fi
shift
else
break
fi
done
COMMAND=$1; shift
if [[ -z "$COMMAND" ]]; then
COMMAND='basename $(pwd)'
# echo >&2 "You must specify a git command as the first argument. Exiting."
# exit 1
fi
# make functions available in the subshell
# eg: exchange-tools/pack-all.sh git checkout '$(_gh_default_branch)'
source $(dirname $0)/functions.sh
for pack in $(find . -depth -maxdepth 2 -type f -name 'pack.yaml' -exec sh -c 'basename $(dirname {})' \; | grep '^stackstorm-' | sort); do
[[ $VERBOSE -gt 4 ]] && echo "In $pack"
# Not 100% sure this is bug-free
if [[ -n "$SKIPIF" ]]; then
(cd $(pwd)/$pack && eval 1>/dev/null $SKIPIF) && continue
fi
[[ $VERBOSE -le 4 && "$COMMAND" != 'basename $(pwd)' ]] && echo "In $pack"
(
cd "$(pwd)/$pack"
eval >$STDOUT_LOGFILE 2>$STDERR_LOGFILE $COMMAND $*
) || {
EXIT_CODE=$?
[[ "$FAIL_FAST" == "true" ]] && {
_exit $EXIT_CODE "Exiting on error"
}
}
[[ -n "$SIGINT_STOP" ]] && {
echo "Caught SIGINT. Exiting." >$STDOUT_LOGFILE
_exit 0
}
done