summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Herlant <aerostitch@debian.org>2019-11-01 18:18:43 -0700
committerJoseph Herlant <aerostitch@debian.org>2019-11-01 18:18:43 -0700
commite9d58b5bfd1dfd552655a7a6c3db17415d922858 (patch)
treeb23e2c692dbfd31d6961e50f5ba84dddc08f0671
parentf334e21516af6c1cb0b96d0d341d262586c33b9b (diff)
downloadnavit-e9d58b5bfd1dfd552655a7a6c3db17415d922858.tar.gz
update:CI: skip the build steps if the change is only for documentation
-rw-r--r--.circleci/config.yml8
-rwxr-xr-xscripts/check_need_build.sh46
2 files changed, 54 insertions, 0 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml
index bb542a94d..e9af55c9e 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -18,6 +18,7 @@ jobs:
<<: *defaults
steps:
- checkout
+ - run: if scripts/check_need_build.sh; then circleci step halt; fi
- run:
name: Id
command: cat /etc/*release
@@ -39,6 +40,7 @@ jobs:
<<: *defaults
steps:
- checkout
+ - run: if scripts/check_need_build.sh; then circleci step halt; fi
- run:
name: Install doxygen and other essentials
command: apt-get update && apt-get -y install doxygen ca-certificates git rsync
@@ -54,6 +56,7 @@ jobs:
machine: true
steps:
- checkout
+ - run: if scripts/check_need_build.sh; then circleci step halt; fi
- run:
name: install docker
command: circleci-install docker
@@ -75,6 +78,7 @@ jobs:
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
steps:
- checkout
+ - run: if scripts/check_need_build.sh; then circleci step halt; fi
- run:
name: Id
command: cat /etc/*release
@@ -131,6 +135,7 @@ jobs:
- image: ubuntu:14.04
steps:
- checkout
+ - run: if scripts/check_need_build.sh; then circleci step halt; fi
- run:
name: Prepare the Windows build environment
command: |
@@ -154,6 +159,7 @@ jobs:
- image: navit/dockerfiles:wince
steps:
- checkout
+ - run: if scripts/check_need_build.sh; then circleci step halt; fi
- run:
name: Prepare the WinCE build environment
command: |
@@ -173,6 +179,7 @@ jobs:
- image: navit/tomtom-ng
steps:
- checkout
+ - run: if scripts/check_need_build.sh; then circleci step halt; fi
- run:
name: Setup common requirements
command: |
@@ -193,6 +200,7 @@ jobs:
- image: navit/tomtom-ng
steps:
- checkout
+ - run: if scripts/check_need_build.sh; then circleci step halt; fi
- run:
name: Setup common requirements
command: |
diff --git a/scripts/check_need_build.sh b/scripts/check_need_build.sh
new file mode 100755
index 000000000..29937764f
--- /dev/null
+++ b/scripts/check_need_build.sh
@@ -0,0 +1,46 @@
+#!/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. #
+# ################################################################################################################### #
+
+# @brief: constructs 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.
+# @param: a variable you want to use to get the resulting value
+# @return: nothing (the input variable is modified according to the brief description)
+list_files_git_diff(){
+ local -n files=$1
+ files=$(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
+ files=$(git diff --name-only HEAD^)
+ fi
+}
+
+# @brief: get the list of files that have differed from trunk (by calling list_files_git_diff for the full list)
+# and filters out those don't match the pattern we use to exclude files that should not trigger a build.
+# @param: a variable you want to use to get the resulting value
+# @return: nothing (the input variable is modified according to the brief description)
+filtered_files_git_diff(){
+ local -n _ret=$1
+ declare -a filters=('^docs/.*', '.*\.md$', '.*\.rst$')
+ declare -a file_list=()
+ list_files_git_diff file_list
+ 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
+ _ret=$file_list
+}
+
+filtered_files_git_diff filtered_out_modified_files
+# exits with a 0 if the list is empty
+[[ -z "${filtered_out_modified_files}" ]]