Skip to content

Commit a19caa7

Browse files
committed
Merge branch 'sg/travis-skip-identical-test'
Avoid repeatedly testing the same tree in TravisCI that have been tested successfully already. * sg/travis-skip-identical-test: travis-ci: record and skip successfully built trees travis-ci: create the cache directory early in the build process travis-ci: print the "tip of branch is exactly at tag" message in color
2 parents a09a5e6 + 9cc2c76 commit a19caa7

File tree

6 files changed

+60
-2
lines changed

6 files changed

+60
-2
lines changed

ci/lib-travisci.sh

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
2874
set -ex
2975

76+
mkdir -p "$HOME/travis-cache"
77+
3078
skip_branch_tip_with_tag
79+
skip_good_tree
3180

3281
if test -z "$jobname"
3382
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
. ${0%/*}/lib-travisci.sh
77

8-
mkdir -p $HOME/travis-cache
98
ln -s $HOME/travis-cache/.prove t/.prove
109
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)