From f8674f46c01f12060ab1fedc35dcf97ea9aaa558 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 12 Jul 2017 07:41:06 +0100 Subject: [PATCH] tools: travis: skip the build if only markdown files are changed Credit: tritoch at https://github.com/travis-ci/travis-ci/issues/6301#issuecomment-313559284 --- .travis-maybe-skip.sh | 30 ++++++++++++++++++++++++++++++ .travis.yml | 3 +++ 2 files changed, 33 insertions(+) create mode 100755 .travis-maybe-skip.sh diff --git a/.travis-maybe-skip.sh b/.travis-maybe-skip.sh new file mode 100755 index 000000000..b9b03eb3c --- /dev/null +++ b/.travis-maybe-skip.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Maybe skip (terminate) this travis build, if it seems unnecessary. +# Emulates appveyor's more powerful skip/only feature. + +set -e + +# works only on master ? +CHANGED_FILES=`git diff --name-only master...${TRAVIS_COMMIT}` + +# only files not matching this pattern will trigger a build +# extended regex, don't quote regex metachars +#SKIP_PAT="(^site/con|do.nload)" +SKIP_PAT="\.md$" + +# doesn't handle empty CHANGED_FILES correctly, shouldn't matter +SKIP=True +for F in $CHANGED_FILES; do + if ! [[ $F =~ $SKIP_PAT ]]; then + SKIP=False + break + fi +done + +if [[ $SKIP == True ]]; then + echo "Only skippable files found, exiting." + travis_terminate 0 + exit 1 +else + echo "Non-skippable files found, continuing with build." +fi diff --git a/.travis.yml b/.travis.yml index d8e4f9f38..fe210219a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,6 +71,9 @@ branches: # - ghc: 7.10.3 # - ghc: 8.0.2 +before_install: + - ./.travis-maybe-skip.sh + install: # command output is hidden as they complete # if any command fails, end the travis script