#!/bin/sh

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

function check() {
    name=$1
    command=$2
    if sh -c "$command >/dev/null 2>&1"; then
        echo -e "${GREEN}✅ $name${NC}"
    else
        echo -e "${RED}❌ $name failed${NC}"
        exit 1
    fi
}

check "fmt" "cargo +nightly fmt"
check "check" "cargo check"
check "clippy" "cargo clippy --all-targets -- -D warnings" &
check "machete" "cargo machete" &
check "deny" "cargo deny check licenses" &
check "test" "cargo test" &
check "changelog syntax" "xmllint --noout CHANGELOG.xml" &
check "changelog schema" "xmllint --noout --schema CHANGELOG.xsd CHANGELOG.xml" &
wait
echo -e "${GREEN}🎉 all done!${NC}"
