#!/usr/bin/env execlineb
# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
# SPDX-License-Identifier: BSD-2-Clause

backtick -E tempd {
  mktemp -d -t feature-check-test.XXXXXX
}
trap {
  default {
    foreground {
      echo "Cleaning up ${tempd} in a ${SIGNAL} signal handler"
    }
    rm -rf -- $tempd
  }
}

backtick -E uvoxen_dep {
  yq -p toml -o json -r -e -- ".\"dependency-groups\".\"testenv-uvoxen\" | filter(. | contains(\"uvoxen \"))[0]" pyproject.toml
}

foreground {
  if {
    mkdir ${tempd}/feature-check-source
  }
  if {
    pipeline {
      tar cf - --exclude .jj --exclude target .
    }
    cd ${tempd}/feature-check-source
    tar xf -
  }
  
  cd ${tempd}/feature-check-source
  
  if {
    tools/rust/build-and-test
  }
  if {
    if {
      cargo build --release
    }
    env TEST_PROG=./target/release/feature-check-cli prove t
  }
  if {
    if {
      uv venv ${tempd}/venv-uvoxen
    }
    sh -c "set -e; . '${tempd}/venv-uvoxen/bin/activate'; uv pip install 'uvoxen >= 0.2.8'"
  }
  if {
    ${tempd}/venv-uvoxen/bin/uvoxen -p supported uv run
  }
  if {
    cd python
    ${tempd}/venv-uvoxen/bin/uvoxen -p supported uv run
  }
  
  echo "Seems fine"
}

importas exitcode ?
foreground {
  echo "Cleaning up ${tempd}"
}
foreground {
  rm -rf -- $tempd
}
exit $exitcode
