Skip to content

Deploy mdBook site to Pages #28

Deploy mdBook site to Pages

Deploy mdBook site to Pages #28

Workflow file for this run

# Workflow for building and deploying a mdBook site to GitHub Pages.
# - On push to main: deploys to the root of gh-pages.
# - On pull_request: deploys a preview under pr-preview/pr-<number>/ on gh-pages,
# comments the preview URL, and cleans up when the PR closes.
#
# Repo Settings required:
# Pages -> Source: "Deploy from a branch" -> gh-pages / (root)
# Actions -> General -> Workflow permissions: "Read and write permissions"
#
# See: https://rust-lang.github.io/mdBook/index.html
name: Deploy mdBook site to Pages
on:
push:
branches: ["main"]
pull_request:
types: [opened, synchronize, reopened, closed]
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
deploy:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
concurrency:
group: pages
cancel-in-progress: false
env:
CARGO_HOME: ${{ github.workspace }}/.cargo
RUSTUP_HOME: ${{ github.workspace }}/.rustup
steps:
- uses: actions/checkout@v4
- name: Cache Cargo registry and git index
uses: actions/cache@v4
with:
path: |
${{ env.CARGO_HOME }}/registry
${{ env.CARGO_HOME }}/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('scripts/install-mdbook.sh') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Rust toolchains
uses: actions/cache@v4
with:
path: |
${{ env.RUSTUP_HOME }}/toolchains
${{ env.RUSTUP_HOME }}/update-hashes
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('scripts/install-mdbook.sh') }}
restore-keys: |
${{ runner.os }}-rust-toolchain-
- name: Cache installed mdBook binaries
id: mdbook-cache
uses: actions/cache@v4
with:
path: |
${{ env.CARGO_HOME }}/bin
key: ${{ runner.os }}-mdbook-bin-${{ hashFiles('scripts/install-mdbook.sh') }}
restore-keys: |
${{ runner.os }}-mdbook-bin-
- name: Install mdBook
if: steps.mdbook-cache.outputs.cache-hit != 'true'
run: bash scripts/install-mdbook.sh
env:
REPO_ROOT: ${{ github.workspace }}
- name: Add Cargo bin to PATH
run: echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH"
- name: Build with mdBook
run: ${{ env.CARGO_HOME }}/bin/mdbook build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./book
keep_files: true
preview:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
concurrency: preview-${{ github.ref }}
env:
CARGO_HOME: ${{ github.workspace }}/.cargo
RUSTUP_HOME: ${{ github.workspace }}/.rustup
steps:
- uses: actions/checkout@v4
- name: Cache Cargo registry and git index
if: github.event.action != 'closed'
uses: actions/cache@v4
with:
path: |
${{ env.CARGO_HOME }}/registry
${{ env.CARGO_HOME }}/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('scripts/install-mdbook.sh') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Rust toolchains
if: github.event.action != 'closed'
uses: actions/cache@v4
with:
path: |
${{ env.RUSTUP_HOME }}/toolchains
${{ env.RUSTUP_HOME }}/update-hashes
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('scripts/install-mdbook.sh') }}
restore-keys: |
${{ runner.os }}-rust-toolchain-
- name: Cache installed mdBook binaries
if: github.event.action != 'closed'
id: mdbook-cache
uses: actions/cache@v4
with:
path: |
${{ env.CARGO_HOME }}/bin
key: ${{ runner.os }}-mdbook-bin-${{ hashFiles('scripts/install-mdbook.sh') }}
restore-keys: |
${{ runner.os }}-mdbook-bin-
- name: Install mdBook
if: github.event.action != 'closed' && steps.mdbook-cache.outputs.cache-hit != 'true'
run: bash scripts/install-mdbook.sh
env:
REPO_ROOT: ${{ github.workspace }}
- name: Add Cargo bin to PATH
if: github.event.action != 'closed'
run: echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH"
- name: Build with mdBook
if: github.event.action != 'closed'
run: ${{ env.CARGO_HOME }}/bin/mdbook build
- name: Deploy PR preview
uses: rossjrw/pr-preview-action@v1
with:
source-dir: ./book
preview-branch: gh-pages
umbrella-dir: pr-preview