From 83c3664d70a81701d62ed0d00f09bd6556accd5f Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Thu, 27 Jul 2023 11:46:37 +0200 Subject: [PATCH] ci: add script to build the docs in Cloudflare Pages --- misc/build-docs.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 misc/build-docs.sh diff --git a/misc/build-docs.sh b/misc/build-docs.sh new file mode 100644 index 00000000..391d12c8 --- /dev/null +++ b/misc/build-docs.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# This script is used by the Cloudflare Pages to build the documentation. +# It detects if it's running in the Cloudflare Pages build environment and will install the required dependencies. +# It can also be used locally to build the documentation, given that the required dependencies are installed. + +set -eux + +# Install the dependencies if we're in the Cloudflare Pages build environment +# In this environment, the CF_PAGES environment variable is set to 1 +if [ "${CF_PAGES:-""}" = "1" ]; then + MDBOOK_VERSION=0.4.32 + + # Install rustup + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain none -y + + # Source the environment variables to add cargo to the path + . "$HOME/.cargo/env" + + # Install the minimal toolchain, which includes rustc, rustdoc, and cargo + rustup toolchain install stable --profile minimal + + # Install mdbook + MDBOOK_URL="https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-$(uname -m)-unknown-linux-gnu.tar.gz" + curl --proto '=https' --tlsv1.2 -sSfL "${MDBOOK_URL}" | tar -C "$HOME/.cargo/bin" -xzv +fi + +# Sanity check +rustdoc --version +rustc --version +cargo --version +mdbook --version +npx --version + +# Build the docs +mdbook build + +# Build the rustdoc +# This is required to be able to use the unstable `-Zrustdoc-map` flag +env RUSTC_BOOTSTRAP=1 \ + cargo doc -Zrustdoc-map --workspace --lib --no-deps +# Delete the rustdoc lockfile +rm target/doc/.lock + +# Move the Rust documentation within the mdBook +mv target/doc target/book/rustdoc + +# Build the frontend storybook +cd frontend +npm ci +npx storybook build -o ../target/book/storybook +cd .. \ No newline at end of file