name: Linting

on:
  pull_request:
    paths:
      - "**/*.rb"
      - "**/*.rs"

jobs:
  rubocop:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.3
          rubygems: latest
          bundler-cache: true # 'bundle install' and cache
      - name: Rubocop
        run: bundle exec rake rubocop

  clippy_format:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true

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

      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            tmp/
            target/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-v1

      - name: Check clippy
        run: cargo clippy

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