enable pre-commit

This commit is contained in:
MorganGeek 2020-02-15 15:16:45 +01:00
parent c2259c5783
commit 1732ed5cd2
16 changed files with 283 additions and 120 deletions

45
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,45 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: pretty-format-json
- id: check-symlinks
- id: detect-aws-credentials
- id: detect-private-key
- id: flake8
- id: requirements-txt-fixer
- id: sort-simple-yaml
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.25.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks:
- id: terraform_fmt
- id: terraform_docs
- id: terraform_tflint
args: ['--deep']
- id: terraform_validate
- repo: https://github.com/jumanjihouse/pre-commit-hooks
sha: 1.11.2
hooks:
- id: shellcheck
- id: shfmt
- id: script-must-have-extension
- id: git-check
# - id: git-dirty
- id: forbid-binary
- id: bundler-audit
#- repo: https://github.com/ansible/ansible-lint.git
# rev: v4.1.0
# hooks:
# - id: ansible-lint
# files: \.(yaml|yml)$
#- repo: https://github.com/pre-commit/mirrors-autopep8
# rev: 'v1.5' # Use the sha / tag you want to point at
# hooks:
# - id: autopep8

View File

@ -158,3 +158,6 @@ brew "coreutils"
brew "gh" # GitHub CLI brew "gh" # GitHub CLI
brew "bash" # time to upgrade bash brew "bash" # time to upgrade bash
brew "popeye" # Kubernetes resources sanity analysis brew "popeye" # Kubernetes resources sanity analysis
brew "pre-commit" # https://pre-commit.com/#install
brew "terraform-docs" # https://github.com/segmentio/terraform-docs
brew "shfmt" # format shell

View File

@ -74,8 +74,8 @@ source "/root/.sdkman/bin/sdkman-init.sh"
# Install Plantuml # Install Plantuml
sdk install java sdk install java
curl -L http://sourceforge.net/projects/plantuml/files/plantuml.jar/download -o /usr/local/bin/plantuml.jar && \ curl -L http://sourceforge.net/projects/plantuml/files/plantuml.jar/download -o /usr/local/bin/plantuml.jar &&
echo 'java -jar /usr/local/bin/plantuml.jar $@' > /usr/local/bin/plantuml && \ echo 'java -jar /usr/local/bin/plantuml.jar $@' >/usr/local/bin/plantuml &&
chmod +x /usr/local/bin/plantuml chmod +x /usr/local/bin/plantuml
# Using pyenv to be able to install specific python versions https://stackoverflow.com/questions/49794432/how-to-setup-a-pipenv-python-3-6-project-if-os-python-version-is-3-5 # Using pyenv to be able to install specific python versions https://stackoverflow.com/questions/49794432/how-to-setup-a-pipenv-python-3-6-project-if-os-python-version-is-3-5
@ -166,22 +166,22 @@ cd "$HOME"
sudo curl -o /usr/local/bin/googler https://raw.githubusercontent.com/jarun/googler/v3.9/googler && sudo chmod +x /usr/local/bin/googler sudo curl -o /usr/local/bin/googler https://raw.githubusercontent.com/jarun/googler/v3.9/googler && sudo chmod +x /usr/local/bin/googler
# Install BAT (cat with more power) # Install BAT (cat with more power)
wget https://github.com/sharkdp/bat/releases/download/v0.11.0/bat-v0.11.0-x86_64-unknown-linux-musl.tar.gz \ wget https://github.com/sharkdp/bat/releases/download/v0.11.0/bat-v0.11.0-x86_64-unknown-linux-musl.tar.gz &&
&& tar -xzvf bat-v0.11.0-x86_64-unknown-linux-musl.tar.gz \ tar -xzvf bat-v0.11.0-x86_64-unknown-linux-musl.tar.gz &&
&& mv bat-v0.11.0-x86_64-unknown-linux-musl/bat /usr/local/bin/ \ mv bat-v0.11.0-x86_64-unknown-linux-musl/bat /usr/local/bin/ &&
&& rm -rf bat-v0.11.0-x86_64-unknown-linux-musl* rm -rf bat-v0.11.0-x86_64-unknown-linux-musl*
# Install fselect # Install fselect
cargo install fselect cargo install fselect
# surfraw # surfraw
git clone --depth 1 https://gitlab.com/surfraw/Surfraw.git \ git clone --depth 1 https://gitlab.com/surfraw/Surfraw.git &&
&& cd Surfraw \ cd Surfraw &&
&& ./prebuild \ ./prebuild &&
&& ./configure \ ./configure &&
&& make && make install \ make && make install &&
&& cd .. \ cd .. &&
&& rm -rf Surfraw rm -rf Surfraw
# Dictionary # Dictionary
yum -y install dictd yum -y install dictd
@ -232,7 +232,6 @@ EOF
yum install -y kubectl yum install -y kubectl
# Install the harbottle-main repo # Install the harbottle-main repo
sudo yum -y install https://harbottle.gitlab.io/harbottle-main/7/x86_64/harbottle-main-release.rpm sudo yum -y install https://harbottle.gitlab.io/harbottle-main/7/x86_64/harbottle-main-release.rpm
yum -y install kubectx yum -y install kubectx

