From 79dbbb2450b4f504dc3568178f8668dce4a050bd Mon Sep 17 00:00:00 2001 From: Stephan Renatus Date: Wed, 13 Oct 2021 17:59:59 +0200 Subject: [PATCH] website/build: misc changes to website build scripts (#3886) * website/scripts/load-docs.sh: less verbose output 1. Less output: the tag semver ordering isn't something we work on daily, so let's silence that. 2. Use 'git archive' and tar, not a checkout: this way, we don't mess up the working directory or reflog. It should also be faster, since we don't end up writing all the vendor files, binary blobs, etc to disk. 3. Make the 'latest' symlink relative. * scripts/live-blocks/inject: run preprocess with max allowed args Before, when attempting to do this, I had used find ... -exec npm run preprocess {} + and find had determined what the maximum number of allowed command line args were, and executed that call in batches of those. `npm`, however, would have prepended the call with its own args, thereby exceeding the limit. As a way out, we had used `xargs -n200`, to preprocess the files in batches of 200 at a time. Now, we're telling `find` the exact command needed, bypassing the package.json helper definition. Signed-off-by: Stephan Renatus --- .../scripts/live-blocks/scripts/inject | 2 +- docs/website/scripts/load-docs.sh | 45 ++----------------- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/docs/website/scripts/live-blocks/scripts/inject b/docs/website/scripts/live-blocks/scripts/inject index 3a9b4e3c2c..763b43ffff 100755 --- a/docs/website/scripts/live-blocks/scripts/inject +++ b/docs/website/scripts/live-blocks/scripts/inject @@ -18,4 +18,4 @@ mkdir -p ../../public/live-blocks # Other assets cp -r static/* ../../public/live-blocks/ # Preprocess the docs -find ../../public/ -name '*.html' -print0 | xargs -0 -n200 npm run preprocess +find ../../public/ -name '*.html' -exec node -r esm src/preprocess/index.js {} + diff --git a/docs/website/scripts/load-docs.sh b/docs/website/scripts/load-docs.sh index b3c3a2e2a4..5d05290f06 100755 --- a/docs/website/scripts/load-docs.sh +++ b/docs/website/scripts/load-docs.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -xe +set -e ORIGINAL_COMMIT=$(git symbolic-ref -q --short HEAD || git name-rev --name-only HEAD) # If no name can be found "git name-rev" returns @@ -57,36 +57,7 @@ for release in ${ALL_RELEASES}; do done echo "Git version: ${GIT_VERSION}" - -echo "Saving current workspace state" -STASH_TOKEN=$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) -git stash push --include-untracked -m "${STASH_TOKEN}" - -function restore_tree { - echo "Returning to commit ${ORIGINAL_COMMIT}" - git checkout ${ORIGINAL_COMMIT} - - # Only pop from the stash if we had stashed something earlier - if [[ -n "$(git stash list | head -1 | grep ${STASH_TOKEN} || echo '')" ]]; then - git stash pop - fi -} - -function cleanup { - EXIT_CODE=$? - - if [[ "${EXIT_CODE}" != "0" ]]; then - # on errors attempt to restore the starting tree state - restore_tree - - echo "Error loading docs" - exit ${EXIT_CODE} - fi - - echo "Docs loading complete" -} - -trap cleanup EXIT +echo "Releases to consider: ${RELEASES[*]}" echo "Cleaning generated folder" rm -rf ${ROOT_DIR}/docs/website/generated/* @@ -101,14 +72,13 @@ echo "- latest" > ${RELEASES_YAML_FILE} for release in "${RELEASES[@]}"; do version_docs_dir=${ROOT_DIR}/docs/website/generated/docs/${release} - mkdir -p ${version_docs_dir} echo "Checking out release ${release}" # Don't error if the checkout fails set +e - git checkout ${release} + git archive --format=tar ${release} content | tar x -C ${version_docs_dir} --strip-components=1 errc=$? set -e @@ -120,15 +90,8 @@ for release in "${RELEASES[@]}"; do else echo "WARNING: Failed to check out version ${version}!!" fi - - echo "Copying doc content from tag ${release}" - cp -r ${ROOT_DIR}/docs/content/* ${version_docs_dir}/ - done -# Go back to the original tree state -restore_tree - # Create the "edge" version from current working tree echo 'Adding "edge" to releases.yaml' echo "- edge" >> ${RELEASES_YAML_FILE} @@ -138,4 +101,4 @@ echo "- edge" >> ${RELEASES_YAML_FILE} ln -s ../../../content ${ROOT_DIR}/docs/website/generated/docs/edge # Create a "latest" version from the latest semver found -ln -s ${ROOT_DIR}/docs/website/generated/docs/${RELEASES[0]} ${ROOT_DIR}/docs/website/generated/docs/latest +ln -s ${RELEASES[0]} ${ROOT_DIR}/docs/website/generated/docs/latest