roc/www/build.sh

145 lines
4.9 KiB
Bash
Raw Normal View History

2022-08-12 12:45:02 +03:00
#!/usr/bin/env bash
2021-06-06 02:02:22 +03:00
2023-05-17 18:39:15 +03:00
# run from root of repo with `./www/build.sh`
# check www/README.md to run a test server
2022-10-17 18:40:35 +03:00
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -euxo pipefail
2023-01-11 20:02:29 +03:00
# check if jq is installed
jq --version
2021-06-06 05:20:32 +03:00
# cd into the directory where this script lives.
# This allows us to run this script from the root project directory,
# which is what Netlify wants to do.
2023-08-01 17:30:35 +03:00
SCRIPT_RELATIVE_DIR=$(dirname "${BASH_SOURCE[0]}")
cd $SCRIPT_RELATIVE_DIR
2022-11-13 22:20:58 +03:00
2023-08-01 17:30:35 +03:00
rm -rf build/
cp -r public/ build/
2022-11-13 22:20:58 +03:00
2023-11-03 08:37:52 +03:00
# download the latest code for the examples
echo 'Downloading latest examples...'
2023-11-20 08:57:40 +03:00
curl -fL -o examples-main.zip https://github.com/roc-lang/examples/archive/refs/heads/main.zip
rm -rf examples-main/
unzip -o examples-main.zip
2023-11-19 08:29:47 +03:00
cp -R examples-main/examples/ content/examples/
2023-11-03 08:37:52 +03:00
2023-11-19 08:29:47 +03:00
# relace links in content/examples/index.md to work on the WIP site
2023-11-20 08:57:40 +03:00
perl -pi -e 's|\]\(/|\]\(/examples/|g' content/examples/index.md
2023-11-03 08:37:52 +03:00
# clean up examples artifacts
rm -rf examples-main examples-main.zip
2023-08-01 17:30:35 +03:00
# download fonts just-in-time so we don't have to bloat the repo with them.
DESIGN_ASSETS_COMMIT="4d949642ebc56ca455cf270b288382788bce5873"
DESIGN_ASSETS_TARFILE="roc-lang-design-assets-4d94964.tar.gz"
DESIGN_ASSETS_DIR="roc-lang-design-assets-4d94964"
2022-11-13 22:20:58 +03:00
2023-08-11 06:04:02 +03:00
curl -fLJO https://github.com/roc-lang/design-assets/tarball/$DESIGN_ASSETS_COMMIT
2023-08-01 17:30:35 +03:00
tar -xzf $DESIGN_ASSETS_TARFILE
mv $DESIGN_ASSETS_DIR/fonts build/
rm -rf $DESIGN_ASSETS_TARFILE $DESIGN_ASSETS_DIR
2022-11-13 22:20:58 +03:00
2023-08-01 17:30:35 +03:00
# grab the source code and copy it to Netlify's server; if it's not there, fail the build.
pushd build
curl -fLJO https://github.com/roc-lang/roc/archive/www.tar.gz
2022-11-13 22:20:58 +03:00
2023-08-01 17:30:35 +03:00
# Download the latest pre-built Web REPL as a zip file. (Build takes longer than Netlify's timeout.)
REPL_TARFILE="roc_repl_wasm.tar.gz"
curl -fLJO https://github.com/roc-lang/roc/releases/download/nightly/$REPL_TARFILE
2023-11-19 08:29:47 +03:00
mkdir repl
2023-08-01 17:30:35 +03:00
tar -xzf $REPL_TARFILE -C repl
rm $REPL_TARFILE
ls -lh repl
2022-11-13 22:20:58 +03:00
2023-08-01 17:30:35 +03:00
popd
2022-11-13 22:20:58 +03:00
2023-08-01 17:30:35 +03:00
pushd ..
cargo --version
2022-11-13 22:20:58 +03:00
2023-08-01 17:30:35 +03:00
# We set ROC_DOCS_ROOT_DIR=builtins so that links will be generated relative to
# "/builtins/" rather than "/" - which is what we want based on how the server
# is set up to serve them.
export ROC_DOCS_URL_ROOT=/builtins
2022-11-13 22:20:58 +03:00
2023-08-01 17:30:35 +03:00
cargo run --release --bin roc-docs crates/compiler/builtins/roc/main.roc
2023-05-17 18:39:15 +03:00
2023-08-01 17:30:35 +03:00
mv generated-docs/ www/build/builtins # move everything to build/builtins/
2022-11-13 22:20:58 +03:00
2023-08-01 17:30:35 +03:00
# Manually add this tip to all the builtin docs.
find www/build/builtins -type f -name 'index.html' -exec sed -i 's!</nav>!<div class="builtins-tip"><b>Tip:</b> <a href="/different-names">Some names</a> differ from other languages.</div></nav>!' {} \;
2022-11-13 22:20:58 +03:00
2022-12-27 15:24:50 +03:00
2023-08-01 17:30:35 +03:00
# cleanup files that could have stayed behind if the script failed
rm -rf roc_nightly roc_releases.json
2023-01-11 16:08:37 +03:00
2023-08-01 17:30:35 +03:00
# we use `! [ -v GITHUB_TOKEN_READ_ONLY ];` to check if we're on a netlify server
if ! [ -v GITHUB_TOKEN_READ_ONLY ]; then
cargo build --release --bin roc
2023-08-01 17:30:35 +03:00
roc=target/release/roc
else
echo 'Fetching latest roc nightly...'
2023-08-11 06:04:02 +03:00
2023-08-01 17:30:35 +03:00
# get roc release archive
curl -fOL https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-linux_x86_64-latest.tar.gz
# extract archive
ls | grep "roc_nightly" | xargs tar -xzvf
# delete archive
ls | grep "roc_nightly.*tar.gz" | xargs rm
# simplify dir name
mv roc_nightly* roc_nightly
2023-08-01 17:26:42 +03:00
2023-08-01 17:30:35 +03:00
roc='./roc_nightly/roc'
fi
2023-01-23 20:10:41 +03:00
2023-08-01 17:30:35 +03:00
$roc version
2022-12-27 15:24:50 +03:00
2023-11-19 08:29:47 +03:00
echo 'Building site markdown content'
$roc run www/main.roc -- www/content/ www/build/
2023-07-05 19:54:28 +03:00
2023-08-01 17:30:35 +03:00
# cleanup
rm -rf roc_nightly roc_releases.json
2023-07-05 19:54:28 +03:00
2023-08-01 17:30:35 +03:00
echo 'Generating CLI example platform docs...'
# Change ROC_DOCS_ROOT_DIR=builtins so that links will be generated relative to
# "/packages/basic-cli/" rather than "/builtins/"
export ROC_DOCS_URL_ROOT=/packages/basic-cli
2023-08-01 17:30:35 +03:00
rm -rf ./downloaded-basic-cli
git clone --depth 1 https://github.com/roc-lang/basic-cli.git downloaded-basic-cli
2023-08-01 17:30:35 +03:00
cargo run --bin roc-docs downloaded-basic-cli/src/main.roc
2023-08-01 17:30:35 +03:00
rm -rf ./downloaded-basic-cli
BASIC_CLI_PACKAGE_DIR="www/build/packages/basic-cli"
mkdir -p $BASIC_CLI_PACKAGE_DIR
2023-08-01 17:30:35 +03:00
mv generated-docs/* $BASIC_CLI_PACKAGE_DIR # move all the folders to build/packages/basic-cli
2023-07-31 20:48:31 +03:00
# set up docs for older basic-cli versions
# we need a github token
if [ -v GITHUB_TOKEN_READ_ONLY ]; then
curl -v -H "Authorization: $GITHUB_TOKEN_READ_ONLY" -fL -o basic_cli_releases.json "https://api.github.com/repos/roc-lang/basic-cli/releases"
2023-07-31 20:48:31 +03:00
DOCS_LINKS=$(cat basic_cli_releases.json | jq -r '.[] | .assets[] | select(.name=="docs.tar.gz") | .browser_download_url')
2023-08-11 06:04:02 +03:00
2023-07-31 20:48:31 +03:00
rm basic_cli_releases.json
VERSION_NUMBERS=$(echo "$DOCS_LINKS" | grep -oP '(?<=/download/)[^/]+(?=/docs.tar.gz)')
while read -r VERSION_NR; do
echo $VERSION_NR
BASIC_CLI_DIR=$BASIC_CLI_PACKAGE_DIR/$VERSION_NR
mkdir -p $BASIC_CLI_DIR
curl -fL --output $BASIC_CLI_DIR/docs.tar.gz https://github.com/roc-lang/basic-cli/releases/download/$VERSION_NR/docs.tar.gz
tar -xf $BASIC_CLI_DIR/docs.tar.gz -C $BASIC_CLI_DIR/
rm $BASIC_CLI_DIR/docs.tar.gz
mv $BASIC_CLI_DIR/generated-docs/* $BASIC_CLI_DIR
rm -rf $BASIC_CLI_DIR/generated-docs
done <<< "$VERSION_NUMBERS"
fi