chore: fix RUNNER_ROOT_DIR detection on MacOS

This commit is contained in:
Ivan Dyachkov 2022-12-19 13:07:18 +01:00
parent bfe2b67fbe
commit e8073f9e7d
1 changed files with 10 additions and 3 deletions

View File

@ -13,10 +13,17 @@ DEBUG="${DEBUG:-0}"
# so we can't use it universally.
# - `stat -f%R` on MacOS does exactly what `readlink -f` does on Linux, but we can't use it
# as a universal solution either because GNU stat has different syntax and this argument is invalid.
# Also, version of stat which supports this syntax is only available since MacOS 12
if [ "$(uname -s)" == 'Darwin' ]; then
# if homebrew coreutils package is installed, GNU version of stat can take precedence,
# so we use absolute path to ensure we are calling MacOS default
RUNNER_ROOT_DIR="$(cd "$(dirname "$(/usr/bin/stat -f%R "$0" || echo "$0")")"/..; pwd -P)"
product_version="$(sw_vers -productVersion | cut -d '.' -f 1)"
if [ "$product_version" -ge 12 ]; then
# if homebrew coreutils package is installed, GNU version of stat can take precedence,
# so we use absolute path to ensure we are calling MacOS default
RUNNER_ROOT_DIR="$(cd "$(dirname "$(/usr/bin/stat -f%R "$0" || echo "$0")")"/..; pwd -P)"
else
# try our best to resolve link on MacOS <= 11
RUNNER_ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
fi
else
RUNNER_ROOT_DIR="$(cd "$(dirname "$(realpath "$0" || echo "$0")")"/..; pwd -P)"
fi