@@ -16,18 +16,67 @@ skip_branch_tip_with_tag () {
1616 if TAG=$( git describe --exact-match " $TRAVIS_BRANCH " 2> /dev/null) &&
1717 test " $TAG " ! = " $TRAVIS_BRANCH "
1818 then
19- echo " Tip of $TRAVIS_BRANCH is exactly at $TAG "
19+ echo " $( tput setaf 2 ) Tip of $TRAVIS_BRANCH is exactly at $TAG $( tput sgr0 ) "
2020 exit 0
2121 fi
2222}
2323
24+ good_trees_file=" $HOME /travis-cache/good-trees"
25+
26+ # Save some info about the current commit's tree, so we can skip the build
27+ # job if we encounter the same tree again and can provide a useful info
28+ # message.
29+ save_good_tree () {
30+ echo " $( git rev-parse $TRAVIS_COMMIT ^{tree}) $TRAVIS_COMMIT $TRAVIS_JOB_NUMBER $TRAVIS_JOB_ID " >> " $good_trees_file "
31+ # limit the file size
32+ tail -1000 " $good_trees_file " > " $good_trees_file " .tmp
33+ mv " $good_trees_file " .tmp " $good_trees_file "
34+ }
35+
36+ # Skip the build job if the same tree has already been built and tested
37+ # successfully before (e.g. because the branch got rebased, changing only
38+ # the commit messages).
39+ skip_good_tree () {
40+ if ! good_tree_info=" $( grep " ^$( git rev-parse $TRAVIS_COMMIT ^{tree}) " " $good_trees_file " ) "
41+ then
42+ # Haven't seen this tree yet, or no cached good trees file yet.
43+ # Continue the build job.
44+ return
45+ fi
46+
47+ echo " $good_tree_info " | {
48+ read tree prev_good_commit prev_good_job_number prev_good_job_id
49+
50+ if test " $TRAVIS_JOB_ID " = " $prev_good_job_id "
51+ then
52+ cat << -EOF
53+ $( tput setaf 2) Skipping build job for commit $TRAVIS_COMMIT .$( tput sgr0)
54+ This commit has already been built and tested successfully by this build job.
55+ To force a re-build delete the branch's cache and then hit 'Restart job'.
56+ EOF
57+ else
58+ cat << -EOF
59+ $( tput setaf 2) Skipping build job for commit $TRAVIS_COMMIT .$( tput sgr0)
60+ This commit's tree has already been built and tested successfully in build job $prev_good_job_number for commit $prev_good_commit .
61+ The log of that build job is available at https://travis-ci.org/$TRAVIS_REPO_SLUG /jobs/$prev_good_job_id
62+ To force a re-build delete the branch's cache and then hit 'Restart job'.
63+ EOF
64+ fi
65+ }
66+
67+ exit 0
68+ }
69+
2470# Set 'exit on error' for all CI scripts to let the caller know that
2571# something went wrong.
2672# Set tracing executed commands, primarily setting environment variables
2773# and installing dependencies.
2874set -ex
2975
76+ mkdir -p " $HOME /travis-cache"
77+
3078skip_branch_tip_with_tag
79+ skip_good_tree
3180
3281if test -z " $jobname "
3382then
0 commit comments