Skip to content

Commit 04634e5

Browse files
ci: Deploy book to gh-pages
This workflow is triggered by pushes to `main`. It will update the `gh-pages` branch, throwing out any prior history to avoid increasing the overall size of repo unnecessarily. For now we just build `main`, but in the future it might be good to build a `stable` version as well. To avoid breaking existing URLs, the book is placed under the `HEAD` subdirectory, with a redirect page in the root.
1 parent 3455e11 commit 04634e5

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

.github/workflows/book.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Book
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
# Adapted from:
8+
# https://github.com/rust-lang/mdBook/wiki/Automated-Deployment%3A-GitHub-Actions#github-pages-deploy
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
- name: Install mdbook
17+
run: |
18+
mkdir mdbook
19+
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.21/mdbook-v0.4.21-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
20+
echo `pwd`/mdbook >> $GITHUB_PATH
21+
- name: Deploy GitHub Pages
22+
run: |
23+
cd book
24+
mdbook build
25+
git worktree add gh-pages gh-pages
26+
git config user.name "Deploy from CI"
27+
git config user.email ""
28+
cd gh-pages
29+
# Delete the ref to avoid keeping history.
30+
git update-ref -d refs/heads/gh-pages
31+
# Place the book under a "HEAD" directory so that we can later
32+
# add other versions (e.g. "stable" or "v0.17") without breaking
33+
# URLs.
34+
rm -rf HEAD
35+
mv ../book HEAD
36+
git add HEAD
37+
# Add an index in the root to redirect to HEAD. If we eventually
38+
# serve multiple versions, this can be changed to a real index.
39+
cp ../head_redirect.html index.html
40+
git add index.html
41+
# Commit and push.
42+
git commit -m "Deploy $GITHUB_SHA to gh-pages"
43+
git push --force

0 commit comments

Comments
 (0)