# Our desired pipeline using only third-party Actions
name: Check and build the TODOs API (no Nix)

on:
  push:
    branches:
      - main
    tags:
      - "v*.*.*"
  pull_request:
    branches:
      - main

jobs:
  check_no-nix:
    name: Check TODOs API
    runs-on: ubuntu-22.04
    steps:
      - name: git checkout
        uses: actions/checkout@v3

      # Third-party Actions
      - name: Set up Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          # Required because this Action recognizes rust-toolchain
          # but not rust-toolchain.toml
          toolchain: "1.63.0"
          profile: minimal
          components: clippy, rustfmt
      - name: Check Rust formatting
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --check --all
      - name: Audit Rust code
        uses: EmbarkStudios/cargo-deny-action@v1
        with:
          command: check
      - name: editorconfig check
        uses: reviewdog/action-eclint@v1
        with:
          eclint_flags: -exclude "Cargo.lock"
      - name: Check spelling
        uses: codespell-project/actions-codespell@master
        with:
          skip: target
          ignore_words_list: crate

  build_and_test_no-nix:
    name: Test and build TODOs API
    needs: check_no-nix
    strategy:
      matrix:
        os: [ubuntu-22.04, macos-12]
    runs-on: ubuntu-22.04
    steps:
      - name: git checkout
        uses: actions/checkout@v3
      - name: Set up Rust cache
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: todos-app-${{ hashFiles('**/Cargo.lock') }}
      - name: Set up Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          # Required because this Action recognizes rust-toolchain
          # but not rust-toolchain.toml
          toolchain: "1.63.0"
          profile: minimal
          components: clippy, rustfmt
      - name: Test TODOs API
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --no-fail-fast
      - name: Build TODOs API
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --all-features
