about summary refs log tree commit diff
path: root/src/ci/scripts
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2023-06-07 19:20:39 -0400
committerTrevor Gross <tgross@intrepidcs.com>2023-06-12 17:31:20 -0400
commit696b0dd472d42c7e71c992bd2e3def2d40fadebb (patch)
treefda72296f6b5e1b778adc948ca9ce38b55e536bf /src/ci/scripts
parentdf77afbcaf3365a32066a8ca4a00ae6fc9a69647 (diff)
downloadrust-696b0dd472d42c7e71c992bd2e3def2d40fadebb.tar.gz
rust-696b0dd472d42c7e71c992bd2e3def2d40fadebb.zip
Publish docs as github artifacts during CI
This PR saves library docs as github artifacts so they can be easily
viewed for review.

Discussed in <https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/Building.20docs.20for.20PR.20CI>
Diffstat (limited to 'src/ci/scripts')
-rwxr-xr-xsrc/ci/scripts/create-doc-artifacts.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/ci/scripts/create-doc-artifacts.sh b/src/ci/scripts/create-doc-artifacts.sh
new file mode 100755
index 00000000000..2516b0d8505
--- /dev/null
+++ b/src/ci/scripts/create-doc-artifacts.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# Compress doc artifacts and name them based on the commit, or the date if
+# commit is not available.
+
+set -euox pipefail
+
+# Try to get short commit hash, fallback to date
+if [ -n "$HEAD_SHA" ]; then
+    short_rev=$(echo "${HEAD_SHA}" | cut -c1-8)
+else
+    short_rev=$(git rev-parse --short HEAD || date -u +'%Y-%m-%dT%H%M%SZ')
+fi
+
+# Try to get branch, fallback to none
+branch=$(git branch --show-current || echo)
+
+if [ -n "$branch" ]; then
+    branch="${branch}-"
+fi
+
+if [ "${GITHUB_EVENT_NAME:=none}" = "pull_request" ]; then
+    pr_num=$(echo "$GITHUB_REF_NAME" | cut -d'/' -f1)
+    name="doc-${pr_num}-${short_rev}"
+else
+    name="doc-${branch}${short_rev}"
+fi
+
+
+if [ -d "obj/staging/doc" ]; then
+    mkdir -p obj/artifacts/doc
+
+    # Level 12 seems to give a good tradeoff of time vs. space savings
+    ZSTD_CLEVEL=12 ZSTD_NBTHREADS=4 \
+    tar --zstd -cf "obj/artifacts/doc/${name}.tar.zst" -C obj/staging/doc .
+
+    ls -lh obj/artifacts/doc
+fi
+
+# Set this environment variable for future use if running in CI
+if [ -n "$GITHUB_ENV" ]; then
+    echo "DOC_ARTIFACT_NAME=${name}" >> "$GITHUB_ENV"
+fi