From 55173058270cfec3d2af0c5284a47ea5051d2504 Mon Sep 17 00:00:00 2001 From: Artur Klauser Date: Wed, 25 Dec 2019 16:00:53 +0100 Subject: [PATCH] Add support as pre-commit hook Changes: * .pre-commit-hooks.yaml: defines this shellcheck repo as a hook for pre-commit * .travis.yml: make sure .pre-commit-hooks.yams is in sync with release --- .pre-commit-hooks.yaml | 7 +++++++ .travis.yml | 11 +++++++++++ README.md | 7 +++++++ 3 files changed, 25 insertions(+) create mode 100644 .pre-commit-hooks.yaml diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 0000000..4e9e38f --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,7 @@ +# See https://pre-commit.com for more information +- id: shellcheck + name: shellcheck shell scripts + description: Validate shell scripts with shellcheck running in Docker + language: docker_image + entry: koalaman/shellcheck:v0.7.1 + types: [shell] diff --git a/.travis.yml b/.travis.yml index d7d202b..785f337 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,6 +65,17 @@ before_install: | test "$TRAVIS_BRANCH" = master && TAGS="$TAGS latest" || true test -n "$TRAVIS_TAG" && TAGS="$TAGS stable $TRAVIS_TAG" || true echo "Tags are $TAGS" + set -e + # The version encoded in pre-commit and built version must be in sync. If not, + # the pre-commit version was forgotten to be updated. + if [ -n "$TRAVIS_TAG" ]; then + precommit_tag="$(awk -F: '/^ *entry:/ {print $NF}' .pre-commit-hooks.yaml)" + if [ "$TRAVIS_TAG" != "$precommit_tag" ]; then + echo "Wrong version number $precommit_tag in .pre-commit-hooks.yaml" + sleep 1 # give Travis time to grab the error message + exit 1 + fi + fi # This is in global context and runs for every stage that doesn't override it. script: diff --git a/README.md b/README.md index 05ce5ad..a1404cd 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,13 @@ docker run --rm -v "$PWD:/mnt" koalaman/shellcheck:stable myscript or use `koalaman/shellcheck-alpine` if you want a larger Alpine Linux based image to extend. It works exactly like a regular Alpine image, but has shellcheck preinstalled. +From [pre-commit](https://pre-commit.com/), add this to your `.pre-commit-config.yaml`: + + - repo: https://github.com/koalaman/shellcheck + rev: '' # Use the sha / tag you want to point at + hooks: + - id: shellcheck + Using the [nix package manager](https://nixos.org/nix): ```sh nix-env -iA nixpkgs.shellcheck