-
Notifications
You must be signed in to change notification settings - Fork 2
/
Taskfile.sh
executable file
·180 lines (141 loc) · 4.45 KB
/
Taskfile.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
#!/bin/bash
GH='/usr/local/bin/gh'
BAD_WORDS=(cialis amoxicillin)
CONTENT_PATH='content'
function install {
./devops/scripts/install-hugo.sh
npm install
}
function build {
hugo --minify
# Sometimes the spookfest.js is missing??
if cat public/index.html | grep -q "spookfest.js" ; then
echo "Spookfest included"
else
echo "Spookfest not found"
exit 1
fi
}
function wait-for {
URL=${1?}
CODE=${2:-200}
start=$SECONDS
timeout --foreground 300 bash \
<<-EOD
until [[ "\$RESP" == "$CODE" ]]; do
[[ \$RESP ]] && sleep 1
RESP=\$(curl -sIL -o /dev/null -w '%{http_code}' $URL | tr -d '\n')
echo -ne "\$RESP "
TRIES=\$(( TRIES + 1 )) && [[ \$(( TRIES % 10 )) == 0 ]] && echo
done
EOD
duration=$(( SECONDS - start ))
RET=$?
echo
if [[ $RET -eq 0 ]]; then
echo "$URL returned $CODE in $duration seconds"
else
echo "$URL timed out after $duration waiting for $CODE"
exit 1
fi
}
function regression {
ACTION=${1?}
hugo serve -b host.docker.internal --bind 0.0.0.0 &
wait-for localhost:1313
curl -s http://localhost:1313/sitemap.xml \
| npx sitemap --parse \
| jq --slurp '. | map(.url) | sort' > devops/backstopjs/urls.json
HOST_IP="$(ip route | grep -E '(default|docker0)' | grep -Eo '([0-9]+\.){3}[0-9]+' | tail -1)"
ADD_HOST_FLAG="--add-host host.docker.internal:$HOST_IP"
echo $ADD_HOST_FLAG
docker run --rm -v $(pwd):/src $ADD_HOST_FLAG \
backstopjs/backstopjs $ACTION --config=devops/backstopjs/main.js
RET=$?
kill %1
exit $RET
}
function deploy {
set -e
STORAGE_ACCOUNT=${1?}
DEST="https://$STORAGE_ACCOUNT.blob.core.windows.net/\$web"
RESOURCE_GROUP=`az storage account show -n $STORAGE_ACCOUNT | jq -r .resourceGroup`
PROFILE_NAME=`az cdn profile list -g $RESOURCE_GROUP | jq -r .[0].name`
CDN_ENDPOINT=`az cdn endpoint list -g $RESOURCE_GROUP --profile-name $PROFILE_NAME | jq -r .[0].name`
azcopy_v10 sync --delete-destination=true --recursive public $DEST
az cdn endpoint purge -n $CDN_ENDPOINT --profile-name $PROFILE_NAME --content-paths "/*" --resource-group $RESOURCE_GROUP --no-wait
}
function clean-prs {
PRS=( $(hub pr list -f "%I ") )
for pr in ${PRS[*]}; do
echo "Pull Request #$pr"
for badword in ${BAD_WORDS[*]}; do
if hub pr show $pr -f "%b" | grep -q -i $badword; then
echo " detected badword \"$badword\""
echo " marking spam and closing"
hub issue update $pr -l spam --state closed
echo " deleting branch"
git push --quiet origin --delete $(hub pr show $pr -f "%H")
break
fi
done
done
}
function compress-videos {
NAME=${1?}
if [ -d "${CONTENT_PATH}/posts/${NAME}" ]; then
VPATH="${CONTENT_PATH}/posts/${NAME}"
elif [ -d "${CONTENT_PATH}/projects/${NAME}" ]; then
VPATH="${CONTENT_PATH}/projects/${NAME}"
fi
for i in $VPATH/*.mp4; do
ffmpeg -y -i "$i" -c:v libx264 -crf 20 "${i%.*}_compress.mp4";
done
}
function compress-pictures {
NAME=${1?}
if [ -d "${CONTENT_PATH}/posts/${NAME}" ]; then
VPATH="${CONTENT_PATH}/posts/${NAME}"
elif [ -d "${CONTENT_PATH}/projects/${NAME}" ]; then
VPATH="${CONTENT_PATH}/projects/${NAME}"
fi
for i in $VPATH/*.{jpg,jpeg}; do
jpegoptim -m 80 "$i"
done
}
function remove-extras {
NAME=${1?}
IGNORED="index.md thumb.jpg thumb.png"
if [ -d "${CONTENT_PATH}/posts/${NAME}" ]; then
VPATH="${CONTENT_PATH}/posts/${NAME}"
elif [ -d "${CONTENT_PATH}/projects/${NAME}" ]; then
VPATH="${CONTENT_PATH}/projects/${NAME}"
fi
mkdir "${VPATH}/unused"
for i in $VPATH/*; do
local FILE="${i##*/}"
if [[ " $IGNORED " =~ .*\ $FILE\ .* ]] || [ -d "${i}" ]; then
continue;
fi
if ! grep -q "${FILE%.*}" "${VPATH}/index.md"; then
mv "${i}" "${VPATH}/unused"
fi
done
}
function new {
TYPE=${1?}
NAME=${2}
if [ ! -d "${CONTENT_PATH}/${TYPE}" ]; then
NAME=$TYPE
TYPE=posts
fi
NAME=`echo $NAME | tr '[:upper:]' '[:lower:]' | tr ' ' '-'`
hugo new $TYPE/$NAME/index.md
}
function help {
echo "$0 <task> <args>"
echo "Tasks:"
compgen -A function | cat -n
}
TIMEFORMAT="Task completed in %3lR"
time "${@:-help}"