ci: separate docs into scripts
CI / check (push) Successful in 8m52s
Deploy docs / deploy (push) Failing after 1m50s
Nightly / nightly (push) Successful in 10m54s

This commit is contained in:
2026-08-07 16:54:59 -04:00
parent abc0bdf621
commit 717c4b412a
4 changed files with 67 additions and 34 deletions
+5 -34
View File
@@ -16,35 +16,15 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Write the channel switcher
run: |
cat > "${{ gitea.workspace }}/docs-banner.html" <<'HTML'
<div style="padding:.4rem .75rem;font:0.85rem/1.4 sans-serif;border-bottom:1px solid var(--border-color,#ddd);background:var(--sidebar-background-color,#f7f7f7);color:var(--main-color,#000)">
Docs channel:
<a id="ch-release" href="#" style="margin:0 .35rem">release</a>|
<a id="ch-nightly" href="#" style="margin:0 .35rem">nightly</a>
<script>
(function () {
var m = location.pathname.match(/^(.*\/)(release|nightly)\//);
var base = m ? m[1] : location.pathname.replace(/[^\/]*$/, "");
document.getElementById("ch-release").href = base + "release/";
document.getElementById("ch-nightly").href = base + "nightly/";
if (m) { document.getElementById("ch-" + m[2]).style.fontWeight = "bold"; }
})();
</script>
</div>
HTML
- name: Build the API docs
env:
RUSTDOCFLAGS: "--html-before-content ${{ gitea.workspace }}/docs-banner.html"
RUSTDOCFLAGS: "--html-before-content ${{ gitea.workspace }}/scripts/docs-banner.html"
run: |
pixi install --locked
pixi run doc-build
- name: Redirect the channel root to the crate page
run: |
printf '%s\n' "<!doctype html><meta http-equiv=\"refresh\" content=\"0; url=${CRATE}/\">" > target/doc/index.html
- name: Flatten so the crate sits at the channel root
run: bash scripts/flatten-docs.sh
- name: Publish the channel to /srv/www
run: |
@@ -52,16 +32,7 @@ jobs:
refs/tags/*) channel=release ;;
*) channel=nightly ;;
esac
dest="/srv/www/${SITE_SLUG}/${channel}"
mkdir -p "$dest"
rsync -a --delete "target/doc/" "$dest/"
bash scripts/publish-docs.sh "$channel"
- name: Point the site root at the latest release, else nightly
run: |
root="/srv/www/${SITE_SLUG}"
if [ -d "$root/release/${CRATE}" ]; then
target="release/${CRATE}/"
else
target="nightly/${CRATE}/"
fi
printf '%s\n' "<!doctype html><meta http-equiv=\"refresh\" content=\"0; url=${target}\">" > "$root/index.html"
run: bash scripts/redirect-docs.sh
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Flatten rustdoc output so the crate serves at the doc root rather than under
# <crate>/. Moves the crate's pages up to the doc root and drops one ../ from
# each page's references to the shared assets (CSS/JS, search index, source),
# scaled to the page's depth.
# Env: DOCROOT (default target/doc), CRATE (default coursebank).
set -euo pipefail
docroot="${DOCROOT:-target/doc}"
crate="${CRATE:-coursebank}"
[ -d "$docroot/$crate" ] || { echo "no $docroot/$crate; did you build the docs?" >&2; exit 1; }
cp -a "$docroot/$crate/." "$docroot/"
rm -rf "${docroot:?}/${crate:?}"
resources='static\.files/\|crates\.js\|search-index\|search\.desc/\|src/\|settings\.html\|help\.html\|trait\.impl/\|type\.impl/'
while IFS= read -r -d '' f; do
rel="${f#"$docroot"/}"
depth=$(printf '%s' "$rel" | tr -cd '/' | wc -c)
pat=''; for ((i=0; i<=depth; i++)); do pat="\\.\\./$pat"; done
rep=''; for ((i=0; i<depth; i++)); do rep="../$rep"; done
sed -i "s#${pat}\(${resources}\)#${rep}\1#g" "$f"
done < <(find "$docroot" -name '*.html' -print0)
echo "flattened $crate into $docroot"
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Publish a built docs channel to the web root.
# Usage: publish-docs.sh <release|nightly> [-d docroot] [-w www_root] [-s site_slug]
# Env: DOCROOT (default target/doc), WWW_ROOT (default /srv/www),
# SITE_SLUG (default coursebank).
# Flags, if given, override the corresponding env var / default.
set -euo pipefail
usage() {
echo "Usage: $0 <release|nightly> [-d docroot] [-w www_root] [-s site_slug]" >&2
exit 1
}
channel="${1:?usage: publish-docs.sh <release|nightly> [-d docroot] [-w www_root] [-s site_slug]}"
shift
docroot="${DOCROOT:-target/doc}"
www_root="${WWW_ROOT:-/srv/www}"
site_slug="${SITE_SLUG:-coursebank}"
while getopts "d:w:s:" opt; do
case "$opt" in
d) docroot="$OPTARG" ;;
w) www_root="$OPTARG" ;;
s) site_slug="$OPTARG" ;;
*) usage ;;
esac
done
dest="${www_root}/${site_slug}/${channel}"
mkdir -p "$dest"
rsync -a --delete "$docroot/" "$dest/"
echo "published $docroot -> $dest"
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Point the site root at the latest release, falling back to nightly.
# Env: WWW_ROOT (default /srv/www), SITE_SLUG (default coursebank).
set -euo pipefail
root="${WWW_ROOT:-/srv/www}/${SITE_SLUG:-coursebank}"
if [ -e "$root/release/index.html" ]; then target="release/"; else target="nightly/"; fi
printf '%s\n' "<!doctype html><meta http-equiv=\"refresh\" content=\"0; url=${target}\">" > "$root/index.html"
echo "site root -> $target"