#!/usr/bin/bash

set -euo pipefail

main() {
    failure=0

    make sort > /dev/null 2>&1 || {
        echo "Sort failed!"
        ((failure+=1))
    }
    make validate || {
        echo "Validate failed!"
        ((failure+=1))
    }

    # Fail if any changes were made to the repo
    if [[ -n $(git status --short) ]]; then
        echo "git status failed! This likely means the PR or the underlying repo is not sorted"
        ((failure+=1))
    fi
    if [[ $failure -gt 0 ]]; then
        echo "${failure} check(s) failed!"
        exit 1
    fi
}

main "${@}"
