name: tests

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

env:
  CARGO_TERM_COLOR: always

jobs:
  fmt:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
    - run: sudo apt-get update
    - run: sudo apt-get install -y cmake
    - uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
      with:
        components: rustfmt
    - name: Rustfmt Check
      uses: actions-rust-lang/rustfmt@559aa3035a47390ba96088dffa783b5d26da9326 # v1

  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
    - run: sudo apt-get update
    - run: sudo apt-get install -y cmake
    - uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
    - name: Build
      run: cargo build --verbose

  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
    - run: sudo apt-get update
    - run: sudo apt-get install -y cmake
    - uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
      with:
        python-version: '3.12'
    - name: Install yt-dlp
      run: pip install yt-dlp
    - uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
    - name: Run tests
      run: cargo test --verbose --all-features

  clippy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
    - run: sudo apt-get update
    - run: sudo apt-get install -y cmake
    - uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
      with:
        components: clippy
    - name: Run clippy
      run: cargo clippy

  pre-commit:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
    - run: sudo apt-get update
    - run: sudo apt-get install -y cmake
    - uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
      with:
        python-version: '3.12'
    - uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
      with:
        components: rustfmt
    - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
