Skip to content

Commit 9cc2c76

Browse files
szedergitster
authored andcommitted
travis-ci: record and skip successfully built trees
Travis CI dutifully builds and tests each new branch tip, even if its tree has previously been successfully built and tested. This happens often enough in contributors' workflows, when a work-in-progress branch is rebased changing e.g. only commit messages or the order or number of commits while leaving the resulting code intact, and is then pushed to a Travis CI-enabled GitHub fork. This is wasting Travis CI's resources and is sometimes scary-annoying when the new tip commit with a tree identical to the previous, successfully tested one is suddenly reported in red, because one of the OSX build jobs happened to exceed the time limit yet again. So extend our Travis CI build scripts to skip building commits whose trees have previously been successfully built and tested. Use the Travis CI cache feature to keep a record of the object names of trees that tested successfully, in a plain and simple flat text file, one line per tree object name. Append the current tree's object name at the end of every successful build job to this file, along with a bit of additional info about the build job (commit object name, Travis CI job number and id). Limit the size of this file to 1000 records, to prevent it from growing too large for git/git's forever living integration branches. Check, using a simple grep invocation, in each build job whether the current commit's tree is already in there, and skip the build if it is. Include a message in the skipped build job's trace log, containing the URL to the build job successfully testing that tree for the first time and instructions on how to force a re-build. Catch the case when a build job, which successfully built and tested a particular tree for the first time, is restarted and omit the URL of the previous build job's trace log, as in this case it's the same build job and the trace log has just been overwritten. Note: this won't kick in if two identical trees are on two different branches, because Travis CI caches are not shared between build jobs of different branches. Signed-off-by: SZEDER Gábor <[email protected]> Reviewed-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b4a2fdc commit 9cc2c76

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed

ci/lib-travisci.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,52 @@ skip_branch_tip_with_tag () {
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
@@ -30,6 +76,7 @@ set -ex
3076
mkdir -p "$HOME/travis-cache"
3177

3278
skip_branch_tip_with_tag
79+
skip_good_tree
3380

3481
if test -z "$jobname"
3582
then

ci/run-linux32-docker.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ docker run \
2222
--volume "${HOME}/travis-cache:/tmp/travis-cache" \
2323
daald/ubuntu32:xenial \
2424
/usr/src/git/ci/run-linux32-build.sh $(id -u $USER)
25+
26+
save_good_tree

ci/run-static-analysis.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
. ${0%/*}/lib-travisci.sh
77

88
make coccicheck
9+
10+
save_good_tree

ci/run-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77

88
ln -s $HOME/travis-cache/.prove t/.prove
99
make --quiet test
10+
11+
save_good_tree

ci/run-windows-build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@ gfwci "action=log&buildId=$BUILD_ID" | cut -c 30-
9999

100100
# Set exit code for TravisCI
101101
test "$RESULT" = "success"
102+
103+
save_good_tree

ci/test-documentation.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ sed '/^GIT_VERSION = / d' stderr.log
2525
! test -s stderr.log
2626
test -s Documentation/git.html
2727
grep '<meta name="generator" content="Asciidoctor ' Documentation/git.html
28+
29+
save_good_tree

0 commit comments

Comments
 (0)