-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathdeploy.sh
More file actions
92 lines (79 loc) · 2.61 KB
/
deploy.sh
File metadata and controls
92 lines (79 loc) · 2.61 KB
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
#!/bin/bash
userAgent="GitHub Autodeploy Bot/1.1.0 (${WIKI_UA_EMAIL})"
pat='\-\-\-\
\-\- @Liquipedia\
\-\- page=([^
]*)\
'
. ./scripts/login_and_get_token.sh
if [[ -n "$1" ]]; then
luaFiles=$1
gitDeployReason="\"$(git log -1 --pretty='%h %s')\""
else
luaFiles=$(find lua/wikis -type f -name '*.lua')
gitDeployReason='Automated Weekly Re-Sync'
fi
allModulesDeployed=true
for luaFile in $luaFiles; do
if [[ -n "$1" ]]; then
luaFile="./$luaFile"
fi
echo "::group::Checking $luaFile"
fileContents=$(cat "$luaFile")
[[ $fileContents =~ $pat ]]
if [[ "${BASH_REMATCH[1]}" == "" ]]; then
echo '...skipping - no magic comment found'
echo "${luaFile} skipped" >> $GITHUB_STEP_SUMMARY
else
# Extract wiki name from path, e.g. ./lua/wikis/commons/Widget/Match/Page/Header.lua -> commons
wiki=$(echo "$luaFile" | awk -F'/' '{for(i=1;i<=NF;i++) if($i=="wikis") print $(i+1)}')
page="${BASH_REMATCH[1]}${LUA_DEV_ENV_NAME}"
echo '...magic comment found - updating wiki...'
echo "...wiki = $wiki"
echo "...page = $page"
wikiApiUrl="${WIKI_BASE_URL}/${wiki}/api.php"
ckf="cookie_${wiki}.ck"
getToken ${wiki}
# Edit page
rawResult=$(
curl \
-s \
-b "$ckf" \
-c "$ckf" \
--data-urlencode "title=${page}" \
--data-urlencode "text=${fileContents}" \
--data-urlencode "summary=Git: ${gitDeployReason}" \
--data-urlencode "bot=true" \
--data-urlencode "recreate=true" \
--data-urlencode "token=${token}" \
-H "User-Agent: ${userAgent}" \
-H 'Accept-Encoding: gzip' \
-X POST "${wikiApiUrl}?format=json&action=edit" \
| gunzip
)
result=$(echo "$rawResult" | jq ".edit.result" -r)
if [[ "${result}" == "Success" ]]; then
nochange=$(echo "$rawResult" | jq ".edit.nochange" -r)
echo "...${result}"
if [[ "${nochange}" == "" ]] && [[ "${DEPLOY_TRIGGER}" == "push" ]]; then
echo "::notice file=${luaFile}::No change made"
elif [[ "${nochange}" != "" ]] && [[ "${DEPLOY_TRIGGER}" != "push" ]]; then
echo "::warning file=${luaFile}::File changed"
fi
echo '...done'
echo ":information_source: ${luaFile} successfully deployed" >> $GITHUB_STEP_SUMMARY
else
echo "::warning file=${luaFile}::failed to deploy"
echo ":warning: ${luaFile} failed to deploy" >> $GITHUB_STEP_SUMMARY
allModulesDeployed=false
fi
# Don't get rate limited
sleep 4
fi
echo '::endgroup::'
if [ "$allModulesDeployed" != true ]; then
echo "::warning::Some modules were not deployed!"
exit 1
fi
done
rm -f cookie_*