Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
syntaqx committed Mar 27, 2019
0 parents commit d21c851
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yml
Original file line number Diff line number Diff line change
@@ -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$
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Chase Pierce <[email protected]>

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.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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].
29 changes: 29 additions & 0 deletions hooks/circleci-config-validate.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d21c851

Please sign in to comment.