#!/bin/bash
# Pre-release hook
set -e

# Make a directory for pre-release artifacts
mkdir -p artifacts

# Build release binaries
cargo build --release --all-targets

# Run all CSG examples
for example in $(ls examples/csg); do
    echo "Running example: $example"
    ./target/release/examples/${example%.rs}
done
# Move the STL files into the artifacts directory
mv ./target/test_renderings/*.stl artifacts

# Run the BVH example(s)
echo "Running BVH example"
./target/release/examples/bvh_raycast --num-regions 100 --num-samples 1000000 --bvh-depth 8

# Move the VTK files into the artifacts directory
mv ./target/test_renderings/*.vtk artifacts

# Run all crater CLI examples
crater_inputs_dir="examples/crater_inputs"
for example in $(ls $crater_inputs_dir); do
    echo "Running crater marching-cubes example: crater_inputs_dir/$example"
    ./target/release/crater marching-cubes -i $crater_inputs_dir/$example -o artifacts/${example%.yaml}.stl
done

# If --cliff is passed, run git cliff
if [[ "$1" == "--cliff" ]]; then
    echo "Running git cliff"
    git cliff -o CHANGELOG.md -c cliff.toml --tag $2
    exit 0
fi

echo "Pre-release script finished. cargo-release taking over"