Skip to content

Commit f8ee853

Browse files
committed
travis: fix skipping tagged releases
When building a PR, TRAVIS_BRANCH refers to the *target branch*. Therefore, if a PR targets `master`, and `master` happened to be tagged, we skipped the build by mistake. Fix this by using TRAVIS_PULL_REQUEST_BRANCH (i.e. the *source branch*) when available, falling back to TRAVIS_BRANCH (i.e. for CI builds, also known as "push builds"). Let's give it a new variable name, too: CI_BRANCH (as it is different from TRAVIS_BRANCH). This also prepares for the upcoming patches which will make our ci/* code a bit more independent from Travis and open it to other CI systems (in particular to Azure Pipelines). Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27e3e78 commit f8ee853

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

ci/lib-travisci.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ skip_branch_tip_with_tag () {
55
# at the same commit as the tip of the branch is pushed, and building
66
# both at the same time is a waste.
77
#
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-
test "$TAG" != "$TRAVIS_BRANCH"
8+
# When the build is triggered by a push to a tag, $CI_BRANCH will
9+
# have that tagname, e.g. v2.14.0. Let's see if $CI_BRANCH is
10+
# exactly at a tag, and if so, if it is different from $CI_BRANCH.
11+
# That way, we can tell if we are building the tip of a branch that
12+
# is tagged and we can skip the build because we won't be skipping a
13+
# build of a tag.
14+
15+
if TAG=$(git describe --exact-match "$CI_BRANCH" 2>/dev/null) &&
16+
test "$TAG" != "$CI_BRANCH"
1817
then
19-
echo "$(tput setaf 2)Tip of $TRAVIS_BRANCH is exactly at $TAG$(tput sgr0)"
18+
echo "$(tput setaf 2)Tip of $CI_BRANCH is exactly at $TAG$(tput sgr0)"
2019
exit 0
2120
fi
2221
}
@@ -81,6 +80,10 @@ check_unignored_build_artifacts ()
8180
# and installing dependencies.
8281
set -ex
8382

83+
# When building a PR, TRAVIS_BRANCH refers to the *target* branch. Not what we
84+
# want here. We want the source branch instead.
85+
CI_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}"
86+
8487
cache_dir="$HOME/travis-cache"
8588
good_trees_file="$cache_dir/good-trees"
8689

0 commit comments

Comments
 (0)