badness 0.5.0

A language server, formatter, and linter for LaTeX
name: Documentation

on:
  workflow_dispatch:
  workflow_call:
  pull_request:
  push:
    branches:
      - main

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    name: Build Documentation
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v7
        with:
          # Full history so the sitemap can derive per-page <lastmod> from git.
          fetch-depth: 0

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - name: Cache cargo dependencies
        uses: actions/cache@v6
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            docs/doc-utils/target
          key: ${{ runner.os }}-docs-${{ hashFiles('docs/doc-utils/Cargo.lock', 'Cargo.toml') }}
          restore-keys: |
            ${{ runner.os }}-docs-

      - uses: jontze/action-mdbook@v4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

      # Build the version-substitution preprocessor up front so the (optional)
      # plugin actually runs during `mdbook build`. Without this the build still
      # succeeds but ships raw `{{ badness-version }}` markers.
      - name: Build docs preprocessor
        run: cargo build --manifest-path docs/doc-utils/Cargo.toml

      - name: Build documentation
        run: mdbook build docs

      # mdbook has no `canonical-site-url` setting (rust-lang/mdBook#2706), so
      # inject a <link rel="canonical"> into every rendered page post-build.
      - name: Inject canonical links
        run: |
          cargo run --quiet --manifest-path docs/doc-utils/Cargo.toml \
            --bin canonical -- docs/book https://badness.dev/

      # mdbook has no built-in sitemap; generate one from the rendered pages.
      # `lastmod` is derived from git history, so this runs against full history.
      - name: Generate sitemap
        run: |
          cargo run --quiet --manifest-path docs/doc-utils/Cargo.toml \
            --bin sitemap -- docs/book https://badness.dev/

      - name: Upload Pages artifact
        if: github.event_name == 'push' && github.ref == 'refs/heads/main'
        uses: actions/upload-pages-artifact@v5
        with:
          path: docs/book

  deploy:
    name: Deploy to GitHub Pages
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    needs: build
    runs-on: ubuntu-latest
    permissions:
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Setup Pages
        uses: actions/configure-pages@v6

      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v5