From b64946b5f991a1d219fc4c5918baa079517acd8d Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Wed, 1 Feb 2017 21:51:12 +0200 Subject: [PATCH] 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 --- .travis.yml | 4 ---- scripts/publish/publish-build-artifacts.sh | 26 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e149edc4cf..d2c97d5644 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/scripts/publish/publish-build-artifacts.sh b/scripts/publish/publish-build-artifacts.sh index 55d58d71f2..cc6913785a 100755 --- a/scripts/publish/publish-build-artifacts.sh +++ b/scripts/publish/publish-build-artifacts.sh @@ -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