Skip to content

Commit 09f5e97

Browse files
larsxschneidergitster
authored andcommitted
travis-ci: skip a branch build if equal tag is present
If we push a branch and a tag pointing to the HEAD of this branch, then Travis CI would run the build twice. This wastes resources and slows the testing. Add a function to detect this situation and skip the build the branch if appropriate. Invoke this function on every build. Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 657343a commit 09f5e97

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

ci/lib-travisci.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# Library of functions shared by all CI scripts
22

3+
skip_branch_tip_with_tag () {
4+
# Sometimes, a branch is pushed at the same time the tag that points
5+
# at the same commit as the tip of the branch is pushed, and building
6+
# both at the same time is a waste.
7+
#
8+
# Travis gives a tagname e.g. v2.14.0 in $TRAVIS_BRANCH when
9+
# the build is triggered by a push to a tag. Let's see if
10+
# $TRAVIS_BRANCH is exactly at a tag, and if so, if it is
11+
# different from $TRAVIS_BRANCH. That way, we can tell if
12+
# we are building the tip of a branch that is tagged and
13+
# we can skip the build because we won't be skipping a build
14+
# of a tag.
15+
16+
if TAG=$(git describe --exact-match "$TRAVIS_BRANCH" 2>/dev/null) &&
17+
$TAG != $TRAVIS_BRANCH
18+
then
19+
echo "Tip of $TRAVIS_BRANCH is exactly at $TAG"
20+
exit 0
21+
fi
22+
}
23+
324
# Set 'exit on error' for all CI scripts to let the caller know that
425
# something went wrong
526
set -e
27+
28+
skip_branch_tip_with_tag

0 commit comments

Comments
 (0)