-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnetlify-ignore.sh
More file actions
48 lines (41 loc) · 1.76 KB
/
Copy pathnetlify-ignore.sh
File metadata and controls
48 lines (41 loc) · 1.76 KB
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
#! /bin/bash
# netlify-ignore.sh
# logic based shell script for the Netlify based on enivonment variables
# exiting script with code 1 means build, code 0 means no changes so cancel
# Optional Environmental Inputs:
# ALWAYS_BUILD: true,yes,on,1
# forces an always build
# WATCHED_BUILD_PATHS: example ( "../../common" )
# space separated paths to append to the default git diff statement
# Required Inputs Supplied from Netlify build environment variables
# CACHED_COMMIT_REF
# COMMIT_REF
# SITE_NAME
# Function to display usage
usage() {
echo -e "\033[1;33mUsage: $0 [--no-default-path]\033[0m"
echo -e "\033[1;33mDefault watch build path is set to '.' before other paths are included.\033[0m"
exit 0 # Exit script after printing usage and do not trigger a build
}
# Parse optional flag
DEFAULT_WATCH_BUILD_PATH="."
while [[ "$1" != "" ]]; do
case $1 in
--no-default-path ) DEFAULT_WATCH_BUILD_PATH="" # remove default path
;;
-h | --help ) usage
;;
* ) usage
;;
esac
shift
done
set -x
shopt -s nocasematch
regex="^(build|deploy|build $SITE_NAME|deploy $SITE_NAME)$"
if [[ ! "$WATCHED_BUILD_PATHS" =~ (false|no|off|0) ]]; then BUILD_PATHS="$WATCHED_BUILD_PATHS"; fi;
# shellcheck disable=SC2046
if [[ "$ALWAYS_BUILD" =~ (true|yes|on|1) ]]; then (exit 1);
elif [ "$CACHED_COMMIT_REF" == "$COMMIT_REF" ]; then (exit 1);
elif [[ $(git rev-parse "$COMMIT_REF^{tree}") == $(git rev-parse "$COMMIT_REF^1^{tree}") && $(git -P show -s "$COMMIT_REF" --format=%s ) =~ $regex ]]; then (exit 1);
else git diff --quiet "$CACHED_COMMIT_REF" "$COMMIT_REF" $([[ -n "$DEFAULT_WATCH_BUILD_PATH" ]] && echo "$DEFAULT_WATCH_BUILD_PATH ")$([[ -n "$BUILD_PATHS" ]] && echo " $BUILD_PATHS"); fi;