tideorm-cli 0.10.0

Command-line interface for TideORM
name: CI

on:
  push:
    branches:
      - main
  pull_request:

env:
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"

jobs:
  fmt:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt

      # `cargo fmt` never resolves dependencies, so this job does not need the
      # sibling ORM checkout that the other jobs set up.
      - name: Check formatting
        run: cargo fmt --all --check

  clippy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout tideorm-cli
        uses: actions/checkout@v6
        with:
          path: tideorm-cli

      # The CLI is not standalone: it imports `tideorm::internal` and drives
      # migrations through the ORM's own connection machinery, so it has to be
      # built against the ORM checkout that sits next to it locally.
      - name: Checkout tideorm
        uses: actions/checkout@v6
        with:
          repository: mohamadzoh/tideorm
          ref: master
          path: tideorm

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2
        with:
          workspaces: tideorm-cli

      # The committed manifest takes tideorm from crates.io; developers run with a
      # permanently-uncommitted `path = "../tideorm"` override, and that is the
      # combination this job has to lint. Recreating the override here is what makes
      # an ORM change that breaks the CLI visible.
      - name: Point the tideorm dependency at the sibling checkout
        working-directory: tideorm-cli
        run: |
          sed -i -E 's|^tideorm = \{.*\}$|tideorm = { path = "../tideorm", default-features = false, features = ["postgres", "mysql", "sqlite", "runtime-tokio"] }|' Cargo.toml
          grep -q 'path = "../tideorm"' Cargo.toml

      - name: Run clippy
        working-directory: tideorm-cli
        run: cargo clippy --all-targets -- -D warnings

  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout tideorm-cli
        uses: actions/checkout@v6
        with:
          path: tideorm-cli

      - name: Checkout tideorm
        uses: actions/checkout@v6
        with:
          repository: mohamadzoh/tideorm
          ref: master
          path: tideorm

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2
        with:
          workspaces: tideorm-cli

      - name: Point the tideorm dependency at the sibling checkout
        working-directory: tideorm-cli
        run: |
          sed -i -E 's|^tideorm = \{.*\}$|tideorm = { path = "../tideorm", default-features = false, features = ["postgres", "mysql", "sqlite", "runtime-tokio"] }|' Cargo.toml
          grep -q 'path = "../tideorm"' Cargo.toml

      # `tests/generated_project.rs` scaffolds projects into a tempdir and runs
      # `cargo check --offline` inside them, so every dependency of a scaffolded
      # project, not only the CLI's own, has to be in the registry cache before the
      # suite starts: the scaffold asks for more (`tokio` with `full`) than the CLI
      # builds with. Scaffold one project per driver and fetch its dependencies,
      # patched onto the sibling ORM the way the tests patch theirs.
      - name: Warm the cargo registry cache
        working-directory: tideorm-cli
        env:
          TIDEORM_NONINTERACTIVE: "1"
        run: |
          cargo fetch
          for driver in sqlite postgres mysql; do
            project="$RUNNER_TEMP/warm-$driver"
            cargo run --quiet -- init "$project" --database "$driver"
            printf '\n[patch.crates-io]\ntideorm = { path = "%s" }\n' "$GITHUB_WORKSPACE/tideorm" >> "$project/Cargo.toml"
            cargo fetch --manifest-path "$project/Cargo.toml"
          done

      - name: Run tests
        working-directory: tideorm-cli
        run: cargo test