name: AsaDB CI

on:
  push:
  pull_request:

permissions:
  contents: read

jobs:
  linux:
    # Keep the distribution explicit: the official SWI-Prolog stable PPA
    # publishes a current runtime for this supported Ubuntu release, while
    # Ubuntu's archive still carries 9.0.4 (too old for `swipl asadb`).
    runs-on: ubuntu-24.04
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v4
      - name: Install supported SWI-Prolog and portable shell
        run: |
          sudo apt-get update
          sudo apt-get install -y software-properties-common busybox
          sudo add-apt-repository -y ppa:swi-prolog/stable
          sudo apt-get update
          sudo apt-get install -y swi-prolog
          swipl --version
      - name: Check POSIX and BusyBox shell syntax
        run: |
          dash -n bin/asadb scripts/*.sh tests/*.sh
          busybox sh -n bin/asadb scripts/*.sh tests/*.sh
      - name: Check Linux runtime
        run: ./scripts/check_linux_runtime.sh
      - name: Run engine, UI, Reservoir, and 15k JOIN regressions
        run: make test-all

  windows:
    runs-on: windows-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v4
      - name: Install supported Python for the bundled wheelhouse
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"
      - name: Install SWI-Prolog
        shell: pwsh
        run: |
          choco install swi-prolog --no-progress -y
          $swiplBin = Join-Path $env:ProgramFiles 'swipl\bin'
          if (-not (Test-Path (Join-Path $swiplBin 'swipl.exe'))) {
            throw "SWI-Prolog executable was not installed at $swiplBin"
          }
          $swiplBin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
      - name: Run core and TVCC regressions on NTFS paths
        shell: pwsh
        run: |
          swipl -q -s tests/mysql_ddl_fail_closed_regression.pl
          swipl -q -s tests/run_tests.pl
          swipl -q -s tests/tvcc_regression.pl
      - name: Run the 64 MiB Reservoir import regressions on Windows
        shell: bash
        run: |
          ./tests/reservoir_large_sql_regression.sh
          ./tests/reservoir_unique_cache_regression.sh
      - name: Run pack, offline bootstrap, and real Server Mode E2E
        shell: pwsh
        run: .\tests\server_e2e_regression.ps1
