-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.sh
52 lines (42 loc) · 1.3 KB
/
index.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
# Detect Harmless Changes
# created by: @briangonzalez
# ---
# exits early if only 'harmless changes' were made
if [ -z "$1" ]
then
BRANCH = "master"
else
BRANCH = $1
fi
if [[ $CIRCLE_BRANCH == $BRANCH || $TRAVIS_BRANCH == $BRANCH ]]; then
exit 1
fi
if [[ ! -a .ciignore ]]; then
echo "Harmless Changes: exiting: no .ciignore file detected ❗️"
exit 1 # If .ciignore doesn't exists, just quit
fi
# Load in every file that is different than master
changes=( `git diff-tree --no-commit-id --name-only -r origin/master..HEAD` )
# 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.
echo "Harmless Changes: potentially harmful changes detected based on .ciignore 👀"
exit 1
else
# Otherwise, consider it harmless
echo "Harmless Changes: exiting: no harmless changes detected based on .ciignore 🎉"
exit 0
fi