|
| 1 | +name: Deploy mdBook Site to Pages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "*" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + id-token: write |
| 15 | + pages: write |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: pages |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + build-deps: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Install Rust |
| 26 | + uses: dtolnay/rust-toolchain@stable |
| 27 | + |
| 28 | + - uses: actions/cache@v4 |
| 29 | + with: |
| 30 | + path: | |
| 31 | + ~/.cargo/bin |
| 32 | + ~/.cargo/git |
| 33 | + ~/.cargo/registry |
| 34 | + target |
| 35 | + key: ${{ runner.os }}-${{ runner.arch }}-cargo-deps |
| 36 | + |
| 37 | + - name: Check for existing binaries |
| 38 | + id: check-binaries |
| 39 | + run: | |
| 40 | + if [ -f ~/.cargo/bin/mdbook ] && \ |
| 41 | + [ -f ~/.cargo/bin/mdbook-admonish ] && \ |
| 42 | + [ -f ~/.cargo/bin/mdbook-footnote ] && \ |
| 43 | + [ -f ~/.cargo/bin/mdbook-graphviz ] && \ |
| 44 | + [ -f ~/.cargo/bin/mdbook-mermaid ]; then |
| 45 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 46 | + echo "All mdbook binaries found, will skip build" |
| 47 | + else |
| 48 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 49 | + echo "Some mdbook binaries missing, will build" |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Build all mdbook components |
| 53 | + if: steps.check-binaries.outputs.exists != 'true' |
| 54 | + run: | |
| 55 | + mkdir -p target |
| 56 | + cargo install mdbook --target-dir target |
| 57 | + cargo install mdbook-admonish --target-dir target |
| 58 | + cargo install mdbook-footnote --target-dir target |
| 59 | + cargo install mdbook-graphviz --target-dir target |
| 60 | + cargo install mdbook-mermaid --target-dir target |
| 61 | +
|
| 62 | + - name: Upload Binaries |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + with: |
| 65 | + name: mdbook-binaries |
| 66 | + path: | |
| 67 | + ~/.cargo/bin/mdbook |
| 68 | + ~/.cargo/bin/mdbook-admonish |
| 69 | + ~/.cargo/bin/mdbook-footnote |
| 70 | + ~/.cargo/bin/mdbook-graphviz |
| 71 | + ~/.cargo/bin/mdbook-mermaid |
| 72 | + retention-days: 1 |
| 73 | + |
| 74 | + deploy-mdbook: |
| 75 | + needs: build-deps |
| 76 | + runs-on: ubuntu-latest |
| 77 | + steps: |
| 78 | + - name: Checkout Source |
| 79 | + uses: actions/checkout@v4 |
| 80 | + |
| 81 | + - name: Install System Dependencies |
| 82 | + env: |
| 83 | + DEBIAN_FRONTEND: noninteractive |
| 84 | + run: | |
| 85 | + sudo apt-get update |
| 86 | + sudo apt-get install -y --no-install-recommends graphviz |
| 87 | +
|
| 88 | + - name: Download mdbook binaries |
| 89 | + uses: actions/download-artifact@v4 |
| 90 | + with: |
| 91 | + name: mdbook-binaries |
| 92 | + path: /usr/local/bin |
| 93 | + |
| 94 | + - name: Make binaries executable |
| 95 | + run: | |
| 96 | + sudo chmod +x /usr/local/bin/mdbook |
| 97 | + sudo chmod +x /usr/local/bin/mdbook-admonish |
| 98 | + sudo chmod +x /usr/local/bin/mdbook-footnote |
| 99 | + sudo chmod +x /usr/local/bin/mdbook-graphviz |
| 100 | + sudo chmod +x /usr/local/bin/mdbook-mermaid |
| 101 | +
|
| 102 | + - name: Prepare Assets Directories |
| 103 | + run: mkdir -p src/fonts src/assets theme |
| 104 | + |
| 105 | + - name: Setup Catppuccin Theme |
| 106 | + run: | |
| 107 | + # Create theme directory |
| 108 | + mkdir -p theme |
| 109 | +
|
| 110 | + # Download latest Catppuccin theme |
| 111 | + curl -sSfL -o theme/catppuccin.css \ |
| 112 | + https://github.com/catppuccin/mdBook/releases/latest/download/catppuccin.css |
| 113 | +
|
| 114 | + # Download Catppuccin admonish theme |
| 115 | + curl -sSfL -o theme/catppuccin-admonish.css \ |
| 116 | + https://github.com/catppuccin/mdBook/releases/latest/download/catppuccin-admonish.css |
| 117 | +
|
| 118 | + # Download default theme's index.hbs for customization |
| 119 | + curl -sSfL -o theme/index.hbs \ |
| 120 | + https://raw.githubusercontent.com/rust-lang/mdBook/master/src/theme/index.hbs |
| 121 | +
|
| 122 | + # Update index.hbs theme options |
| 123 | + sed -i 's/Light/Latte/; s/Rust/Frappé/; s/Coal/Macchiato/; s/Navy/Mocha/; /Ayu/d' theme/index.hbs |
| 124 | +
|
| 125 | + - name: Download Additional Assets |
| 126 | + run: | |
| 127 | + # Devicon Fonts and CSS |
| 128 | + curl -sSf \ |
| 129 | + -o devicon.min.css \ |
| 130 | + https://raw.githubusercontent.com/devicons/devicon/master/devicon.min.css |
| 131 | + curl -sSf \ |
| 132 | + -o src/fonts/devicon.eot \ |
| 133 | + https://raw.githubusercontent.com/devicons/devicon/master/fonts/devicon.eot |
| 134 | + curl -sSf \ |
| 135 | + -o src/fonts/devicon.svg \ |
| 136 | + https://raw.githubusercontent.com/devicons/devicon/master/fonts/devicon.svg |
| 137 | + curl -sSf \ |
| 138 | + -o src/fonts/devicon.ttf \ |
| 139 | + https://raw.githubusercontent.com/devicons/devicon/master/fonts/devicon.ttf |
| 140 | + curl -sSf \ |
| 141 | + -o src/fonts/devicon.woff \ |
| 142 | + https://raw.githubusercontent.com/devicons/devicon/master/fonts/devicon.woff |
| 143 | +
|
| 144 | + # WhichLang Assets |
| 145 | + curl -sSf \ |
| 146 | + -o src/assets/whichlang.css \ |
| 147 | + https://raw.githubusercontent.com/phoenixr-codes/mdbook-whichlang/master/src/whichlang.css |
| 148 | + curl -sSf \ |
| 149 | + -o src/assets/whichlang.js \ |
| 150 | + https://raw.githubusercontent.com/phoenixr-codes/mdbook-whichlang/master/dist/whichlang.js |
| 151 | +
|
| 152 | + - name: Build the mdBook Site |
| 153 | + run: mdbook build |
| 154 | + |
| 155 | + - name: Turn off Jekyll |
| 156 | + run: touch book/.nojekyll |
| 157 | + |
| 158 | + - name: Upload Artifact |
| 159 | + uses: actions/upload-pages-artifact@v3 |
| 160 | + with: |
| 161 | + path: ./book |
| 162 | + |
| 163 | + - name: Deploy to GitHub Pages |
| 164 | + id: deployment |
| 165 | + uses: actions/deploy-pages@v4 |
| 166 | + if: ${{ github.ref == 'refs/heads/main' }} |
0 commit comments