language: rust
rust: nightly
virt: lxd

jobs:
  include:
    - name: "Main"
      script:
        - |
          RUN_CLIPPY=true
          rustup component add clippy --toolchain=nightly || RUN_CLIPPY=false
        - cargo test --workspace
        - |
          if $RUN_CLIPPY; then
            CLIPPY_STATUS=0
            for package in maud_htmlescape maud_macros maud; do
              (cd $package && cargo clippy -- -D warnings) || CLIPPY_STATUS=$?
            done
            (exit $CLIPPY_STATUS)
          fi
    # Optional features (i.e. web framework integrations) take a long time to
    # build and rarely break. Speed up CI by checking them separately.
    - name: "All features"
      script:
        - cargo check --workspace --all-features --all-targets
    - name: "Benchmarks"
      script:
        - (cd benchmarks && cargo test --benches --locked)
    - name: "Documentation"
      script:
        - (cd docs && make -j$(nproc))
      deploy:
        provider: pages
        edge: true
        token: $GITHUB_TOKEN
        fqdn: maud.lambda.xyz
        local_dir: docs/site
        keep_history: false
        on:
          tags: true
    - name: "Format"
      # rustfmt is often missing on nightly. Since there's little benefit to
      # using the nightly version, use the more reliable stable build instead.
      rust: stable
      before_script:
        - rustup component add rustfmt
      script:
        - cargo fmt -- --check
        - (cd benchmarks && cargo fmt -- --check)
        - (cd docs && cargo fmt -- --check)
        # trybuild harnesses are technically not part of the Cargo project, so
        # need to be checked separately
        - rustfmt --check maud/tests/warnings/*.rs