From d21c851f8ea266a1adb37cba4be066e8bac7e44a Mon Sep 17 00:00:00 2001 From: Chase Pierce Date: Wed, 27 Mar 2019 03:46:43 -0600 Subject: [PATCH] first commit --- .pre-commit-hooks.yml | 6 ++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 23 +++++++++++++++++++++++ hooks/circleci-config-validate.sh | 29 +++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 .pre-commit-hooks.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 hooks/circleci-config-validate.sh diff --git a/.pre-commit-hooks.yml b/.pre-commit-hooks.yml new file mode 100644 index 0000000..863b62f --- /dev/null +++ b/.pre-commit-hooks.yml @@ -0,0 +1,6 @@ +- id: circleci-config-validate + name: CircleCI config validator + description: Validates CircleCI configuration files locally + entry: hooks/circleci-config-validate.sh + language: [script] + files: ^.circleci/config.ya?ml$ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..92fdbde --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Chase Pierce + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8473ca7 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# git-hooks + +[pre-commit]: http://pre-commit.com/ + +A collection of useful Git hooks for integration with [pre-commit][]. + +## Usage + +Create or append to your `.pre-commit-config.yml` configuration: + +```yaml +- repo: https://github.com/syntaqx/git-hooks + hooks: + - id: circleci-config-validate +``` + +Then simply install or run the checks on-demand as desired. + +## License + +[MIT]: https://opensource.org/licenses/MIT + +`git-hooks` is open source software released under the [MIT license][MIT]. diff --git a/hooks/circleci-config-validate.sh b/hooks/circleci-config-validate.sh new file mode 100644 index 0000000..12dd2f1 --- /dev/null +++ b/hooks/circleci-config-validate.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Test if the CircleCI config file is well formed via the circleci local cli. +# https://circleci.com/docs/2.0/local-cli/ +# https://circleci.com/blog/circleci-hacks-validate-circleci-config-on-every-commit-with-a-git-hook/ + +set -o errexit +set -o pipefail +set -o nounset + +readonly DEBUG=${DEBUG:-unset} +[[ $DEBUG != unset ]] && set -x + +# assert the circleci command exists +if ! [ -x "$(command -v circleci)" ]; then + echo 'circleci command not found' + echo 'See https://circleci.com/docs/2.0/local-cli/ for installation instructions.' + exit 1 +fi + +# The following is needed by the circleci local build tool (due to Docker interactivity) +exec < /dev/tty + +# If validation fails, tell Git to stop and provide error message. Otherwise, continue. +if ! msg=$(circleci config validate); then + echo "CircleCI Configuration Failed Validation." + echo "$msg" + exit 1 +fi