status-react/scripts/update-status-go.sh

61 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
if [[ -z "${IN_NIX_SHELL}" ]]; then
echo "Remember to call 'make shell'!"
exit 1
fi
set -eof pipefail
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
usage() {
printf "%s is a tool for upgrading status-go to a given version.\n" "$(basename "$0")"
printf "Usage:\n\n"
printf " %s version\n\n" "$(basename "$0")"
printf "Example:\n\n"
printf " %s develop-g12345678\n" "$(basename "$0")"
}
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
exit 1
fi
if [ $# -eq 0 ]; then
echo "Need to provide a status-go version"
exit 1
fi
STATUS_GO_REPO="${STATUS_GO_REPO:=status-go}"
STATUS_GO_OWNER="${STATUS_GO_OWNER:=status-im}"
STATUS_GO_VERSION=$1
repoUrl="https://github.com/${STATUS_GO_OWNER}/${STATUS_GO_REPO}"
STATUS_GO_COMMIT_SHA1=$(git ls-remote ${repoUrl} U ${STATUS_GO_VERSION} | cut -f1)
if [[ -z "${STATUS_GO_COMMIT_SHA1}" ]]; then
echo "Could not find SHA1 for rev ${STATUS_GO_VERSION}, assuming it's a commit."
echo "WARNING: Setting 'version' value to 'develop'"
STATUS_GO_COMMIT_SHA1="${STATUS_GO_VERSION}"
STATUS_GO_VERSION="develop" # to reduce metrics cardinality in Prometheus
fi
STATUS_GO_SHA256=$(nix-prefetch-url --unpack ${repoUrl}/archive/${STATUS_GO_VERSION}.zip)
cat << EOF > ${GIT_ROOT}/status-go-version.json
{
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "${STATUS_GO_OWNER}",
"repo": "${STATUS_GO_REPO}",
"version": "${STATUS_GO_VERSION}",
"commit-sha1": "${STATUS_GO_COMMIT_SHA1}",
"src-sha256": "${STATUS_GO_SHA256}"
}
EOF
echo "SHA-1 for ${STATUS_GO_VERSION} is ${STATUS_GO_COMMIT_SHA1}.
SHA-256 for source archive is ${STATUS_GO_SHA256}
Owner is ${STATUS_GO_OWNER}"