name: Continuous integration

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

defaults:
  run:
    shell: bash

jobs:

  format:
    name: Fmt
    runs-on: ubuntu-latest
    steps:

      - name: Install stable toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          components: rustfmt

      - name: Checkout sources
        uses: actions/checkout@v3

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

  check:
    name: Check
    runs-on: ubuntu-latest
    steps:

      - name: Install stable toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable

      - name: Checkout sources
        uses: actions/checkout@v3

      - name: Run cargo check
        run: cargo check --locked

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:

      - name: Install stable toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          components: clippy

      - name: Checkout sources
        uses: actions/checkout@v3

      - name: Run cargo clippy
        run: cargo clippy --no-deps -- -W warnings

  test:
    name: Test
    runs-on: ubuntu-latest
    steps:

      - name: Install stable toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable

      - name: Checkout sources
        uses: actions/checkout@v3

      - name: Run cargo test
        run: cargo test --locked
