Merge pull request #87 from mustafamagdy/add-mdbook-lint-to-ci #259
This file contains hidden or 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: CI | |
| on: | |
| push: # Run CI for all branches except GitHub merge queue tmp branches | |
| branches-ignore: | |
| - "gh-readonly-queue/**" | |
| pull_request: # Run CI for PRs on any branch | |
| merge_group: # Run CI for the GitHub merge queue | |
| jobs: | |
| # Check code build succeeds. | |
| build-book-code: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: thumbv7em-none-eabihf | |
| - name: Build book code | |
| working-directory: . | |
| run: cargo build | |
| # Check build succeeds for microbit docs. | |
| build-book-doc: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: thumbv7em-none-eabihf | |
| - name: Build docs for micro:bit v2 | |
| working-directory: . | |
| run: cargo doc | |
| # Build the book HTML itself and optionally publish it. | |
| build-book: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: thumbv7em-none-eabihf | |
| - name: Install Python dependencies | |
| run: | | |
| pip3 install --user python-dateutil linkchecker | |
| - name: Put pip binary directory into path | |
| run: echo "~/.local/bin" >> $GITHUB_PATH | |
| - name: Cache Cargo installed binaries | |
| uses: actions/cache@v4 | |
| id: cache-cargo | |
| with: | |
| path: ~/cargo-bin | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo- | |
| - name: Put mdbook tools where mdbook expects it | |
| if: steps.cache-cargo.outputs.cache-hit == 'true' | |
| run: | | |
| ls ~/cargo-bin | |
| mkdir -p ~/.cargo/bin | |
| cp ~/cargo-bin/mdbook ~/.cargo/bin || true | |
| cp ~/cargo-bin/mdbook-epub ~/.cargo/bin || true | |
| cp ~/cargo-bin/mdbook-lint ~/.cargo/bin || true | |
| - name: Install mdbook | |
| if: steps.cache-cargo.outputs.cache-hit != 'true' | |
| run: cargo install --locked mdbook --version 0.4.51 | |
| - name: Install mdbook-epub | |
| if: steps.cache-cargo.outputs.cache-hit != 'true' | |
| run: cargo install --locked mdbook-epub --version 0.4.48 | |
| - name: Install mdbook-lint | |
| if: steps.cache-cargo.outputs.cache-hit != 'true' | |
| run: cargo install --locked mdbook-lint | |
| - name: Copy mdbook tools to cache directory | |
| if: steps.cache-cargo.outputs.cache-hit != 'true' | |
| run: | | |
| mkdir ~/cargo-bin | |
| cp ~/.cargo/bin/mdbook ~/cargo-bin | |
| cp ~/.cargo/bin/mdbook-epub ~/cargo-bin | |
| cp ~/.cargo/bin/mdbook-lint ~/cargo-bin | |
| ls ~/cargo-bin | |
| - name: Put new cargo binary directory into path | |
| run: echo "~/cargo-bin" >> $GITHUB_PATH | |
| - name: Build book | |
| working-directory: mdbook | |
| run: mdbook build | |
| - name: Lint book with mdbook-lint | |
| working-directory: mdbook | |
| continue-on-error: true # Don't fail the build for now, just report issues | |
| run: mdbook-lint lint src/ || echo "mdbook-lint found issues - see log above" | |
| - name: Check book links | |
| working-directory: mdbook | |
| run: linkchecker --ignore-url "print.html" book | |
| - name: Copy EPUB to html directory | |
| working-directory: mdbook | |
| run: cp book/epub/*.epub book/html/ | |
| - name: Deploy book | |
| if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: mdbook/book/html | |
| force_orphan: true |