Updated get-changed-paths.sh

This commit is contained in:
Tonye Jack 2022-11-23 18:59:55 -07:00
parent bf3ca40593
commit 6093777a38

View File

@ -25,16 +25,19 @@ if [[ -n $INPUT_DIFF_RELATIVE ]]; then
fi
function get_dirname_max_depth() {
local dir="$1"
local depth=0
local dir=""
local dirs=()
while IFS='' read -r line; do
dir="$line"
IFS='/' read -ra dirs <<<"$dir"
local max_depth=${#dirs[@]}
INPUT_DIR_NAMES_MAX_DEPTH="${INPUT_DIR_NAMES_MAX_DEPTH:-$max_depth}"
local input_dir_names_max_depth="${INPUT_DIR_NAMES_MAX_DEPTH:-$max_depth}"
if [[ -n "$INPUT_DIR_NAMES_MAX_DEPTH" && "$INPUT_DIR_NAMES_MAX_DEPTH" -lt "$max_depth" ]]; then
max_depth="$INPUT_DIR_NAMES_MAX_DEPTH"
if [[ -n "$input_dir_names_max_depth" && "$input_dir_names_max_depth" -lt "$max_depth" ]]; then
max_depth="$input_dir_names_max_depth"
fi
local output=${dirs[1]}
@ -50,6 +53,7 @@ function get_dirname_max_depth() {
done
echo "$output"
done < <(uniq)
}
function get_diff() {
@ -81,7 +85,7 @@ function get_diff() {
done < <(git submodule | awk '{print $2}')
if [[ "$INPUT_DIR_NAMES" == "true" ]]; then
git diff --diff-filter="$filter" --name-only --ignore-submodules=all "$base$DIFF$sha" | xargs -I {} dirname {} | uniq | xargs get_dirname_max_depth | uniq && exit_status=$? || exit_status=$?
git diff --diff-filter="$filter" --name-only --ignore-submodules=all "$base$DIFF$sha" | xargs -I {} dirname {} | get_dirname_max_depth | uniq && exit_status=$? || exit_status=$?
if [[ $exit_status -ne 0 ]]; then
echo "::error::Failed to get changed directories between: $base$DIFF$sha"
@ -125,7 +129,7 @@ function get_renames() {
done < <(git submodule | awk '{print $2}')
if [[ "$INPUT_DIR_NAMES" == "true" ]]; then
git log --name-status --ignore-submodules=all "$base" "$sha" | { grep -E "^R" || true; } | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' | xargs -I {} dirname {} | uniq | xargs get_dirname_max_depth | uniq && exit_status=$? || exit_status=$?
git log --name-status --ignore-submodules=all "$base" "$sha" | { grep -E "^R" || true; } | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' | xargs -I {} dirname {} | get_dirname_max_depth | uniq && exit_status=$? || exit_status=$?
if [[ $exit_status -ne 0 ]]; then
echo "::error::Failed to get renamed directories between: $base$sha"