diff --git a/.buildkite/scripts/steps/check_types_commits.sh b/.buildkite/scripts/steps/check_types_commits.sh index 2d53e9e245929..973e4ce6fbb60 100755 --- a/.buildkite/scripts/steps/check_types_commits.sh +++ b/.buildkite/scripts/steps/check_types_commits.sh @@ -2,6 +2,10 @@ set -euo pipefail +# This script detects the files changed in a given set of commits, finds the related tsconfig.json files, and scope the TypeScript type check to those. +# In CI, this script can be used for selective type-checking on projects that might be affected for a given PR. +# (The accuracy for finding related projects is not a 100%) + argv=( "$@" ) diffArgs=("--name-only") uniq_dirs=() @@ -16,13 +20,34 @@ is_flag_set () { fi } +get_args_for_flag_result=() +get_args_for_flag () { + flag=$1 + found=false + get_args_for_flag_result=() + if [ ${#argv[@]} -gt 0 ]; then + for i in "${!argv[@]}"; do + arg="${argv[$i]}" + if [ "$found" == false ] && [[ "$arg" == "$flag" ]]; then + found=true + elif [ "$found" == true ]; then + if [[ "$arg" == -* ]]; then + return + else + get_args_for_flag_result+=("$arg") + fi + fi + done + fi +} + if is_flag_set "--help" || is_flag_set "-h"; then echo "Detects the files changed in a given set of commits, finds the related" echo "tsconfig.json files, and scope the TypeScript type check to those." echo echo "Usage:" echo " $0 [options]" - echo " $0 [ref1 [ref2]]" + echo " $0 [ []]" echo echo "Options:" echo " --help, -h Show this help" @@ -49,7 +74,8 @@ if [[ "${CI-}" == "true" ]]; then diffArgs+=("$sha" "${GITHUB_PR_TRIGGERED_SHA-}") elif is_flag_set "--merge-base"; then # Similar to when CI=true, but locally - diffArgs+=("--merge-base" "${2-main}" "${3-HEAD}") + get_args_for_flag "--merge-base" + diffArgs+=("--merge-base" "${get_args_for_flag_result[0]-main}" "${get_args_for_flag_result[1]-HEAD}") elif is_flag_set "--cached"; then # Only check staged files diffArgs+=("--cached")