1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-01 01:04:00 +00:00
starship/install/macos_packages/common.sh
Kevin Song 001253cebe
ci: Fix how version is obtained for pkgbuild (#5443)
* fix: Change how starship version is determined

* Add STARSHIP_VERSION envar into CI for notarization

* More strict!

* Supress pushd/popd output

* Fix shellcheck issue with quoting
2023-10-01 08:59:34 +02:00

31 lines
1.1 KiB
Bash

#!/bin/bash
error() {
echo "[ERROR]: $1"
exit 1
}
starship_version() {
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
# 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]+'
else
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
fi
}