From bc12c90d2e9c3d60f640baebe9cb959d79605082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 1 Oct 2020 14:40:30 +0200 Subject: [PATCH] update-status-go: fix case where two matching refs exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before it was possible to break the format of `status-go-version.json`: ``` > git ls-remote https://github.com/status-im/status-go v0.62.3.hotfix.3 59e6602405bfbcf8446d26aca9b8087e84529f8e refs/heads/release/v0.62.3.hotfix.3 59e6602405bfbcf8446d26aca9b8087e84529f8e refs/tags/v0.62.3.hotfix.3 ``` Which would result in `commit-sha1` key being set to two commits insted of one. Signed-off-by: Jakub SokoĊ‚owski --- scripts/update-status-go.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/update-status-go.sh b/scripts/update-status-go.sh index 99294d15d7..b2191363c7 100755 --- a/scripts/update-status-go.sh +++ b/scripts/update-status-go.sh @@ -20,6 +20,7 @@ HELP_MESSAGE=$(cat <<-END This is a tool for upgrading status-go to a given version in: ${VERSION_FILE} Which is then used by Nix derivations to build status-go for the app. +If the given name matches both a branch and a tag the tag is used. Usage: ${SCRIPT_FILE} {version} @@ -55,7 +56,18 @@ if [[ "${STATUS_GO_VERSION}" = PR-* ]]; then fi # ls-remote finds only tags, branches, and pull requests, but can't find commits -STATUS_GO_COMMIT_SHA1=$(git ls-remote ${REPO_URL} ${STATUS_GO_VERSION} | cut -f1) +STATUS_GO_MATCHING_REFS=$(git ls-remote ${REPO_URL} ${STATUS_GO_VERSION}) + +# It's possible that there's both a branch and a tag matching the given version +STATUS_GO_TAG_SHA1=$(echo "${STATUS_GO_MATCHING_REFS}" | grep 'refs/tags' | cut -f1) +STATUS_GO_BRANCH_SHA1=$(echo "${STATUS_GO_MATCHING_REFS}" | grep 'refs/heads' | cut -f1) + +# Prefer tag over branch if both are found +if [[ -n "${STATUS_GO_TAG_SHA1}" ]]; then + STATUS_GO_COMMIT_SHA1="${STATUS_GO_TAG_SHA1}" +else + STATUS_GO_COMMIT_SHA1="${STATUS_GO_BRANCH_SHA1}" +fi if [[ -z "${STATUS_GO_COMMIT_SHA1}" ]]; then echo "ERROR: Failed to find a SHA1 for rev '${STATUS_GO_VERSION}'."