forked from amethyst/amethyst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitlab-ci-helper.sh
180 lines (151 loc) · 5.67 KB
/
gitlab-ci-helper.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
set -euxo pipefail
function build_book {
if [[ -z "$1" || -z "$2" || -z "$3" ]]; then
echo "Usage: build-book REF DIR INVALIDATION_PATH"
exit 1
fi
REF=$1
DIR=$2
INVALIDATION_PATH=$3
# Checkout the ref we were given
git checkout -q $REF
HEAD_REV=$(git rev-parse HEAD)
# Check if the existing ref matches
if [[ -f "$DIR" && -f "${DIR}/.rev" && "$(cat ${DIR}/.rev)" = "$HEAD_REV" ]]; then
echo "Cached book build for $REF found in $DIR!"
exit 0
fi
rm -rf $DIR
mkdir -p $DIR
echo "Building book for $REF..."
mdbook build book -d "../$DIR"
# Write the newly built rev to the rev file
echo "$HEAD_REV" >> $DIR/.rev
# Write the invalidation path since we just rebuilt
echo "$INVALIDATION_PATH" >> ./book-paths-updated
}
function build_docs_wasm {
if [[ -z "$1" || -z "$2" || -z "$3" ]]; then
echo "Usage: build-book REF DIR INVALIDATION_PATH"
exit 1
fi
REF=$1
DIR=$2
INVALIDATION_PATH=$3
# Checkout the ref we were given
git checkout -q $REF
HEAD_REV=$(git rev-parse HEAD)
# Check if the existing ref matches
if [[ -f "$DIR" && -f "${DIR}/.rev" && "$(cat ${DIR}/.rev)" = "$HEAD_REV" ]]; then
echo "Cached docs build for $REF found in $DIR!"
exit 0
fi
rm -rf $DIR
mkdir -p $DIR
echo "Building wasm docs for $REF..."
# TODO: build wasm branch here
# cargo doc --all --features="animation gltf vulkan"
# taken from run.sh for future reference:
# # (cd amethyst_animation && cargo doc --no-deps)
# (cd amethyst_assets && cargo doc --target wasm32-unknown-unknown --features="wasm" --no-deps)
# (cd amethyst_audio && cargo doc --target wasm32-unknown-unknown --no-default-features --features="wasm vorbis wav" --no-deps)
# (cd amethyst_config && cargo doc --target wasm32-unknown-unknown --no-deps)
# (cd amethyst_controls && cargo doc --target wasm32-unknown-unknown --features="wasm" --no-deps)
# (cd amethyst_core && cargo doc --target wasm32-unknown-unknown --no-default-features --features="wasm" --no-deps)
# (cd amethyst_derive && cargo doc --target wasm32-unknown-unknown --no-deps)
# (cd amethyst_error && cargo doc --target wasm32-unknown-unknown --no-deps)
# # (cd amethyst_gltf && cargo doc --no-deps)
# # (cd amethyst_input && cargo doc --target wasm32-unknown-unknown --features="wasm" --no-deps)
# # (cd amethyst_locale && cargo doc --no-deps)
# (cd amethyst_network && cargo doc --target wasm32-unknown-unknown --features="web_socket" --no-deps)
# (cd amethyst_rendy && cargo doc --target wasm32-unknown-unknown --features="wasm gl" --no-deps)
# # (cd amethyst_test && cargo doc --features="wasm gl web_socket" --no-deps)
# # (cd amethyst_tiles && cargo doc --features="wasm gl web_socket" --no-deps)
# # (cd amethyst_ui && cargo doc --target wasm32-unknown-unknown --no-default-features --features="gl wasm" --no-deps)
# # (cd amethyst_utils && cargo doc --target wasm32-unknown-unknown --no-default-features --features="wasm" --no-deps)
# (cd amethyst_window && cargo doc --target wasm32-unknown-unknown --no-default-features --features="wasm" --no-deps)
# cargo doc --target wasm32-unknown-unknown --no-default-features --features="audio network renderer wasm vorbis wav gl web_socket" --no-deps
# cd ..
# mv target/doc/* $DIR/
# Write the newly built rev to the rev file
# echo "$HEAD_REV" >> $DIR/.rev
# Write the invalidation path since we just rebuilt
# echo "$INVALIDATION_PATH" >> ./docs-paths-updated
}
function build_docs {
if [[ -z "$1" || -z "$2" || -z "$3" ]]; then
echo "Usage: build-book REF DIR INVALIDATION_PATH"
exit 1
fi
REF=$1
DIR=$2
INVALIDATION_PATH=$3
# Checkout the ref we were given
git checkout -q $REF
HEAD_REV=$(git rev-parse HEAD)
# Check if the existing ref matches
if [[ -f "$DIR" && -f "${DIR}/.rev" && "$(cat ${DIR}/.rev)" = "$HEAD_REV" ]]; then
echo "Cached docs build for $REF found in $DIR!"
exit 0
fi
rm -rf $DIR
mkdir -p $DIR
echo "Building docs for $REF..."
cargo doc --all --features="animation gltf vulkan"
mv target/doc/* $DIR/
# Write the newly built rev to the rev file
echo "$HEAD_REV" >> $DIR/.rev
# Write the invalidation path since we just rebuilt
echo "$INVALIDATION_PATH" >> ./docs-paths-updated
}
function invalidate_aws {
# Check if there are any updated docs paths
if [[ -f "docs-paths-updated" ]]; then
echo "Invalidating docs paths..."
if [[ -z "$AWS_DOCS_DISTRIBUTION_ID" ]]; then
echo "AWS_DOCS_DISTRIBUTION_ID must be set"
exit 1
fi
# Loop through updated docs paths and create an invalidation for each
while read p; do
echo "Creating invalidation for docs path $p"
/usr/local/bin/aws cloudfront create-invalidation \
--distribution-id "$AWS_DOCS_DISTRIBUTION_ID" \
--paths "$p"
done < docs-paths-updated
fi
# Check if there are any updated book paths
if [[ -f "book-paths-updated" ]]; then
echo "Invalidating book paths..."
if [[ -z "$AWS_BOOK_DISTRIBUTION_ID" ]]; then
echo "AWS_BOOK_DISTRIBUTION_ID must be set"
exit 1
fi
# Loop through updated book paths and create an invalidation for each
while read p; do
echo "Creating invalidation for book path $p"
/usr/local/bin/aws cloudfront create-invalidation \
--distribution-id "$AWS_BOOK_DISTRIBUTION_ID" \
--paths "$p"
done < book-paths-updated
fi
}
SUBCOMMAND=$1
case $SUBCOMMAND in
"build-docs")
build_docs $2 $3 $4
;;
"build-docs-wasm")
build_docs_wasm $2 $3 $4
;;
"build-book")
build_book $2 $3 $4
;;
"invalidate-aws")
invalidate_aws
;;
*)
shift
echo "Usage: gitlab-ci-helper (build-book|build-docs|build-docs-wasm|invalidate-aws) [ARGS...]"
esac