summaryrefslogtreecommitdiff
path: root/scripts/check_need_build.sh
blob: 4e15adeb72bb4c6163f0cc80d9ff3071c29af3d1 (plain)
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
#!/bin/bash -e
# ################################################################################################################### #
# This file exits 1 if there are files of interest that should trigger a build and exits normally otherwise.          #
# The idea is also to build if the exit code is different from 0 as it means we cannot get a filtered list properly.  #
# ################################################################################################################### #

# This blockconstructs the list of files that differ from the trunk branch.
# Note that if you are on the trunk or master branch it will return the files modified by the last commit.
declare -a file_list=$(git diff --name-only refs/remotes/origin/trunk)

# If there is no diff that might just mean that you are on the trunk or master branch
# so you just want to check the last commit. This way we still have that check more
# or less working when pushing directly to trunk or when merging in master.
if [[ -z "$files" ]]; then
    file_list=$(git diff --name-only HEAD^)
fi

# This block filters out those don't match the pattern we use to exclude files that should not trigger a build.
declare -a filters=('^docs/.*' '.*\.md$' '.*\.rst$' '.*') # WARNING! '.*' is here only for testing if the circleci command works. It should be removed before merge!
for f in ${file_list[@]}; do
    for filter in "${filters[@]}" ; do
        if [[ "$f" =~ $filter ]]; then
            # This removes the element from the element matching the filter
            file_list=(${file_list[@]/$f})
            break
        fi
    done
done

# exits with a 0 if the list is empty
[[ -z "${filte_list}" ]]