Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·93 lines (80 loc) · 4.26 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·93 lines (80 loc) · 4.26 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
93
#!/bin/bash
#
# Ferrous Systems Cloudflare Deployment Script
#
# Copyright (c) Ferrous Systems, 2026
#
# This script will find every tag in this repo and build the material.
set -euo pipefail
# We only support macOS (the x86 binaries work OK on Apple Silicon), or x86-64 Linux
if [ "$(uname)" == "Darwin" ]; then
./mdbook --version || curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.5.2/mdbook-v0.5.2-x86_64-apple-darwin.tar.gz | tar -xvzf -
dot -V || brew install graphviz
mdbook-graphviz --version || cargo install mdbook-graphviz@0.3.1 --locked
./mdslides --version || ( curl -sSL https://github.com/ferrous-systems/mdslides/releases/download/v0.7.2/mdslides-x86_64-apple-darwin.tar.xz | tar -xvJf - \
&& mv ./mdslides-*/mdslides . \
&& rm -rf ./mdslides-*/ )
else
#./mdbook --version || curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.5.2/mdbook-v0.5.2-x86_64-unknown-linux-gnu.tar.gz | tar -xvzf -
# This one carries a patch we want
./mdbook --version || ( curl -sSL https://github.com/jonathanpallant/mdBook/releases/download/v0.5.2-current-page-active/mdbook -o ./mdbook && chmod a+x ./mdbook )
dot -V || ( curl -ssL https://github.com/restruct/dot-static/raw/refs/tags/2.0.2/x64/dot_static -o ./dot && chmod a+x ./dot )
./mdbook-graphviz --version || ( curl -sSL https://github.com/dylanowen/mdbook-graphviz/releases/download/v0.3.1/mdbook-graphviz_v0.3.1_x86_64-unknown-linux-musl.zip -o mdbook-graphviz.zip \
&& unzip mdbook-graphviz.zip \
&& rm mdbook-graphviz.zip \
&& chmod a+x ./mdbook-graphviz )
./mdslides --version || ( curl -sSL https://github.com/ferrous-systems/mdslides/releases/download/v0.7.2/mdslides-x86_64-unknown-linux-gnu.tar.xz | tar -xvJf - \
&& mv ./mdslides-*/mdslides . \
&& rm -rf ./mdslides-*/ )
fi
mdbook-striplineno supports || (
cargo || ( curl -sSLf https://sh.rustup.rs > rustup.sh && bash ./rustup.sh -y )
source $HOME/.cargo/env
cargo install --path ./mdbook-striplineno
chmod o+x $HOME/.cargo/bin/mdbook-striplineno
)
# Must be an absolute path, otherwise mdbook puts the output in the wrong place
OUTPUT_DIR=$(pwd)/html
VERSION_FILE="${OUTPUT_DIR}/history/index.html"
# Clean out whatever exists, and make the index (before we do any git checkouts
# and lose the files from this checkout)
rm -rf "${OUTPUT_DIR}"
mkdir -p "${OUTPUT_DIR}"
mkdir -p "${OUTPUT_DIR}/history"
cp ./_redirects "${OUTPUT_DIR}/_redirects"
cp ./index-top.html "${VERSION_FILE}"
export PATH=$PATH:${HOME}/.cargo/bin
# Build the book and slides
function build_and_store {
mkdir -p "${OUTPUT_DIR}/$1"
# Build the book first, because mdbook will create any empty sections
# The PATH override lets it find our local copy of mdbook-graphviz or mdbook-mermaid
PATH=$PATH:$(pwd) ./mdbook build -d "${OUTPUT_DIR}/$1/book" ./training-slides
# Then build the slides
PATH=$PATH:$(pwd) RUST_LOG=info ./mdslides --template ./training-slides/template.html \
--output-dir "${OUTPUT_DIR}/$1/slides" \
--mdbook-path ./training-slides \
--index-template ./training-slides/index-template.html
cp -r "${OUTPUT_DIR}/$1/book/images" "${OUTPUT_DIR}/$1/slides"
}
# Build what we currently have checked out
build_and_store latest
# Fetch all the git tags (in case this is some kind of shallow clone)
git fetch --tags
for tag in $(git tag | sort -V); do
url1="https://github.com/ferrous-systems/rust-training/releases/download/${tag}/rust-training-${tag}.zip"
url2="https://github.com/ferrous-systems/rust-training/releases/download/${tag}/output.zip"
echo "Unpacking ${tag}..."
if [ ! -f "${tag}.zip" ]; then
curl -sfSL "${url1}" -o "${tag}.zip" || curl -sfSL "${url2}" -o "${tag}.zip"
fi
# Make a place to put the rendered output
mkdir -p "${OUTPUT_DIR}/${tag}"
unzip -q "${tag}.zip" -d "${OUTPUT_DIR}/${tag}"
mv "${OUTPUT_DIR}/${tag}"/*/*-book "${OUTPUT_DIR}/${tag}/book"
mv "${OUTPUT_DIR}/${tag}"/*/*-presentation "${OUTPUT_DIR}/${tag}/slides"
rm -rf "${OUTPUT_DIR}/${tag}"/rust-*
rm -rf "${OUTPUT_DIR}/${tag}"/output
echo "<li>${tag} (<a href=\"/${tag}/slides\">Slides</a> | <a href=\"/${tag}/book\">Book</a>)</li>" >> "${VERSION_FILE}"
done
cat ./index-bottom.html >> "${VERSION_FILE}"