Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions .buildkite/scripts/steps/check_types_commits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=()
Expand All @@ -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 [<ref1> [<ref2>]]"
echo
echo "Options:"
echo " --help, -h Show this help"
Expand All @@ -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")
Expand Down