mdr 0.6.1

A lightweight Markdown viewer with live reload and multiple rendering backends
name: CI

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

env:
  CARGO_TERM_COLOR: always
  # Minimum supported Rust version, kept in sync with `rust-version` in Cargo.toml.
  #
  # 1.95 is the highest `rust-version` declared in the dependency tree, and it
  # is verified by an actual compilation rather than by reading manifests: the
  # job below runs `cargo check --all-features --all-targets` and the test suite
  # on a pinned 1.95 toolchain.
  MSRV: "1.95"

jobs:
  fmt:
    name: Format & manifest
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v4

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

      - name: Check formatting
        run: cargo fmt --all --check

      # Cheap textual check, kept here so a mismatch is reported in seconds
      # instead of after the full MSRV build.
      - name: Check that rust-version matches MSRV
        run: |
          declared=$(grep -m1 '^rust-version' Cargo.toml | cut -d'"' -f2)
          if [ "$declared" != "${MSRV}" ]; then
            echo "rust-version in Cargo.toml ($declared) does not match MSRV in ci.yml (${MSRV})" >&2
            exit 1
          fi

  check:
    name: Check (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - uses: actions/checkout@v4

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

      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo-

      - name: Install Linux dependencies
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libxdo-dev libgl1-mesa-dev

      - name: Build (all features)
        run: cargo build --release

      - name: Build (gui only)
        run: cargo build --release --no-default-features --features egui-backend

      - name: Build (web only)
        run: cargo build --release --no-default-features --features webview-backend

      - name: Build (tui only)
        run: cargo build --release --no-default-features --features tui-backend

      # Every feature combination is linted: a warning that only shows up in a
      # single-backend build is still a warning users see when they build one.
      - name: Run clippy (all features)
        run: cargo clippy --all-features --all-targets -- -D warnings

      - name: Run clippy (single backends)
        # The matrix includes windows-latest, whose default shell is pwsh.
        shell: bash
        run: |
          for feature in egui-backend webview-backend tui-backend; do
            cargo clippy --no-default-features --features "$feature" -- -D warnings
          done

      - name: Run tests
        run: cargo test --all-features

  msrv:
    name: MSRV (Rust 1.95)
    runs-on: ubuntu-latest
    timeout-minutes: 90
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust ${{ env.MSRV }}
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ env.MSRV }}

      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-msrv-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-msrv-cargo-

      - name: Install Linux dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libxdo-dev libgl1-mesa-dev

      - name: Check (all features)
        run: cargo check --all-features --all-targets

      - name: Test
        run: cargo test --all-features