2022-02-27 22:58:28 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-03-08 16:42:00 +01:00
|
|
|
error() {
|
|
|
|
echo "[ERROR]: $1"
|
|
|
|
exit 1
|
2022-02-27 22:58:28 +01:00
|
|
|
}
|
|
|
|
|
2023-03-08 16:42:00 +01:00
|
|
|
starship_version() {
|
2022-02-27 22:58:28 +01:00
|
|
|
starship_program_file="$1"
|
|
|
|
# Check if this is a relative path: if so, prepend './' to it
|
|
|
|
if [ "$1" = "${1#/}" ]; then
|
|
|
|
starship_program_file="./$starship_program_file"
|
|
|
|
fi
|
2023-10-01 08:59:34 +02:00
|
|
|
|
|
|
|
# Try to get the version from three sources in the following order:
|
|
|
|
# - the STARSHIP_VERSION envar (usually set by the CI)
|
|
|
|
# - Running the binary file
|
|
|
|
# - By cutting out the first version tag in Cargo.toml
|
|
|
|
# These get increasingly fragile as we go down the list---ideally CI should
|
|
|
|
# always run with STARSHIP_VERSION set to avoid issues in determining version.
|
|
|
|
if [ "$STARSHIP_VERSION" != "" ]; then
|
|
|
|
echo "$STARSHIP_VERSION" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+'
|
|
|
|
elif "$starship_program_file" -V >/dev/null 2>&1; then
|
|
|
|
"$starship_program_file" -V 2> /dev/null | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+'
|
2022-02-27 22:58:28 +01:00
|
|
|
else
|
2023-10-01 08:59:34 +02:00
|
|
|
pushd "$(git rev-parse --show-toplevel)" &> /dev/null || true
|
|
|
|
grep '^version = \"\(.*\)\"' Cargo.toml | head -n 1 | cut -f 2 -d '"' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+'
|
|
|
|
popd &> /dev/null || true
|
2022-02-27 22:58:28 +01:00
|
|
|
fi
|
|
|
|
}
|