#!/usr/bin/env bash

if ! [ -z $DISABLE_ADDITIONAL_CHECKS ]; then
    echo "Check is disabled"
    exit 0
fi
# -- Get all the envs from the current helmfile installation
ENVS=$(yq '.environments | keys | .[]' ./common/environments.yaml)


FAILED_LINTERS=""
for ENV in $ENVS; do
    if ! helmfile -e $ENV lint; then FAILED_LINTERS="$ENV\n$FAILED_LINTERS"; fi
done
if ! [ -z $FAILED_LINTERS ]; then
    printf "\n\nSome env can't pass the linter:\n $FAILED_LINTERS"
    exit 1
fi

echo "The linter is happy"