View File

@ -0,0 +1,45 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: pretty-format-json
- id: check-symlinks
- id: detect-aws-credentials
- id: detect-private-key
- id: flake8
- id: requirements-txt-fixer
- id: sort-simple-yaml
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.25.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks:
- id: terraform_fmt
- id: terraform_docs
- id: terraform_tflint
args: ['--deep']
- id: terraform_validate
- repo: https://github.com/jumanjihouse/pre-commit-hooks
sha: 1.11.2
hooks:
- id: shellcheck
- id: shfmt
- id: script-must-have-extension
- id: git-check
# - id: git-dirty
- id: forbid-binary
- id: bundler-audit
#- repo: https://github.com/ansible/ansible-lint.git
# rev: v4.1.0
# hooks:
# - id: ansible-lint
# files: \.(yaml|yml)$
#- repo: https://github.com/pre-commit/mirrors-autopep8
# rev: 'v1.5' # Use the sha / tag you want to point at
# hooks:
# - id: autopep8

View File

@ -0,0 +1,44 @@
#!/usr/bin/env python
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
import os
import sys
# we try our best, but the shebang of this script is difficult to determine:
# - macos doesn't ship with python3
# - windows executables are almost always `python.exe`
# therefore we continue to support python2 for this small script
if sys.version_info < (3, 3):
from distutils.spawn import find_executable as which
else:
from shutil import which
# work around https://github.com/Homebrew/homebrew-core/issues/30445
os.environ.pop('__PYVENV_LAUNCHER__', None)
# start templated
INSTALL_PYTHON = '/usr/local/Cellar/pre-commit/2.0.1/libexec/bin/python3.8'
ARGS = ['hook-impl', '--config=.pre-commit-config.yaml', '--hook-type=pre-commit', '--skip-on-missing-config']
# end templated
ARGS.extend(('--hook-dir', os.path.realpath(os.path.dirname(__file__))))
ARGS.append('--')
ARGS.extend(sys.argv[1:])
DNE = '`pre-commit` not found. Did you forget to activate your virtualenv?'
if os.access(INSTALL_PYTHON, os.X_OK):
CMD = [INSTALL_PYTHON, '-mpre_commit']
elif which('pre-commit'):
CMD = ['pre-commit']
else:
raise SystemExit(DNE)
CMD.extend(ARGS)
if sys.platform == 'win32': # https://bugs.python.org/issue19124
import subprocess
if sys.version_info < (3, 7): # https://bugs.python.org/issue25942
raise SystemExit(subprocess.Popen(CMD).wait())
else:
raise SystemExit(subprocess.call(CMD))
else:
os.execvp(CMD[0], CMD)

View File

@ -31,4 +31,4 @@
[diff] [diff]
noprefix = true noprefix = true
[init] [init]
templatedir = ~/.git-templates templateDir = /Users/morganwattiez/.git-template

