Merge pull request #50 from nicholasbishop/bishop-book-split-5 #83
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Book | |
on: | |
push: | |
branches: [main] | |
tags: ['*'] | |
permissions: | |
contents: write | |
# Adapted from: | |
# https://github.com/rust-lang/mdBook/wiki/Automated-Deployment%3A-GitHub-Actions#github-pages-deploy | |
jobs: | |
deploy: | |
# if: github.repository == 'rust-osdev/uefi-rs' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install mdbook | |
run: | | |
mkdir mdbook | |
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 | |
echo `pwd`/mdbook >> $GITHUB_PATH | |
- name: Deploy GitHub Pages | |
run: | | |
# Configure git user so that `git commit` works. | |
git config user.name "Deploy from CI" | |
git config user.email "" | |
# Get the highest `uefi` release tag. | |
highest_tag="$(git tag --list | grep uefi-v | sort -V | tail -1)" | |
# Create worktrees for both the `main` branch and the highest tag. | |
git worktree add wt-main refs/remotes/origin/main | |
git worktree add wt-tag refs/tags/"${highest_tag}" | |
# Create a worktree for the `gh-pages` branch. | |
git worktree add wt-gh-pages gh-pages | |
# Delete the ref to avoid keeping history. | |
git -C wt-gh-pages update-ref -d refs/heads/gh-pages | |
# Delete existing book builds. | |
rm -rf wt-gh-pages/HEAD wt-gh-pages/latest-release | |
# Build the book for both `main` and the highest tag. The dest dir is | |
# relative to the second path. | |
mdbook build --dest-dir ../../wt-gh-pages/HEAD wt-main/book | |
mdbook build --dest-dir ../../wt-gh-pages/latest-release wt-tag/book | |
# Add an index in the root to redirect to the latest release. | |
cp wt-main/book/redirect.html wt-gh-pages/index.html | |
# Commit and push. | |
cd wt-gh-pages | |
git add HEAD latest-release index.html | |
git commit -m "Deploy $GITHUB_SHA to gh-pages" | |
git push --force |