100 lines
3.5 KiB
YAML
100 lines
3.5 KiB
YAML
name: deploy-docs
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- .github/workflows/docs.yml
|
|
- docs/**
|
|
|
|
env:
|
|
CARGO_TARGET_DIR: ~/cargo-target-dir
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Environment preparation
|
|
id: prep
|
|
run: |
|
|
set -x
|
|
|
|
rustup toolchain update --no-self-update stable
|
|
rustup default stable
|
|
rustup component add clippy rustfmt
|
|
rustup show
|
|
|
|
rustc --version | awk '{print $2}' | tee RUSTC_VER
|
|
echo "rustc_ver=$(cat RUSTC_VER)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Get latest versions of mdbook with plugins
|
|
id: get-version
|
|
run: |
|
|
set -x
|
|
|
|
curl -SsL https://crates.io/api/v1/crates/mdbook | jq -r .crate.max_stable_version | tee MDBOOK_VER
|
|
curl -SsL https://crates.io/api/v1/crates/mdbook-admonish | jq -r .crate.max_stable_version | tee MDBOOK_ADMONISH_VER
|
|
curl -SsL https://crates.io/api/v1/crates/mdbook-pagetoc | jq -r .crate.max_stable_version | tee MDBOOK_PAGETOC_VER
|
|
echo "mdbook_ver=$(cat MDBOOK_VER)" >> $GITHUB_OUTPUT
|
|
echo "mdbook_admonish_ver=$(cat MDBOOK_ADMONISH_VER)" >> $GITHUB_OUTPUT
|
|
echo "mdbook_pagetoc_ver=$(cat MDBOOK_PAGETOC_VER)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Cache for mdbook
|
|
id: cache-mdbook
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.cargo/bin/mdbook
|
|
key: ${{ github.workflow }}|${{ runner.os }}|cargo|00|${{ steps.prep.outputs.rustc_ver }}|mdbook|${{ steps.get-version.outputs.mdbook_ver }}
|
|
- name: Cache for mdbook-admonish
|
|
id: cache-mdbook-admonish
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.cargo/bin/mdbook-admonish
|
|
key: ${{ github.workflow }}|${{ runner.os }}|cargo|00|${{ steps.prep.outputs.rustc_ver }}|mdbook-admonish|${{ steps.get-version.outputs.mdbook_admonish_ver }}
|
|
- name: Cache for mdbook-pagetoc
|
|
id: cache-mdbook-pagetoc
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.cargo/bin/mdbook-pagetoc
|
|
key: ${{ github.workflow }}|${{ runner.os }}|cargo|00|${{ steps.prep.outputs.rustc_ver }}|mdbook-pagetoc|${{ steps.get-version.outputs.mdbook_pagetoc_ver }}
|
|
|
|
- name: Install mdbook
|
|
if: steps.cache-mdbook.outputs.cache-hit != 'true'
|
|
run: cargo install mdbook --version ${{ steps.get-version.outputs.mdbook_ver }}
|
|
- name: Install mdbook-admonish
|
|
if: steps.cache-mdbook-admonish.outputs.cache-hit != 'true'
|
|
run: cargo install mdbook-admonish --version ${{ steps.get-version.outputs.mdbook_admonish_ver }}
|
|
- name: Install mdbook-pagetoc
|
|
if: steps.cache-mdbook-pagetoc.outputs.cache-hit != 'true'
|
|
run: cargo install mdbook-pagetoc --version ${{ steps.get-version.outputs.mdbook_pagetoc_ver }}
|
|
|
|
- name: Deploy GitHub Pages
|
|
run: |
|
|
set -x
|
|
export PATH="$HOME/.cargo/bin:$PATH"
|
|
|
|
cd docs
|
|
mdbook build
|
|
|
|
git branch gh-pages
|
|
git worktree add gh-pages gh-pages
|
|
git config user.name "GitHub Action"
|
|
git config user.email "action@github.com"
|
|
|
|
cd gh-pages
|
|
git update-ref -d refs/heads/gh-pages
|
|
|
|
mv .git ../dotgit
|
|
find . -name . -o -prune -exec rm -rf -- {} +
|
|
mv ../dotgit .git
|
|
mv ../book/* .
|
|
|
|
git add .
|
|
git commit -m "Deploy $GITHUB_SHA to gh-pages"
|
|
git push -f -u origin gh-pages
|