#!/bin/sh
# script/check: run all checks (test, lint, fmt-check) and then the
# image build. Our own extension to scripts-to-rule-them-all. test and
# lint are Docker phases; fmt-check is native, because a formatter
# writes the working tree. Must not modify any files.
set -eu

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"

main() {
    "$SCRIPT_DIR/test"
    "$SCRIPT_DIR/lint"
    "$SCRIPT_DIR/fmt-check"
    # No --no-cache here: the two phases this build depends on were just
    # built uncached above, so what it reuses is that run and not an
    # older one.
    cd "$ROOT"
    docker build -t "$("$SCRIPT_DIR/projectname")" .
}

main "$@"
