name: Rust

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

env:
  CARGO_TERM_COLOR: always

jobs:
  mdopen:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Build
      run: cargo build --verbose
    - name: Run
      run: |
        RUST_LOG=debug ./target/debug/mdopen -- README.md > mdopen.log 2>mdopen_error.log &
        sleep 3
    - name: Test
      run: HOST=127.0.0.1 PORT=5032 cargo test
    - name: Logs
      run: |
        cat mdopen.log
        cat mdopen_error.log
  clippy:
    runs-on: ubuntu-latest
    name: ${{ matrix.toolchain }} / clippy
    strategy:
      matrix:
        toolchain: [nightly-2025-03-31]
    steps:
      - uses: actions/checkout@v4
      - name: Install ${{ matrix.toolchain }}
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.toolchain }}
          components: clippy
      - name: cargo clippy
        run: cargo clippy --all-targets --all-features
        env:
          RUSTFLAGS: -Dwarnings
  fmt:
    runs-on: ubuntu-latest
    name: stable / fmt
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - name: Install stable
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - name: cargo fmt --check
        run: cargo fmt --check
