2018-05-07 09:22:14 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-09-14 20:16:42 +00:00
|
|
|
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
|
2023-06-24 13:53:12 +00:00
|
|
|
source "${GIT_ROOT}/scripts/colors.sh"
|
2021-09-14 20:16:42 +00:00
|
|
|
source "${GIT_ROOT}/nix/scripts/source.sh"
|
|
|
|
|
2020-10-08 12:28:17 +00:00
|
|
|
set -ef
|
2018-05-07 09:22:14 +00:00
|
|
|
|
2021-09-14 20:16:42 +00:00
|
|
|
# urlencode <string>
|
2020-12-31 10:50:26 +00:00
|
|
|
urlencode() {
|
2021-09-14 20:16:42 +00:00
|
|
|
old_lc_collate=$LC_COLLATE
|
|
|
|
LC_COLLATE=C
|
|
|
|
local length="${#1}"
|
|
|
|
for (( i = 0; i < length; i++ )); do
|
|
|
|
local c="${1:$i:1}"
|
|
|
|
case $c in
|
|
|
|
[a-zA-Z0-9.~_-]) printf '%s' "$c";;
|
|
|
|
*) printf '%%%02X' "'$c";;
|
2020-12-31 10:50:26 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
LC_COLLATE=$old_lc_collate
|
|
|
|
}
|
|
|
|
|
2023-06-24 13:53:12 +00:00
|
|
|
identify_git_sha() {
|
|
|
|
# Do not fail on grep for refs
|
|
|
|
set +o pipefail
|
|
|
|
|
|
|
|
# ls-remote finds only tags, branches, and pull requests, but can't find commits
|
|
|
|
STATUS_GO_MATCHING_REFS=$(git ls-remote ${REPO_URL} ${1})
|
|
|
|
|
|
|
|
# It's possible that there's both a branch and a tag matching the given version
|
2024-09-19 11:19:35 +00:00
|
|
|
STATUS_GO_TAG_SHA1=$(echo "${STATUS_GO_MATCHING_REFS}" | grep "refs/tags/${1}" | cut -f1)
|
2023-06-24 13:53:12 +00:00
|
|
|
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
|
|
|
|
echo -n "${STATUS_GO_TAG_SHA1}"
|
|
|
|
elif [[ -n "${STATUS_GO_BRANCH_SHA1}" ]]; then
|
|
|
|
echo -n "${STATUS_GO_BRANCH_SHA1}"
|
|
|
|
elif [[ "${#STATUS_GO_VERSION}" -gt 4 ]]; then
|
|
|
|
echo -n "${1}"
|
|
|
|
else
|
|
|
|
echo -e "${RED}${BLD}ERROR:${RST} Input not a tag or branch, but too short to be a SHA1!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2020-02-05 11:02:27 +00:00
|
|
|
|
|
|
|
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.
|
2020-10-01 12:40:30 +00:00
|
|
|
If the given name matches both a branch and a tag the tag is used.
|
2020-02-05 11:02:27 +00:00
|
|
|
|
|
|
|
Usage:
|
|
|
|
${SCRIPT_FILE} {version}
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
# Using branch name
|
|
|
|
${SCRIPT_FILE} feature-abc-xyz
|
|
|
|
|
|
|
|
# Using tag name
|
|
|
|
${SCRIPT_FILE} v2.1.1
|
|
|
|
|
2022-03-28 15:17:16 +00:00
|
|
|
# Using commit SHA1
|
|
|
|
${SCRIPT_FILE} 1a2b3c4d
|
|
|
|
|
2020-02-05 11:02:27 +00:00
|
|
|
# Using PR number
|
|
|
|
${SCRIPT_FILE} PR-2134
|
|
|
|
END
|
|
|
|
)
|
2018-05-08 07:58:04 +00:00
|
|
|
|
2023-06-24 13:53:12 +00:00
|
|
|
if [[ ! -x "$(command -v nix-prefetch-url)" ]]; then
|
|
|
|
echo "No 'nix-prefetch-url' utility found!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-05-08 07:58:04 +00:00
|
|
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
2020-02-05 11:02:27 +00:00
|
|
|
echo "${HELP_MESSAGE}"
|
2018-05-08 07:58:04 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
2020-02-05 11:02:27 +00:00
|
|
|
echo "Need to provide a status-go version!"
|
|
|
|
echo
|
|
|
|
echo "${HELP_MESSAGE}"
|
2018-05-07 09:22:14 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-06-24 13:53:12 +00:00
|
|
|
VERSION_FILE="${GIT_ROOT}/status-go-version.json"
|
|
|
|
SCRIPT_FILE="$(basename "$0")"
|
|
|
|
|
|
|
|
STATUS_GO_REPO="${STATUS_GO_REPO:=status-go}"
|
|
|
|
STATUS_GO_OWNER="${STATUS_GO_OWNER:=status-im}"
|
|
|
|
REPO_URL="https://github.com/${STATUS_GO_OWNER}/${STATUS_GO_REPO}"
|
|
|
|
STATUS_GO_VERSION=$1
|
|
|
|
|
2020-02-05 11:02:27 +00:00
|
|
|
# If prefixed with # we assume argument is a PR number
|
|
|
|
if [[ "${STATUS_GO_VERSION}" = PR-* ]]; then
|
|
|
|
STATUS_GO_VERSION="refs/pull/${STATUS_GO_VERSION#"PR-"}/head"
|
|
|
|
fi
|
2019-07-22 03:31:47 +00:00
|
|
|
|
2023-06-24 13:53:12 +00:00
|
|
|
STATUS_GO_COMMIT_SHA1="$(identify_git_sha "${STATUS_GO_VERSION}")"
|
|
|
|
STATUS_GO_COMMIT_URL="https://github.com/${STATUS_GO_OWNER}/${STATUS_GO_REPO}/commit/${STATUS_GO_COMMIT_SHA1}"
|
|
|
|
STATUS_GO_ZIP_URL="${REPO_URL}/archive/$(urlencode ${STATUS_GO_VERSION}).zip"
|
|
|
|
STATUS_GO_SHA256=$(nix-prefetch-url --unpack ${STATUS_GO_ZIP_URL} --name status-go-archive.zip)
|
2019-07-22 03:31:47 +00:00
|
|
|
|
2020-02-05 11:02:27 +00:00
|
|
|
cat << EOF > ${VERSION_FILE}
|
2019-07-19 18:42:16 +00:00
|
|
|
{
|
2021-09-14 20:16:42 +00:00
|
|
|
"_comment": "THIS SHOULD NOT BE EDITED BY HAND.",
|
|
|
|
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
2019-07-19 18:42:16 +00:00
|
|
|
"owner": "${STATUS_GO_OWNER}",
|
2019-07-22 03:31:47 +00:00
|
|
|
"repo": "${STATUS_GO_REPO}",
|
2019-07-19 18:42:16 +00:00
|
|
|
"version": "${STATUS_GO_VERSION}",
|
|
|
|
"commit-sha1": "${STATUS_GO_COMMIT_SHA1}",
|
|
|
|
"src-sha256": "${STATUS_GO_SHA256}"
|
|
|
|
}
|
2019-05-02 11:29:10 +00:00
|
|
|
EOF
|
|
|
|
|
2023-06-24 13:53:12 +00:00
|
|
|
echo -e "${GRN}URL${RST}: ${BLD}${STATUS_GO_COMMIT_URL}${RST}"
|
|
|
|
echo -e "${GRN}SHA-1${RST}: ${BLD}${STATUS_GO_COMMIT_SHA1}${RST}"
|
|
|
|
echo -e "${GRN}SHA-256${RST}: ${BLD}${STATUS_GO_SHA256}${RST}"
|