Browse Source

Add new Travis stuff so PRs only test the bits that have changed

Tianon Gravi 11 years ago
parent
commit
42dcf1a6c8
2 changed files with 41 additions and 2 deletions
  1. 4 2
      .travis.yml
  2. 37 0
      bashbrew/travis.sh

+ 4 - 2
.travis.yml

@@ -3,7 +3,9 @@ language: bash
 # allow for use of Docker-based workers
 sudo: false
 
+before_script:
+    - env | sort
+
 # --no-build because we has no Docker in Travis :)
 script:
-    - ./bashbrew/build.sh --no-build --all
-    - ./bashbrew/push.sh --no-push --all
+    - ./bashbrew/travis.sh

+ 37 - 0
bashbrew/travis.sh

@@ -0,0 +1,37 @@
+#!/bin/bash
+set -e
+
+cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
+
+repos=( --all )
+
+upstreamRepo='docker-library/official-images'
+upstreamBranch='master'
+if [ "$TRAVIS_PULL_REQUEST" -a "$TRAVIS_PULL_REQUEST" != 'false' ]; then
+	upstreamRepo="$TRAVIS_REPO_SLUG"
+	upstreamBranch="$TRAVIS_BRANCH"
+fi
+
+HEAD="$(git rev-parse --verify HEAD)"
+
+git fetch -q "https://github.com/$upstreamRepo.git" "refs/heads/$upstreamBranch"
+UPSTREAM="$(git rev-parse --verify FETCH_HEAD)"
+
+if [ "$(git diff --numstat "$UPSTREAM...$HEAD" -- . | wc -l)" ]; then
+	# changes in bashbrew/ -- keep "--all" so we test the bashbrew script changes appropriately
+	echo >&2 'Changes in bashbrew/ detected!'
+else
+	repos=( $(git diff --numstat "$UPSTREAM...$HEAD" -- ../library | awk -F '/' '{ print $2 }') )
+fi
+
+if [ "${#repos[@]}" -eq 0 ]; then
+	echo >&2 'Skipping test builds: no changes to library/ or bashbrew/ in PR'
+	exit
+fi
+
+# --no-build because we has no Docker in Travis :)
+# TODO that will change eventually!
+
+set -x
+./build.sh --no-build "${repos[@]}"
+./push.sh --no-push "${repos[@]}"