update-status-go: don't accept SHA1s, accept PR numbers
There was some confusion when given ref/tag did not exist. Script would just use the value as commit SHA1 even if it was not one. Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
27a001b0f0
commit
f9c15be1d4
|
@ -1,50 +1,71 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
if [[ -z "${IN_NIX_SHELL}" ]]; then
|
if [[ ! -x "$(command -v nix-prefetch-url)" ]] && [[ -z "${IN_NIX_SHELL}" ]]; then
|
||||||
echo "Remember to call 'make shell'!"
|
echo "Remember to call 'make shell'!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -eof pipefail
|
set -eof pipefail
|
||||||
|
|
||||||
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
|
GIT_ROOT="$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)"
|
||||||
|
VERSION_FILE="${GIT_ROOT}/status-go-version.json"
|
||||||
|
SCRIPT_FILE="$(basename "$0")"
|
||||||
|
|
||||||
usage() {
|
STATUS_GO_REPO="${STATUS_GO_REPO:=status-go}"
|
||||||
printf "%s is a tool for upgrading status-go to a given version.\n" "$(basename "$0")"
|
STATUS_GO_OWNER="${STATUS_GO_OWNER:=status-im}"
|
||||||
printf "Usage:\n\n"
|
REPO_URL="https://github.com/${STATUS_GO_OWNER}/${STATUS_GO_REPO}"
|
||||||
printf " %s version\n\n" "$(basename "$0")"
|
STATUS_GO_VERSION=$1
|
||||||
printf "Example:\n\n"
|
|
||||||
printf " %s develop-g12345678\n" "$(basename "$0")"
|
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.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
${SCRIPT_FILE} {version}
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
# Using branch name
|
||||||
|
${SCRIPT_FILE} feature-abc-xyz
|
||||||
|
|
||||||
|
# Using tag name
|
||||||
|
${SCRIPT_FILE} v2.1.1
|
||||||
|
|
||||||
|
# Using PR number
|
||||||
|
${SCRIPT_FILE} PR-2134
|
||||||
|
END
|
||||||
|
)
|
||||||
|
|
||||||
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||||
usage
|
echo "${HELP_MESSAGE}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
echo "Need to provide a status-go version"
|
echo "Need to provide a status-go version!"
|
||||||
|
echo
|
||||||
|
echo "${HELP_MESSAGE}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
STATUS_GO_REPO="${STATUS_GO_REPO:=status-go}"
|
# If prefixed with # we assume argument is a PR number
|
||||||
STATUS_GO_OWNER="${STATUS_GO_OWNER:=status-im}"
|
if [[ "${STATUS_GO_VERSION}" = PR-* ]]; then
|
||||||
STATUS_GO_VERSION=$1
|
STATUS_GO_VERSION="refs/pull/${STATUS_GO_VERSION#"PR-"}/head"
|
||||||
|
|
||||||
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
|
fi
|
||||||
|
|
||||||
STATUS_GO_SHA256=$(nix-prefetch-url --unpack ${repoUrl}/archive/${STATUS_GO_VERSION}.zip)
|
# 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)
|
||||||
|
|
||||||
cat << EOF > ${GIT_ROOT}/status-go-version.json
|
if [[ -z "${STATUS_GO_COMMIT_SHA1}" ]]; then
|
||||||
|
echo "ERROR: Failed to find a SHA1 for rev '${STATUS_GO_VERSION}'."
|
||||||
|
echo "NOTE: To set SHA1 you can just edit ${VERSION_FILE} by hand."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
STATUS_GO_SHA256=$(nix-prefetch-url --unpack ${REPO_URL}/archive/${STATUS_GO_VERSION}.zip)
|
||||||
|
|
||||||
|
cat << EOF > ${VERSION_FILE}
|
||||||
{
|
{
|
||||||
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
|
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
|
||||||
"owner": "${STATUS_GO_OWNER}",
|
"owner": "${STATUS_GO_OWNER}",
|
||||||
|
|
Loading…
Reference in New Issue