summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2017-09-07 18:39:06 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-09-14 19:11:19 +0000
commit580edf092563ba07ab46686b22636e67a37225fc (patch)
tree4b2320a18865970a54f6194eda542c83c7a7c89e
parent4fe3fba866dd4456ce26e56873bb81c20bd55765 (diff)
downloadchrome-ec-580edf092563ba07ab46686b22636e67a37225fc.tar.gz
utils: a script to help creating EC git tags
The script tries to determine the upstream branch name, and finds out which is the first sha1 of the current branch. Then the script tags the branch and generates a git command strings the operator is supposed to check for sanity and enter to push the new tag to the server. With the new tag set each following run of ./util/getversion.sh would generate version strings including the new tag name and number of patches above the branch point. More implementation details are included in the comments in the script. BRANCH=cr50 BUG=b:64698702 TEST=tried the script in cr50 and gru firmware branches: cr50$ <path to>/tagbranch.sh A new tag 'v1.9308_B.0' has been set. Use the following command to push it to the server git push --tags https://chromium.googlesource.com/chromiumos/platform/ec v1.9308_B.0 Or if you want to delete it: git tag -d v1.9308_B.0 cr50$ ./util/getversion.sh | grep -w VERSION #define VERSION "_v1.9308_B.192-b5c9d0aa7" cr50$ cr50$ cd <path/to>gru gru$ <path to>/tagbranch.sh A new tag 'v1.8785_B.0' has been set. Use the following command to push it to the server git push --tags https://chromium.googlesource.com/chromiumos/platform/ec v1.8785_B.0 Or if you want to delete it: git tag -d v1.8785_B.0 es^o: ~/new_projects/gru-8785/src/platform/ec 175 > ./util/getversion.sh | grep -w VERSION gru$ #define VERSION "_v1.8785_B.218-5d857ed8c" gru$ Change-Id: I0c0067f6b7bb837a0c119bc14ff48cb9223a3fa5 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/656575 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> (cherry picked from commit a26ddda387929fbf078bda96fd3c5643135d283a) Reviewed-on: https://chromium-review.googlesource.com/667858
-rwxr-xr-xutil/tagbranch.sh83
1 files changed, 83 insertions, 0 deletions
diff --git a/util/tagbranch.sh b/util/tagbranch.sh
new file mode 100755
index 0000000000..bcc71a4806
--- /dev/null
+++ b/util/tagbranch.sh
@@ -0,0 +1,83 @@
+#!/bin/bash
+#
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Generate git strings for tagging EC branches.
+#
+# This script builds up on ideas put by vpalatin@ into util/getversion.sh
+#
+# Git allows to count number of patches between the current state of the tree
+# and any directly preceding tag in the tree. That is if we tag the first
+# patch in the current branch, we can tell how many patches are in the branch
+# above that tag. And if we tag the branch such that the tag string includes
+# the branch name, we can also say what branch we are in looking at the
+# closest tag in the tree.
+#
+# This admittedly brittle script automates the process of tagging for the EC
+# git tree in Chrome OS repo, but it could be used for any other Chrome OS
+# repo git tree just as well.
+#
+# The script is brittle because it relies on the following assumptions which
+# are true for Chrome OS repo at the time of writing:
+#
+# - the upstream branch alias name shows up in the 'git branch -a' output
+# separated by ->
+# - the upstream branch alias name has the format of
+# cros/<branch name>
+# - the remote git server name shows up in 'git config -l' output in the
+# line starting with "remote.cros.url="
+# - firmware branch names have format of firmware-<board>-XXXXXX
+# - the current branch was cut off of <remote name>/master
+#
+# The tag name generated by this script would be the XXXXX string with dots,
+# if any, replaced by underscores.
+
+# Retrieve the upstream branch alias name
+UPSTREAM="$(git branch -a | awk '/->/ {print $3}')"
+if [[ -z "${UPSTREAM}" ]]; then
+ echo "Failed to determine upstream branch alias" >&2
+ exit 1
+fi
+
+export ORIGIN_NAME="cros"
+ORIGIN="$(git config "remote.${ORIGIN_NAME}.url")"
+
+# The last common patch between this branch and the master.
+BRANCH_POINT="$(git merge-base "${UPSTREAM}" "${ORIGIN_NAME}/master")"
+if [[ -z "${BRANCH_POINT}" ]]; then
+ echo "Failed to determine cros/master branch point" >&2
+ exit 1
+fi
+
+# Derive tag base string from the upstream branch name as described above.
+TAG_BASE="$(sed 's/.*-// # drop everything up to including the last -
+ s/\./_/g # replace dots and dashes with underscores
+ ' <<< "${UPSTREAM}" )"
+
+if [[ "${TAG_BASE}" == "master" ]]; then
+ echo "Nothing to tag in master branch" >&2
+ exit 1
+fi
+
+TAG="v1.${TAG_BASE}.0"
+
+#SHA1 of the first patch of this branch
+BASE_SHA="$(git rev-list --ancestry-path "${BRANCH_POINT}".."${UPSTREAM}" |
+ tail -1)"
+
+if git tag -a -m 'firmware branch ${TAG}' "${TAG}" "${BASE_SHA}"; then
+ cat <<EOF
+
+A new tag '$TAG' has been set. Use the following command
+to push it to the server
+
+git push --tags ${ORIGIN} ${TAG}
+
+Or if you want to delete it:
+
+git tag -d $TAG
+
+EOF
+fi