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 "bash" # time to upgrade bash
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

@ -45,14 +45,14 @@ rm -rf fonts
# Install ZSH
sudo yum -y install zsh
curl https://raw.githubusercontent.com/git-ftp/git-ftp/master/git-ftp > /bin/git-ftp
curl https://raw.githubusercontent.com/git-ftp/git-ftp/master/git-ftp >/bin/git-ftp
# Install git-ftp
chmod 755 /bin/git-ftp
# Install Golang
yum install golang golang-godoc golang-vet golang-src golang-pkg-linux-amd64 -y
echo "export GOPATH=\"$HOME/go\"" >> ~/.zshrc
echo "export PATH=\"$GOPATH/bin:$PATH\"" >> ~/.zshrc
echo "export GOPATH=\"$HOME/go\"" >>~/.zshrc
echo "export PATH=\"$GOPATH/bin:$PATH\"" >>~/.zshrc
. ~/.zshrc
# Install Hugo
@ -74,15 +74,15 @@ source "/root/.sdkman/bin/sdkman-init.sh"
# Install Plantuml
sdk install java
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 && \
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 &&
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
curl https://pyenv.run | bash
echo "export PYENV_ROOT=\"$HOME/.pyenv\"" >> ~/.zshrc
echo "export PATH=\"$PYENV_ROOT/bin:$PATH\"" >> ~/.zshrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
echo "export PYENV_ROOT=\"$HOME/.pyenv\"" >>~/.zshrc
echo "export PATH=\"$PYENV_ROOT/bin:$PATH\"" >>~/.zshrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >>~/.zshrc
source ~/.zshrc
yum -y install git gcc zlib-devel bzip2-devel readline-devel sqlite-devel openssl-devel
# Install Python 3
@ -122,7 +122,7 @@ yum -y install ansible
yum -y install cargo
# Next gen ls command https://github.com/Peltoche/lsd
cargo install lsd
echo 'export PATH="/root/.cargo/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/root/.cargo/bin:$PATH"' >>~/.zshrc
source ~/.zshrc
# Prepare swipl install
@ -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
# 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 \
&& 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/ \
&& rm -rf bat-v0.11.0-x86_64-unknown-linux-musl*
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 &&
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*
# Install fselect
cargo install fselect
# surfraw
git clone --depth 1 https://gitlab.com/surfraw/Surfraw.git \
&& cd Surfraw \
&& ./prebuild \
&& ./configure \
&& make && make install \
&& cd .. \
&& rm -rf Surfraw
git clone --depth 1 https://gitlab.com/surfraw/Surfraw.git &&
cd Surfraw &&
./prebuild &&
./configure &&
make && make install &&
cd .. &&
rm -rf Surfraw
# Dictionary
yum -y install dictd
@ -196,13 +196,13 @@ yes | ~/.fzf/install
#exec "$SHELL"
# Install diff-so-fancy
curl https://raw.githubusercontent.com/so-fancy/diff-so-fancy/master/third_party/build_fatpack/diff-so-fancy > /usr/local/bin/diff-so-fancy && chmod +x /usr/local/bin/diff-so-fancy
curl https://raw.githubusercontent.com/so-fancy/diff-so-fancy/master/third_party/build_fatpack/diff-so-fancy >/usr/local/bin/diff-so-fancy && chmod +x /usr/local/bin/diff-so-fancy
# Install nice disk usage
yum -y install ncdu
# Install tldr alternative to help
curl https://raw.githubusercontent.com/raylee/tldr/master/tldr > /usr/local/bin/tldr && chmod +x /usr/local/bin/tldr
curl https://raw.githubusercontent.com/raylee/tldr/master/tldr >/usr/local/bin/tldr && chmod +x /usr/local/bin/tldr
# Add pandoc
yum -y install pandoc
@ -220,7 +220,7 @@ yum -y install neofetch
cargo install nu
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
cat <<EOF >/etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
@ -232,7 +232,6 @@ EOF
yum install -y kubectl
# Install the harbottle-main repo
sudo yum -y install https://harbottle.gitlab.io/harbottle-main/7/x86_64/harbottle-main-release.rpm
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]
noprefix = true
[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

@ -10,7 +10,7 @@ chmod +x ~/.scripts/*.sh
# Install missing package (Linux)
case "$(uname -s)" in
Linux)
Linux)
echo "(Linux) Installing Development Tools"
yum install sudo -y
sudo yum groupinstall 'Development Tools' -y
@ -20,7 +20,7 @@ esac
# Install HomeBrew
case "$(uname -s)" in
Darwin)
Darwin)
echo "(Mac OS X) installing homebrew"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Prevent `Error: Your Homebrew is outdated. Please run `brew update`.`
@ -31,6 +31,7 @@ esac
# Create symbolic links
echo "Creating symbolic links"
ln -snf ~/Code/dotfiles/dot_profile ~/.profile
ln -snf ~/.local/share/chezmoi/ ~/dotfiles
ln -snf ~/Code/dotfiles/Gemfile ~/Gemfile
ln -snf ~/Code/dotfiles/README.md ~/README.md
@ -49,10 +50,11 @@ ln -snf ~/Code/dotfiles/dot_surfraw.conf ~/.surfraw.conf
ln -snf ~/Code/dotfiles/private_dot_3llo/config.sh ~/.3llo_config
ln -snf ~/Code/dotfiles/dot_ansiweatherrc ~/.ansiweatherrc
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
case "$(uname -s)" in
Darwin)
Darwin)
echo "(Mac OS X) Adding symbolic links"
ln -snf "$HOME/.config/Code/User/settings.json" "$HOME/Library/Application Support/Code/User/settings.json"
ln -snf "$HOME/Library/Mobile Documents/com~apple~CloudDocs/Mackup/Library/Application Support/Code/User/snippets" "$HOME/Library/Application Support/Code/User/snippets"
@ -64,7 +66,7 @@ esac
# Install dependencies (apps, fonts, ...) with Brew
case "$(uname -s)" in
Darwin)
Darwin)
echo "(Mac OS X) Brew installing stuff (apps, fonts, ...)"
ln -snf ~/Code/dotfiles/Brewfile ~/Brewfile
brew bundle
@ -73,7 +75,7 @@ esac
# Install dependencies (apps, fonts, ...) for CentOS
case "$(uname -s)" in
Linux)
Linux)
echo "(CentOS) Installing stuff (apps, ...)"
chmod +x ~/Code/dotfiles/centos.sh
~/Code/dotfiles/centos.sh
@ -82,7 +84,7 @@ esac
# Switch to ZSH
echo "switching to ZSH"
command -v zsh >> /etc/shells
command -v zsh >>/etc/shells
chsh -s "$(command -v zsh)"
# Use SDKMan to install development tools
@ -98,7 +100,7 @@ echo "SDKMan updating"
sdk selfupdate
case "$(uname -s)" in
Linux)
Linux)
echo '(Linux) Installing ruby'
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
@ -127,7 +129,7 @@ ln -snf ~/Code/dotfiles/dot_zshrc.pre-oh-my-zsh ~/.zshrc.pre-oh-my-zsh
echo "Installing Vundle + VIM Plugins"
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim +PluginInstall +qall > /dev/null
vim +PluginInstall +qall >/dev/null
#https://github.com/ycm-core/YouCompleteMe/blob/master/README.md#installation
cd "$HOME/.vim/bundle/YouCompleteMe" || exit
./install.py --all
@ -144,7 +146,7 @@ cd "$HOME" || exit
# OSX Defaults
case "$(uname -s)" in
Darwin)
Darwin)
echo "(Mac OS X) Loading preferences"
sudo sh .macos
;;
@ -161,7 +163,7 @@ sudo pip install --upgrade pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py
case "$(uname -s)" in
Darwin)
Darwin)
echo "(Mac OS X) Updating PATH for loading pip user installed packages"
ln -snf /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/bin/pip pip3
export PATH="$PATH:/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/bin/:/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/bin"
@ -178,16 +180,16 @@ pip install -r requirements.txt
# Install baton (CLI to manage Spotify playback) https://github.com/joshuathompson/baton
case "$(uname -s)" in
Darwin)
Darwin)
echo '(Mac OS X) Installing baton (spotify CLI)'
curl -sSL https://github.com/joshuathompson/baton/releases/download/0.1.7/baton-0.1.7-darwin-amd64 -o /usr/local/bin/baton && chmod +x /usr/local/bin/baton
;;
Linux)
Linux)
echo '(Linux) Installing baton (spotify CLI)'
curl -sSL https://github.com/joshuathompson/baton/releases/download/0.1.7/baton-0.1.7-linux-amd64 -o /usr/local/bin/baton && chmod +x /usr/local/bin/baton
;;
*)
*)
echo 'Non supported OS : Installation aborted for baton (spotify CLI)'
exit
;;
@ -205,6 +207,12 @@ git clone https://github.com/sherlock-project/sherlock.git ~/Code/sherlock
cd sherlock || exit
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
echo "Upgrading apps"
~/.scripts/upgrade.sh

View File

@ -7,7 +7,7 @@ sdk use java 8.0.222-zulu
# Homebrew reloading stuff
case "$(uname -s)" in
Darwin)
Darwin)
echo "(Mac OS X) Homebrew reloading stuff"
brew bundle
;;
@ -15,9 +15,9 @@ esac
# OSX Defaults
case "$(uname -s)" in
Darwin)
Darwin)
sudo sh .macos
;;
esac
pip freeze > /Users/morganwattiez/Code/dotfiles/requirements.txt
pip freeze >/Users/morganwattiez/Code/dotfiles/requirements.txt
bundle check

View File

@ -5,7 +5,7 @@ sdk selfupdate
# Upgrading HomeBrew stuff
case "$(uname -s)" in
Darwin)
Darwin)
echo "(Mac OS X) Homebrew upgrading stuff"
brew update
#brew upgrade
@ -20,7 +20,7 @@ zsh ~/.oh-my-zsh/tools/upgrade.sh
sudo pip install --upgrade pip 2>/dev/null
sudo pip3 install --upgrade pip 2>/dev/null
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
pip freeze > ~/requirements.txt
pip freeze >~/requirements.txt
# Update VIM plugins installed via Vundle https://github.com/VundleVim/Vundle.vim
vim +PluginUpdate +qall > /dev/null
vim +PluginUpdate +qall >/dev/null
rustup-update

View File

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

View File

@ -71,6 +71,7 @@ alias ipinfo='curl "ipinfo.io/"$(ip)'
# Misc
alias h='cd $HOME'
alias bash="/usr/local/bin/bash"
alias diff='colordiff'
alias cp='cp -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 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
}