#!/usr/bin/env sh
set -e

export MIX_ENV=test

# Always install mix dependencies
(cd /srv/philomena && mix deps.get)

# Run formatting check
mix format --check-formatted

# Sleep to allow OpenSearch to finish initializing
# if it's not done doing whatever it does yet
echo -n "Waiting for OpenSearch"

until wget -qO - opensearch:9200; do
  echo -n "."
  sleep 2
done

echo

# Create the database
mix ecto.create
mix ecto.load

# Test the application
mix test

# Security lint
mix sobelow --config
mix deps.audit

# Static analysis
exec mix dialyzer