name: Check

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-Dwarnings"

jobs:
  build:
    runs-on: self-hosted

    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js environment
        uses: actions/setup-node@v4.2.0
        with:
          node-version: "22.x"
          check-latest: true
      
      - name: Setup Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: "1.89.0"
          components: clippy, rustfmt

      - name: Setup rust
        run: |
          cargo install sqlx-cli cargo-machete
          cd sync-server
          sqlx database create --database-url sqlite://db.sqlite3
          sqlx migrate run --source src/app_state/database/migrations --database-url sqlite://db.sqlite3

      - name: Lint & test
        run: scripts/check.sh
