name: CI

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  setup:
    name: Detect Changes
    runs-on: ubuntu-latest
    outputs:
      source_changed: ${{ steps.set-source-changed.outputs.source_changed }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Get source files that changed
        id: changed-source
        uses: tj-actions/changed-files@v36
        with:
          files: |
            integrations
            leptos
            leptos_config
            leptos_dom
            leptos_hot_reload
            leptos_macro
            leptos_reactive
            leptos_server
            meta
            router
            server_fn
            server_fn_macro

      - name: List source files that changed
        run: echo '${{ steps.changed-source.outputs.all_changed_files }}'

      - name: Set source_changed
        id: set-source-changed
        run: |
          echo "source_changed=${{ steps.changed-source.outputs.any_changed }}" >> "$GITHUB_OUTPUT"

  matrix-job:
    name: CI
    needs: [setup]
    if: needs.setup.outputs.source_changed == 'true'
    strategy:
      matrix:
        directory:
          [
            integrations/actix,
            integrations/axum,
            integrations/viz,
            integrations/utils,
            leptos,
            leptos_config,
            leptos_dom,
            leptos_hot_reload,
            leptos_macro,
            leptos_reactive,
            leptos_server,
            meta,
            router,
            server_fn,
            server_fn/server_fn_macro_default,
            server_fn_macro,
          ]
    uses: ./.github/workflows/run-cargo-make-task.yml
    with:
      directory: ${{ matrix.directory }}
      cargo_make_task: "ci"
