name: Setup New Project Smoke Test

on:
  workflow_call:
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  setup-and-run:
    name: setup-and-run (${{ matrix.flow_name }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - flow_name: default
            ixa_branch: ""
          - flow_name: release
            ixa_branch: release

    steps:
      - name: Ensure clippy is installed
        run: rustup component add clippy

      - name: Create project with setup script
        shell: bash
        run: |
          set -euo pipefail
          temp_root="$(mktemp -d)"
          project_dir="$temp_root/ixa_project"
          mkdir -p "$project_dir"
          echo "PROJECT_DIR=$project_dir" >> "$GITHUB_ENV"
          cd "$project_dir"

          if [ -z "${{ matrix.ixa_branch }}" ]; then
            curl -s -f -L https://raw.githubusercontent.com/CDCgov/ixa/main/scripts/setup_new_ixa_project.sh | sh
          else
            curl -s -f -L https://raw.githubusercontent.com/CDCgov/ixa/main/scripts/setup_new_ixa_project.sh | sh -s "${{ matrix.ixa_branch }}"
          fi

      - name: cargo run
        run: cargo run
        working-directory: ${{ env.PROJECT_DIR }}

      - name: cargo clippy
        run: cargo clippy
        working-directory: ${{ env.PROJECT_DIR }}
