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
This commit is contained in:
Artur Klauser 2019-12-25 16:02:03 +01:00
commit 2be30235da
No known key found for this signature in database
GPG key ID: 70B7884D56F42F15
2 changed files with 34 additions and 0 deletions

13
.pre-commit-config.yaml Normal file
View file

@ -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]

View file

@ -57,6 +57,27 @@ jobs:
- source ./.multi_arch_docker - source ./.multi_arch_docker
- set -ex; multi_arch_docker::main; set +x - 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. # This is in global context and runs for every stage that doesn't override it.
before_install: | before_install: |
DOCKER_BASE="$DOCKER_USERNAME/shellcheck" DOCKER_BASE="$DOCKER_USERNAME/shellcheck"