Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -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:
Expand Down
26 changes: 25 additions & 1 deletion scripts/publish/publish-build-artifacts.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down