# This is the name that shows up in the GitHub Actions interface
name: Rust

# When should this Github Action run?
on:
  push:
    branches: [master]

# What Environment variables to use? It is possible to have secret environment variables, any defined here will be in plaintext though.
env:
  CARGO_TERM_COLOR: always

# What do we want to run in order?
jobs:
  # name of the job to run. Can be anything.
  deploy:
    # Docker based operating system to load. Windows and Mac are also available
    runs-on: ubuntu-latest

    steps:
      # Defining a custom shell command to run for this job
      - name: Install Packages
        run: sudo apt install libasound2-dev libudev-dev pkg-config
      # Predefined GitHub action that is available globally
      # This is supposed to cache the install
      - uses: actions/cache@v2
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      # Checkout the code so that we can use it
      - uses: actions/checkout@v2
      # Install rust and add features to rust for later usage
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          components: clippy, rustfmt
      - name: Check formatting
        run: cargo fmt -- --check
      - name: Check Clippy
        run: cargo clippy -- -D clippy::all
      - name: Test
        run: cargo test
      - name: Build
        run: cargo build --release
      - uses: katyo/publish-crates@v1
        with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
