name: CI

concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

on:
  pull_request:
    types: [opened, synchronize, reopened]
  push:
    branches:
      - main

jobs:
  ci:
    name: CI (stable)
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Install necessary dependencies
        run: |
          sudo apt update
          sudo apt install "linux-modules-extra-$(uname -r)"
          sudo modprobe vrf

      - name: Install Rust Stable
        run: |
          rustup override set stable
          rustup update stable

      - name: Test with default feature
        env:
          # Needed for the `link::test::create_get_delete_w` test to pass.
          CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER: "sudo -E"
        run: cargo test

      - name: Test with tokio feature
        env:
          # Needed for the `link::test::create_get_delete_w` test to pass.
          CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER: "sudo -E"
        run: cargo test --features tokio_socket

      - name: Test with smol_socket feature
        env:
          # Needed for the `link::test::create_get_delete_w` test to pass.
          CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER: "sudo -E"
        run: cargo test --features smol_socket
