-
Notifications
You must be signed in to change notification settings - Fork 40
/
run
executable file
·291 lines (242 loc) · 7.81 KB
/
run
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/usr/bin/env bash
# vi:syntax=sh
help(){
if [ "$1" == "help" ]; then
echo "Shows a short and helpful help text"
exit 0
fi
me=`basename "$0"`
echo ""
echo "Builder Script for GDQuest demos"
cat "./build.md"
echo ""
echo "please use one of the following commands:"
for i in ${!funcs[@]}; do
command=${funcs[i]}
echo " - ${command//_/:}"
done
echo "you can get more info about commands by writing \`$me <command> help\`"
echo ""
}
function check_itch() {
if [ "$1" == "help" ]; then
echo "Checks itch variables are set, and butler available. Downloads butler if necessary."
exit 0
fi
[ -n "$ITCHIO_USERNAME" ] || { echo >&2 "\$ITCHIO_USERNAME is not set" ; exit 1; }
[ -n "$ITCHIO_GAME" ] || { echo >&2 "\$ITCHIO_GAME is not set" ; exit 1; }
[ -n "$BUTLER_API_KEY" ] || { echo >&2 "\$BUTLER_API_KEY is not set" ; exit 1; }
command -v butler >/dev/null 2>&1 || {
temp_dir=$(mktemp -d)
cd "$temp_dir"
wget -O butler.zip https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default \
&& unzip butler.zip \
&& chmod +x butler
export PATH="$temp_dir/":$PATH
}
}
function check_commands() {
if [ "$1" == "help" ]; then
echo "Verifies all necessary commands are available on \$PATH"
exit 0
fi
command -v zip >/dev/null 2>&1 || { echo >&2 "'zip' is required"; exit 1; }
command -v awk >/dev/null 2>&1 || { echo >&2 "'awk' is required"; exit 1; }
command -v pandoc >/dev/null 2>&1 || { echo >&2 "'pandoc' is required"; exit 1; }
}
function check_directories() {
if [ "$1" == "help" ]; then
echo "Verifies necessary directories exist or creates them."
exit 0
fi
mkdir -p "$BUILD_DIR" || { echo >&2 "Could not create destination directory $BUILD_DIR"; exit 1; }
mkdir -p "$ARTIFACTS_DIR" || { echo >&2 "Could not create destination directory $ARTIFACTS_DIR"; exit 1; }
}
function check() {
if [ "$1" == "help" ]; then
echo "Verifies necessary directories and softwares exist and creates/downloads them if possible."
echo "Pass itch as an argument to check for itch requirements too."
exit 0
fi
check_commands
check_directories
if [ "$1" == "itch" ]; then
check_itch
fi
}
function clean_build() {
if [ "$1" == "help" ]; then
echo "Removes the build directory"
exit 0
fi
rm -rf build
}
function clean() {
if [ "$1" == "help" ]; then
echo "Removes the build directory"
exit 0
fi
clean_build
}
function _process_project() {
project_file="$1"
use_itch="$2"
# extract project name from project.godot
project_name=$(awk -F "=" '/config\/name=/ {print $2}' "$project_file" | tr -d '"')
# remove the (GDQuest) mention
project_name=$(echo "$project_name" | sed -e 's/([^()]*)//g')
# clean whitespace
project_name=$(echo "$project_name" | xargs)
# extract project description from project.godot
description=$(awk -F "=" '/config\/description/ {print $2}' "$project_file" | tr -d '"')
# get fully qualified directory path
dir=$(dirname "$project_file")
# get project slug
base=$(basename "$dir")
# generate a unique filename for artifacts
filename="$base.$DATE.$GIT_BRANCH.$GIT_HASH.zip"
artifact="$ARTIFACTS_DIR/$filename"
# readme location for extracting text from it
readme="$dir/README.md"
# video listing location
videos_metadata_file="$dir/videos.yaml"
# icon.png
image="$base/icon.png"
# destination for writing files
destination="$BUILD_DIR/$base"
# create the zip
cd "$ROOT" && zip "$artifact" -r "$base" -x "$base/.import/*" "$base/.git/*"
# push to itch
if [ "$use_itch" == "itch" ]; then
butler push "$artifact" "$ITCHIO_USERNAME/$ITCHIO_GAME:$base" --userversion "$DATE.$GIT_HASH"
fi
# check if video listing exists
videos=""
if [[ -f "$videos_metadata_file" ]]; then
videos="--metadata-file=$videos_metadata_file"
fi
###### BUILD
# create destination directory
mkdir -p $destination
# Generate HTML
pandoc \
--metadata title="$project_name" \
--metadata pageTitle="$project_name | GDQuest 2022 Demos" \
--metadata type="project" \
--metadata is_project \
--metadata base="../" \
--metadata url="$WEBSITE_URL/$base" \
--metadata favicon="$WEBSITE_URL/favicon.ico" \
--metadata description="$description" \
--metadata image="$WEBSITE_URL/$image" \
--metadata filename="$filename" \
--metadata repo_url="$REPO_URL/tree/main/$base" \
$videos \
--template="$HTML_TEMPLATE" \
--css="../styles.css" \
-t gfm -t html5 \
-o "$destination/index.html" \
"$readme"
# copy images
cp $dir/*.png "$destination"
# write link to list for main index.html listing
echo " - [![logo for $project_name]($image) $project_name]($base)\\n" >> "$TEMP_FILE"
}
function _generate_index() {
# Assumes $TEMP_FILE has been generated
pandoc \
--metadata title="GDQuest 2022 Demos" \
--metadata type="listing" \
--metadata url="$WEBSITE_URL" \
--metadata image="$WEBSITE_URL/demos-cover.png" \
--metadata base="" \
--metadata favicon="$WEBSITE_URL/favicon.ico" \
--metadata description="A collection of Free and Open-Source Godot demos created for learning purposes and for our YouTube videos in 2022." \
--template="$HTML_TEMPLATE" \
--metadata repo_url="$REPO_URL" \
--css="styles.css" \
-t gfm -t html5 \
-o "$BUILD_DIR/index.html" \
"$TEMP_FILE"
# Copy static files
cp "$ROOT/demos-cover.png" "$BUILD_DIR"
cp $ROOT/.github/templates/static/* "$BUILD_DIR"
}
function generate() {
if [ "$1" == "help" ]; then
echo "Generates html files for all projects. Does not check for requirements."
echo "Pass itch as an argument to upload to itch too."
exit 0
fi
use_itch=""
if [ "$1" == "itch" ]; then
use_itch="itch"
fi
export -f _process_project
export BUILD_DIR
export ARTIFACTS_DIR
export ROOT
export HTML_TEMPLATE
export ITCHIO_USERNAME
export BUTLER_API_KEY
export ITCHIO_GAME
export DATE
export GIT_BRANCH
export GIT_HASH
export TEMP_FILE
export WEBSITE_URL
export REPO_URL
find "$ROOT" -name "project.godot" -exec bash -c "_process_project \"\$0\" $use_itch" {} \;
echo $'\n</div>' >> "$TEMP_FILE"
# create main index file
_generate_index
}
function build() {
if [ "$1" == "help" ]; then
echo "Verifies requirements, and generates html files."
echo "Pass itch as an argument to use Butler and upload your files to itch."
exit 0
fi
use_itch=""
if [ "$1" == "itch" ]; then
use_itch="itch"
fi
check "$use_itch"
generate "$use_itch"
}
# these variables are used in several places, and changing them will probably break things
# specifically, the link to files in the html template, and the pages location in the gh-pages CI
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
git_diff=$(git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo "*")
GIT_BRANCH=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$git_diff/" | tr -d '*')
GIT_HASH=$(git rev-parse --short HEAD 2> /dev/null)
ROOT=$(dirname "$(readlink -f $0)")
BUILD_DIR="$ROOT/build"
ARTIFACTS_DIR="$BUILD_DIR/artifacts"
HTML_TEMPLATE="$ROOT/.github/templates/template.html"
WEBSITE_URL="https://gdquest.github.io/godot-demos-2022"
REPO_URL="https://github.com/GDQuest/godot-demos-2022"
# contains a list of generated projects to list in the main file
TEMP_FILE=$(mktemp)
mv "$TEMP_FILE" "$TEMP_FILE.md"
TEMP_FILE="$TEMP_FILE.md"
cat "$ROOT/README.md" > "$TEMP_FILE"
echo $'\n\n# Demos\n<div class="links-list">' >> "$TEMP_FILE"
_bootstrap(){
funcs=(`declare -F | awk '{print $NF}' | sort | egrep -v "^_"`)
command=${1//:/_}
if [[ " ${funcs[*]} " =~ " ${command} " ]]; then
shift
$command $@
exit 0
else
if [[ $command ]]; then
echo ""
echo "\`${command}\` isn't a recognized command"
echo ""
fi
help
exit 1
fi
}
_bootstrap $@