From fc380b2ddab205f61d8d4c67cbb15b30770be93a Mon Sep 17 00:00:00 2001 From: abejgonzalez Date: Thu, 29 Aug 2019 23:43:08 -0700 Subject: [PATCH] ignore docs using a github webhook --- .ciignore | 1 + .githooks/ignore-certain-dirs-commit-msg | 31 ++++++++++++++++++++++++ scripts/add-githooks.sh | 5 ++++ 3 files changed, 37 insertions(+) create mode 100644 .ciignore create mode 100644 .githooks/ignore-certain-dirs-commit-msg create mode 100755 scripts/add-githooks.sh diff --git a/.ciignore b/.ciignore new file mode 100644 index 0000000000..a188e0692f --- /dev/null +++ b/.ciignore @@ -0,0 +1 @@ +docs/* diff --git a/.githooks/ignore-certain-dirs-commit-msg b/.githooks/ignore-certain-dirs-commit-msg new file mode 100644 index 0000000000..3ab0e7b45e --- /dev/null +++ b/.githooks/ignore-certain-dirs-commit-msg @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +if [[ ! -a .ciignore ]]; then + exit # If .ciignore doesn't exists, just quit this Git hook +fi + +# Load in every file that will be changed via this commit into an array +changes=( `git diff --name-only --cached` ) + +# Load the patterns we want to skip into an array +mapfile -t blacklist < .ciignore + +for i in "${blacklist[@]}" +do + # Remove the current pattern from the list of changes + changes=( ${changes[@]/$i/} ) + + if [[ ${#changes[@]} -eq 0 ]]; then + # If we've exhausted the list of changes before we've finished going + # through patterns, that's okay, just quit the loop + break + fi +done + +if [[ ${#changes[@]} -gt 0 ]]; then + # If there's still changes left, then we have stuff to build, leave the commit alone. + exit +fi + +# Prefix the commit message with "[skip ci]" +sed -i '1s/^/[skip ci] /' "$1" diff --git a/scripts/add-githooks.sh b/scripts/add-githooks.sh new file mode 100755 index 0000000000..fb5e47853e --- /dev/null +++ b/scripts/add-githooks.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +# adds githooks, expects to be run from base directory + +git config core.hooksPath .githooks