ci: find latest tag when deeper than the git clone depth (#14231)

Since we have a shallow clone of the repository, it might be the case that the
latest tag (which we need for publishing the build artifacts) might not be in
the current history.

This commit incrementally deepens the clone until it finds a tag (or reaches a
max depth).

PR Close #14231
This commit is contained in:
Georgios Kalpakas 2017-02-01 21:51:12 +02:00 committed by Miško Hevery
parent 09b4bd0dfb
commit b64946b5f9
2 changed files with 25 additions and 5 deletions

View File

@ -3,10 +3,6 @@ sudo: false
node_js:
- '6.9.5'
git:
# Increased from default (50) to ensure last release tag is in this range
depth: 150
addons:
# firefox: "38.0"
apt:

View File

@ -2,6 +2,30 @@
set -e -x
# Find the most recent tag that is reachable from the current commit.
# This is shallow clone of the repo, so we might need to fetch more commits to
# find the tag.
function getLatestTag {
local depth=`git log --oneline | wc -l`
local latestTag=`git describe --tags --abbrev=0 || echo NOT_FOUND`
while [ "$latestTag" == "NOT_FOUND" ]; do
# Avoid infinite loop.
if [ "$depth" -gt "1000" ]; then
echo "Error: Unable to find the latest tag." 1>&2
exit 1;
fi
# Increase the clone depth and look for a tag.
depth=$((depth + 50))
echo "Looking for latest tag at depth $depth..."
git fetch --depth=$depth
latestTag=`git describe --tags --abbrev=0 || echo NOT_FOUND`
done
echo $latestTag;
}
function publishRepo {
COMPONENT=$1
ARTIFACTS_DIR=$2
@ -92,7 +116,7 @@ function publishPackages {
COMMIT_MSG=`git log --oneline | head -n1`
COMMITTER_USER_NAME=`git --no-pager show -s --format='%cN' HEAD`
COMMITTER_USER_EMAIL=`git --no-pager show -s --format='%cE' HEAD`
LATEST_TAG=`git describe --tags --abbrev=0`
LATEST_TAG=`getLatestTag`
publishRepo "${COMPONENT}" "${JS_BUILD_ARTIFACTS_DIR}"
done