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 <stephan.renatus@gmail.com>
This commit is contained in:
Stephan Renatus
2021-10-13 17:59:59 +02:00
committed by GitHub
parent 9f45a65732
commit 79dbbb2450
2 changed files with 5 additions and 42 deletions
@@ -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 {} +
+4 -41
View File
@@ -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