name: CI

on:
  push:
    branches: [ "main", "dev", "x" ]
  pull_request:
    branches: [ "main" ]

env:
  CARGO_TERM_COLOR: always

jobs:
  lints:
    name: Rustfmt & Clippy
    runs-on: ubuntu-latest
    container: jrottenberg/ffmpeg:7.1-ubuntu

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install dependencies
        run: |
          DEBIAN_FRONTEND=noninteractive apt-get update
          DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential ca-certificates clang curl pkg-config protobuf-compiler

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Rustfmt
        run: cargo fmt --all -- --check

      - name: Clippy
        run: cargo clippy --all-features --all-targets -- -D warnings

  check:
    name: cargo-check
    runs-on: ubuntu-latest
    container: jrottenberg/ffmpeg:7.1-ubuntu

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install dependencies
        run: |
          DEBIAN_FRONTEND=noninteractive apt-get update
          DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential ca-certificates clang curl pkg-config protobuf-compiler

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable

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

  test:
    name: cargo-test
    runs-on: ubuntu-latest
    container: jrottenberg/ffmpeg:7.1-ubuntu

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install dependencies
        run: |
          DEBIAN_FRONTEND=noninteractive apt-get update
          DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential ca-certificates clang curl pkg-config protobuf-compiler

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@nightly

      - name: Test
        run: cargo +nightly test --all-features --all-targets 

  build-linux:
    needs: test
    name: cargo build / linux / ffmpeg ${{ matrix.ffmpeg_version }}
    runs-on: ubuntu-latest
    container: jrottenberg/ffmpeg:${{ matrix.ffmpeg_version }}-ubuntu

    strategy:
      matrix:
        ffmpeg_version: [ "5.0", "5.1", "6.0", "6.1", "7.0", "7.1" ]  # "4.3", "4.4"
      fail-fast: false

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install dependencies
        run: |
          DEBIAN_FRONTEND=noninteractive apt-get update
          DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential ca-certificates clang curl pkg-config protobuf-compiler

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Build
        run: cargo build --all-features