scripts/publish-docs.sh

58f3b73e8ff337e5a15111fbb32c0d57cf2346da
orgstar/scripts/publish-docs.sh history · blame · raw

40 lines · 1617 bytes · executable

 1#!/bin/sh
 2# Builds the user manual in docs/manual with orgo, with the third-party notices as a page, and
 3# copies it to files.krz.sh/orgstar/, next to the DMGs. While krz/orgstar is public it also
 4# force-pushes it to the `pages` branch, which gitbay serves at https://krz.gitbay.site/orgstar/:
 5# installs from before 1.0.0 read their appcast there.
 6# Usage: scripts/publish-docs.sh [--dry-run]
 7#   ORGSTAR_FILES  rsync destination (default: homelab:/var/www/files/orgstar)
 8set -eu
 9
10cd "$(dirname "$0")/.."
11tmp=$(mktemp -d)
12trap 'rm -rf "$tmp"' EXIT
13site="$tmp/site"
14
15files="${ORGSTAR_FILES:-homelab:/var/www/files/orgstar}"
16src="$tmp/manual"
17cp -R docs/manual "$src"
18cp THIRD_PARTY.org "$src/third-party.org"
19orgo build "$src" -o "$site" --strict --no-cache
20rm -f "$site/.orgo-cache.json"
21
22if [ "${1:-}" = "--dry-run" ]; then
23	echo "built $(find "$site" -name '*.html' | wc -l | tr -d ' ') pages; not published"
24	exit 0
25fi
26
27# --delete keeps the copy exact, apart from the DMGs that release-mac.sh puts beside it.
28rsync -a --delete --exclude '*.dmg' "$site/" "$files/"
29echo "published the manual to $files"
30
31visibility=$(gitbay repo show krz/orgstar --json | sed -n 's/.*"visibility":"\([a-z]*\)".*/\1/p')
32[ "$visibility" = public ] || exit 0
33# The pages branch holds only the built site, replaced on each publish.
34sha=$(git rev-parse --short HEAD)
35git init -q "$tmp/work"
36cp -R "$site/." "$tmp/work/"
37git -C "$tmp/work" add -A
38git -C "$tmp/work" commit -q -m "Publish the manual from $sha"
39git -C "$tmp/work" push -q --force "$(git remote get-url origin)" HEAD:refs/heads/pages
40echo "published the manual from $sha"