---
name: Rust

on:
  push:
  pull_request:

env:
  CARGO_TERM_COLOR: always

jobs:
  rust:

    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: ['ubuntu-latest', macos-latest]
      fail-fast: false

    steps:
      - uses: actions/checkout@v6
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v6
        with:
          python-version: "3.x"
      - name: Update apt cache
        if: matrix.os == 'ubuntu-latest'
        run: sudo apt-get update
      - name: Install Debian tools on Ubuntu
        if: matrix.os == 'ubuntu-latest'
        run: sudo apt-get install -y mmdebstrap
      - name: Install system breezy and libapt-pkg-dev
        if: matrix.os == 'ubuntu-latest'
        run: sudo apt-get install -y brz libapt-pkg-dev libpcre3-dev
      - name: Install breezy
        run: pip install breezy
      - name: Install breezy and brz-debian
        run: pip install \
            git+https://github.com/breezy-team/breezy-debian \
            python_apt@git+https://salsa.debian.org/apt-team/python-apt
        if: matrix.os == 'ubuntu-latest'
      - name: Build
        run: cargo build --verbose
      - name: Run tests
        # Exclude debian features:
        run: cargo test --verbose --no-default-features --features=breezy,dep-server,upstream
        if: matrix.os != 'ubuntu-latest'
      - name: Run tests
        run: cargo test --verbose
        if: matrix.os == 'ubuntu-latest'
      - name: Run tests (with Debian feature)
        run: cargo test --verbose --features=debian
        if: matrix.os == 'ubuntu-latest'

  minimal-versions:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6
      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.x"
      - name: Update apt cache
        run: sudo apt-get update
      - name: Install Debian tools
        run: sudo apt-get install -y mmdebstrap
      - name: Install system dependencies
        run: sudo apt-get install -y brz libapt-pkg-dev libpcre3-dev
      - name: Install breezy and brz-debian
        run: pip install breezy \
            git+https://github.com/breezy-team/breezy-debian \
            python_apt@git+https://salsa.debian.org/apt-team/python-apt
      - name: Install cargo-minimal-versions
        run: cargo install cargo-minimal-versions cargo-hack
      - name: Check with minimal versions
        run: cargo minimal-versions --direct check --all-features
      - name: Test with minimal versions
        run: cargo minimal-versions --direct test --all-features
