name: Lint

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

env:
  SQLX_VERSION: 0.7.1
  SQLX_FEATURES: "rustls,postgres"
  SQLX_OFFLINE: true

jobs:
  test:
    name: fmt & clippy
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          workspaces: |
            AppFlowy-Cloud

      - name: Copy and rename dev.env to .env
        run: cp dev.env .env

      - name: Code Gen
        working-directory: ./build
        run: ./code_gen.sh

      - name: Rustfmt
        run: |
          cargo fmt --check

      - name: Clippy
        run: cargo clippy --all-targets --all-features -- -D warnings