10
dot_profile Normal file
View File

@ -0,0 +1,10 @@
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export JETBRAINS_LICENSE_SERVER=https://licenseserver.collibra.com
export PATH="$HOME/.cargo/bin:$PATH"

View File

@ -31,6 +31,7 @@ esac
# Create symbolic links # Create symbolic links
echo "Creating symbolic links" echo "Creating symbolic links"
ln -snf ~/Code/dotfiles/dot_profile ~/.profile
ln -snf ~/.local/share/chezmoi/ ~/dotfiles ln -snf ~/.local/share/chezmoi/ ~/dotfiles
ln -snf ~/Code/dotfiles/Gemfile ~/Gemfile ln -snf ~/Code/dotfiles/Gemfile ~/Gemfile
ln -snf ~/Code/dotfiles/README.md ~/README.md ln -snf ~/Code/dotfiles/README.md ~/README.md
@ -49,6 +50,7 @@ ln -snf ~/Code/dotfiles/dot_surfraw.conf ~/.surfraw.conf
ln -snf ~/Code/dotfiles/private_dot_3llo/config.sh ~/.3llo_config ln -snf ~/Code/dotfiles/private_dot_3llo/config.sh ~/.3llo_config
ln -snf ~/Code/dotfiles/dot_ansiweatherrc ~/.ansiweatherrc ln -snf ~/Code/dotfiles/dot_ansiweatherrc ~/.ansiweatherrc
ln -snf ~/Code/dotfiles/dot_p10k_dot_zsh ~/.p10k.zsh ln -snf ~/Code/dotfiles/dot_p10k_dot_zsh ~/.p10k.zsh
ln -snf ~/Code/dotfiles/dot_git-template ~/.git-template
# Other symblinks + Install Docker Desktop for Mac # Other symblinks + Install Docker Desktop for Mac
case "$(uname -s)" in case "$(uname -s)" in
@ -205,6 +207,12 @@ git clone https://github.com/sherlock-project/sherlock.git ~/Code/sherlock
cd sherlock || exit cd sherlock || exit
python3 -m pip install -r requirements.txt python3 -m pip install -r requirements.txt
git config --global init.templateDir ~/.git-template
pre-commit init-templatedir ~/.git-template
terraform-docs completion zsh >/usr/local/share/zsh/site-functions/_terraform-docs
autoload -U compinit && compinit
# Upgrade # Upgrade
echo "Upgrading apps" echo "Upgrading apps"
~/.scripts/upgrade.sh ~/.scripts/upgrade.sh

View File

@ -31,3 +31,6 @@ aws-iam-authenticator version
stern --version stern --version
helm version helm version
terragrunt --version terragrunt --version
pre-commit --version
terraform-docs --version
tflint --version

View File

@ -71,6 +71,7 @@ alias ipinfo='curl "ipinfo.io/"$(ip)'
# Misc # Misc
alias h='cd $HOME' alias h='cd $HOME'
alias bash="/usr/local/bin/bash"
alias diff='colordiff' alias diff='colordiff'
alias cp='cp -i' # confirmation before overwrite # alias cp='cp -i' # confirmation before overwrite #
alias mv='mv -i' # confirmation before overwrite alias mv='mv -i' # confirmation before overwrite

View File

@ -226,3 +226,8 @@ function gcrb {
} }
function terraform-compliance { docker run --rm -v "$(pwd):/target" -i -t eerkunt/terraform-compliance "$@"; } function terraform-compliance { docker run --rm -v "$(pwd):/target" -i -t eerkunt/terraform-compliance "$@"; }
function checkov { docker run -i --rm -v "$(pwd):/tf" bridgecrew/checkov -d /tf "$@" ; } function checkov { docker run -i --rm -v "$(pwd):/tf" bridgecrew/checkov -d /tf "$@" ; }
function copyhooks {
cp -f ~/.git-template/.pre-commit-config.yaml ./
pre-commit install --install-hooks --overwrite
pre-commit run -a
}