# ----------------------------------------------------------------------------
# GitHub Action workflow to quickly test that some CGE tools/examples compile.
#
# This is a small subset of tests done by test-and-pack.yml ,
# just to make a quick error in case you break the compilation of a critical CGE part.
# The full test-and-pack.yml tests much more, but takes about 2h now.
# ----------------------------------------------------------------------------

name: Quick Test

# Called by everything.yml
on: [workflow_call]
#on: [push, pull_request]

# setup.sh inside Docker requires using bash
defaults:
  run:
    shell: bash

jobs:
  test-quick:
    name: Quick Test of Tools
    strategy:
      matrix:
        # Not using macos-latest as it randomly fails because of timeouts
        # (e.g. https://github.com/castle-engine/castle-engine/actions/runs/2771175624 )
        # Looks like GH hosted macOS runner is just too busy.
        operating-system: [ubuntu-latest, windows-latest]
        lazarus-versions: [stable]
    runs-on: ${{ matrix.operating-system }}
    steps:
      - uses: actions/checkout@v4
      - name: Install FPC+Lazarus
        uses: gcarreno/setup-lazarus@v3.2.17
        with:
          lazarus-version: ${{ matrix.lazarus-versions }}
          # Cache makes Windows jobs fail (they timeout),
          # documented as TODO on https://github.com/marketplace/actions/setup-lazarus-environment .
          with-cache: false
      - name: Install Ubuntu dependencies
        if: ${{ matrix.operating-system == 'ubuntu-latest' }}
        run: sudo apt-get --no-install-recommends -y install libgl-dev
      - name: Install macOS dependencies
        if: ${{ matrix.operating-system == 'macos-latest' }}
        run: brew install gnu-sed coreutils
      - name: Set environment
        run: echo "CASTLE_ENGINE_PATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
      - name: Build Tool (Unix)
        if: ${{ matrix.operating-system == 'ubuntu-latest' || matrix.operating-system == 'macos-latest' }}
        run: ./tools/build-tool/castle-engine_compile.sh
      - name: Build Tool (Windows)
        if: ${{ matrix.operating-system == 'windows-latest' }}
        shell: pwsh
        run: ./tools/build-tool/castle-engine_compile.ps1
      - name: Build Editor
        run: ./tools/build-tool/castle-engine compile --project ./tools/castle-editor/
      - name: Build FPS Game
        run: ./tools/build-tool/castle-engine compile --project ./examples/fps_game/
      - name: Run Autotests
        run: |
          ./tools/build-tool/castle-engine --project ./tests/ compile --mode=debug
          ./tools/build-tool/castle-engine --project ./tests/ run -- --console --no-window-create
