@@ -16,18 +16,67 @@ skip_branch_tip_with_tag () {
16
16
if TAG=$( git describe --exact-match " $TRAVIS_BRANCH " 2> /dev/null) &&
17
17
test " $TAG " ! = " $TRAVIS_BRANCH "
18
18
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 ) "
20
20
exit 0
21
21
fi
22
22
}
23
23
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
+
24
70
# Set 'exit on error' for all CI scripts to let the caller know that
25
71
# something went wrong.
26
72
# Set tracing executed commands, primarily setting environment variables
27
73
# and installing dependencies.
28
74
set -ex
29
75
76
+ mkdir -p " $HOME /travis-cache"
77
+
30
78
skip_branch_tip_with_tag
79
+ skip_good_tree
31
80
32
81
if test -z " $jobname "
33
82
then
0 commit comments