-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgithub-workflows-generate
executable file
Β·145 lines (108 loc) Β· 3.15 KB
/
github-workflows-generate
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
#!/bin/sh
set -e
COLOR_RED='\033[0;31m' # Red
COLOR_GREEN='\033[0;32m' # Green
COLOR_YELLOW='\033[0;33m' # Yellow
COLOR_BLUE='\033[0;94m' # Blue
COLOR_PURPLE='\033[0;35m' # Purple
COLOR_OFF='\033[0m' # Reset
print() {
printf '%b' "$*"
}
echo() {
printf '%b\n' "$*"
}
note() {
printf '%b\n' "${COLOR_YELLOW}π $*${COLOR_OFF}" >&2
}
warn() {
printf '%b\n' "${COLOR_YELLOW}π₯ $*${COLOR_OFF}" >&2
}
success() {
printf '%b\n' "${COLOR_GREEN}[β] $*${COLOR_OFF}" >&2
}
error() {
printf '%b\n' "${COLOR_RED}π $*${COLOR_OFF}" >&2
}
abort() {
EXIT_STATUS_CODE="$1"
shift
printf '%b\n' "${COLOR_RED}π $*${COLOR_OFF}" >&2
exit "$EXIT_STATUS_CODE"
}
run() {
echo "${COLOR_PURPLE}==>${COLOR_OFF} ${COLOR_GREEN}$@${COLOR_OFF}"
eval "$@"
}
list_size() {
printf '%s\n' "$#"
}
is_integer() {
case "${1#[+-]}" in
(*[!0123456789]*) return 1 ;;
('') return 1 ;;
(*) return 0 ;;
esac
}
sed_in_place() {
echo "${COLOR_PURPLE}==>${COLOR_OFF} ${COLOR_GREEN}sed -i $@${COLOR_OFF}"
sed -i "$@"
}
main() {
unset GROUP_SIZE
for arg in "$@"
do
case $arg in
--group-size=*)
GROUP_SIZE="${1#*=}"
is_integer "$GROUP_SIZE" || abort 1 "--group-size=<INTEGER>, <INTEGER> must be an integer."
;;
esac
done
if [ -z "$GROUP_SIZE" ] ; then
abort 1 "--group-size=<INTEGER> option must be given."
fi
unset AVAILABLE_PACKAGES
unset YDEPENDED_PACKAGES
unset NDEPENDED_PACKAGES
AVAILABLE_PACKAGES=$(find formula -maxdepth 1 -type f -name '*.yml' -exec basename {} .yml \; | sort)
for item in test d8 v8 skia webrtc pdfium
do
AVAILABLE_PACKAGES=$(printf '%s\n' "$AVAILABLE_PACKAGES" | sed "s|^$item$||")
done
YDEPENDED_PACKAGES="$(sed -n '/^dep-pkg:/p' formula/*.yml | cut -c10- | tr ' ' '\n' | sort| uniq)"
printf '%s\n' "YDEPENDED_PACKAGES=$YDEPENDED_PACKAGES"
AVAILABLE_PACKAGES_COUNT="$(list_size $AVAILABLE_PACKAGES)"
printf '%s\n' "$AVAILABLE_PACKAGES_COUNT"
I=0
J=0
K=0
for x in $AVAILABLE_PACKAGES
do
I=$(expr "$I" + 1)
for y in $YDEPENDED_PACKAGES
do
if [ "$x" = "$y" ] ; then
continue 2
fi
done
if [ -z "$NDEPENDED_PACKAGES" ] ; then
NDEPENDED_PACKAGES="$x"
else
NDEPENDED_PACKAGES="$NDEPENDED_PACKAGES $x"
fi
K=$(expr "$K" + 1)
if [ "$I" -eq "$AVAILABLE_PACKAGES_COUNT" ] || [ "$K" -eq "$GROUP_SIZE" ] ; then
J=$(expr "$J" + 1)
OUTPUT_FILEPATH=".github/workflows/ci$J.yml"
NDEPENDED_PACKAGES=$(printf '%s\n' "$NDEPENDED_PACKAGES" | tr ' ' ',')
printf '\n'
run cp github-workflows-template "$OUTPUT_FILEPATH"
sed_in_place "s/INDEX/$J/" "$OUTPUT_FILEPATH"
sed_in_place "s/PKGLIST/$NDEPENDED_PACKAGES/" "$OUTPUT_FILEPATH"
unset NDEPENDED_PACKAGES
K=0
fi
done
}
main "$@"