Last active
August 11, 2022 23:52
-
-
Save pgib/131365897bcd93d34e69a54be9105518 to your computer and use it in GitHub Desktop.
CircleCI precommit hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Slightly modified from: https://circleci.com/blog/circleci-hacks-validate-circleci-config-on-every-commit-with-a-git-hook/ | |
# The following line is needed by the CircleCI Local Build Tool (due to Docker interactivity) | |
exec < /dev/tty | |
# Only validate if we've changed the .circleci/config.yml file | |
if git diff --cached --name-only | grep --quiet ".circleci/config.yml"; then | |
# Make sure we have the circleci utility installed | |
# https://circleci.com/docs/local-cli | |
circleci_path=$(which circleci) | |
return_code=$? | |
if [ ${return_code} -eq 0 ]; then | |
# If validation fails, tell Git to stop and provide error message. Otherwise, continue. | |
if ! eMSG=$(circleci config validate -c .circleci/config.yml); then | |
echo "CircleCI Configuration Failed Validation." | |
echo $eMSG | |
exit 1 | |
fi | |
else | |
echo "circleci utility not found, so we can't validate the changed config file." | |
sleep 2 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment