From 2be30235da04f64a9018dc68bc97597831e7a23c Mon Sep 17 00:00:00 2001 From: Artur Klauser Date: Wed, 25 Dec 2019 16:02:03 +0100 Subject: [PATCH] Use pre-commit on this repo Changes: * .pre-commit-config.yaml: uses pre-commit on this repo * .travis.yml: run pre-commit in Travis CI pipeline --- .pre-commit-config.yaml | 13 +++++++++++++ .travis.yml | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8bf1d8d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit + rev: v2.1.1 + hooks: + - id: validate_manifest + +- repo: local + hooks: + - id: shellcheck + name: shellcheck + language: docker_image + entry: koalaman/shellcheck:stable + types: [shell] diff --git a/.travis.yml b/.travis.yml index 785f337..5fbea9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,6 +57,27 @@ jobs: - source ./.multi_arch_docker - set -ex; multi_arch_docker::main; set +x + # Run pre-commit checks with the shellcheck docker package that was just + # deployed. + - stage: Pre-commit checks + language: python + python: 3.7 + cache: + - pip + - directories: $HOME/.cache/pre-commit + install: pip install pre-commit + script: | + # Run pre-commit. It also uses shellcheck on itself from the just built + # and deployed docker image. + # Use the first build tag, or if there isn't any use 'latest'. + set -e + tag="$(echo "${TAGS/ */}")" + tag="${tag:-latest}" + echo "tag: $tag" + sed -i.bak -e "s/\(shellcheck\):.*/\1:$tag/" .pre-commit-config.yaml + pre-commit run --all-files --show-diff-on-failure --color=always + mv .pre-commit-config.yaml.bak .pre-commit-config.yaml + # This is in global context and runs for every stage that doesn't override it. before_install: | DOCKER_BASE="$DOCKER_USERNAME/shellcheck"