Skip to content

Commit

Permalink
fixed output
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Oct 21, 2021
1 parent b2e2817 commit b36bc2c
Showing 1 changed file with 74 additions and 64 deletions.
138 changes: 74 additions & 64 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ echo "Retrieving changes between $PREVIOUS_SHA ($TARGET_BRANCH) → $CURRENT_SHA

if [[ -z "${INPUT_FILES[*]}" ]]; then
echo "Getting diff..."
ADDED=$(IFS=$INPUT_SEPARATOR eval 'git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA"')
COPIED=$(IFS=$INPUT_SEPARATOR eval 'git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA"')
DELETED=$(IFS=$INPUT_SEPARATOR eval 'git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA"')
MODIFIED=$(IFS=$INPUT_SEPARATOR eval 'git diff --diff-filter=M --name-only "$PREVIOUS_SHA" "$CURRENT_SHA"')
RENAMED=$(IFS=$INPUT_SEPARATOR eval 'git diff --diff-filter=R --name-only "$PREVIOUS_SHA" "$CURRENT_SHA"')
TYPE_CHANGED=$(IFS=$INPUT_SEPARATOR eval 'git diff --diff-filter=T --name-only "$PREVIOUS_SHA" "$CURRENT_SHA"')
UNMERGED=$(IFS=$INPUT_SEPARATOR eval 'git diff --diff-filter=U --name-only "$PREVIOUS_SHA" "$CURRENT_SHA"')
UNKNOWN=$(IFS=$INPUT_SEPARATOR eval 'git diff --diff-filter=X --name-only "$PREVIOUS_SHA" "$CURRENT_SHA"')
ALL_CHANGED_AND_MODIFIED=$(IFS=$INPUT_SEPARATOR eval 'git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA"')
ALL_MODIFIED_FILES=$(IFS=$INPUT_SEPARATOR eval 'git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA"')
IFS=" " read -r -a ADDED_ARRAY <<< "$(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")"
IFS=" " read -r -a COPIED_ARRAY <<< "$(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")"
IFS=" " read -r -a DELETED_ARRAY <<< "$(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")"
IFS=" " read -r -a MODIFIED_ARRAY <<< "$(git diff --diff-filter=M --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")"
IFS=" " read -r -a RENAMED_ARRAY <<< "$(git diff --diff-filter=R --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")"
IFS=" " read -r -a TYPE_CHANGED_ARRAY <<< "$(git diff --diff-filter=T --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")"
IFS=" " read -r -a UNMERGED_ARRAY <<< "$(git diff --diff-filter=U --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")"
IFS=" " read -r -a UNKNOWN_ARRAY <<< "$(git diff --diff-filter=X --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")"
IFS=" " read -r -a ALL_CHANGED_AND_MODIFIED_ARRAY <<< "$(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")"
IFS=" " read -r -a ALL_MODIFIED_ARRAY <<< "$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")"
else
ADDED_ARRAY=()
COPIED_ARRAY=()
Expand All @@ -85,90 +85,100 @@ else
TYPE_CHANGED_ARRAY=()
UNMERGED_ARRAY=()
UNKNOWN_ARRAY=()
ALL_CHANGED_ARRAY=()
ALL_MODIFIED_FILES_ARRAY=()
ALL_CHANGED_AND_MODIFIED_ARRAY=()
ALL_MODIFIED_ARRAY=()

echo "Input files: ${INPUT_FILES[*]}"

for path in ${INPUT_FILES}
do
echo "Checking for file changes: \"${path}\"..."
# shellcheck disable=SC2207
ADDED_ARRAY+=($(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
# shellcheck disable=SC2207
COPIED_ARRAY+=($(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
# shellcheck disable=SC2207
DELETED_ARRAY+=($(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
# shellcheck disable=SC2207
MODIFIED_ARRAY+=($(git diff --diff-filter=M --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
# shellcheck disable=SC2207
RENAMED_ARRAY+=($(git diff --diff-filter=R --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
# shellcheck disable=SC2207
TYPE_CHANGED_ARRAY+=($(git diff --diff-filter=T --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
# shellcheck disable=SC2207
UNMERGED_ARRAY+=($(git diff --diff-filter=U --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
# shellcheck disable=SC2207
UNKNOWN_ARRAY+=($(git diff --diff-filter=X --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
# shellcheck disable=SC2207
ALL_CHANGED_ARRAY+=($(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
# shellcheck disable=SC2207
ALL_MODIFIED_FILES_ARRAY+=($(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))

IFS=" " read -r -a ADDED_CURRENT_ARRAY <<< "$(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true)"
ADDED_ARRAY=("${ADDED_ARRAY[@]}" "${ADDED_CURRENT_ARRAY[@]}")

IFS=" " read -r -a COPIED_CURRENT_ARRAY <<< "$(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true)"
COPIED_ARRAY=("${COPIED_ARRAY[@]}" "${COPIED_CURRENT_ARRAY[@]}")

IFS=" " read -r -a DELETED_CURRENT_ARRAY <<< "$(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true)"
DELETED_ARRAY=("${DELETED_ARRAY[@]}" "${DELETED_CURRENT_ARRAY[@]}")

IFS=" " read -r -a MODIFIED_CURRENT_ARRAY <<< "$(git diff --diff-filter=M --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true)"
MODIFIED_ARRAY=("${MODIFIED_ARRAY[@]}" "${MODIFIED_CURRENT_ARRAY[@]}")

IFS=" " read -r -a RENAMED_CURRENT_ARRAY <<< "$(git diff --diff-filter=R --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true)"
RENAMED_ARRAY=("${RENAMED_ARRAY[@]}" "${RENAMED_CURRENT_ARRAY[@]}")

IFS=" " read -r -a TYPE_CHANGED_CURRENT_ARRAY <<< "$(git diff --diff-filter=T --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true)"
TYPE_CHANGED_ARRAY=("${TYPE_CHANGED_ARRAY[@]}" "${TYPE_CHANGED_CURRENT_ARRAY[@]}")

IFS=" " read -r -a UNMERGED_CURRENT_ARRAY <<< "$(git diff --diff-filter=U --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true)"
UNMERGED_ARRAY=("${UNMERGED_ARRAY[@]}" "${UNMERGED_CURRENT_ARRAY[@]}")

IFS=" " read -r -a UNKNOWN_CURRENT_ARRAY <<< "$(git diff --diff-filter=X --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true)"
UNKNOWN_ARRAY=("${UNKNOWN_ARRAY[@]}" "${UNKNOWN_CURRENT_ARRAY[@]}")

IFS=" " read -r -a ALL_CHANGED_AND_MODIFIED_CURRENT_ARRAY <<< "$(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true)"
ALL_CHANGED_AND_MODIFIED_ARRAY=("${ALL_CHANGED_AND_MODIFIED_ARRAY[@]}" "${ALL_CHANGED_AND_MODIFIED_CURRENT_ARRAY[@]}")

IFS=" " read -r -a ALL_MODIFIED_CURRENT_ARRAY <<< "$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true)"
ALL_MODIFIED_ARRAY=("${ALL_MODIFIED_ARRAY[@]}" "${ALL_MODIFIED_CURRENT_ARRAY[@]}")
done

ADDED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${ADDED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
COPIED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${COPIED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
DELETED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${DELETED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
MODIFIED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${MODIFIED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
RENAMED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${RENAMED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
TYPE_CHANGED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${TYPE_CHANGED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
UNMERGED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${UNMERGED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
UNKNOWN=$(IFS=$INPUT_SEPARATOR; eval 'echo "${UNKNOWN_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
ALL_CHANGED_AND_MODIFIED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${ALL_CHANGED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
ALL_MODIFIED_FILES=$(IFS=$INPUT_SEPARATOR; eval 'echo "${ALL_MODIFIED_FILES_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
ADDED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${ADDED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')
COPIED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${COPIED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')
DELETED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${DELETED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')
MODIFIED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${MODIFIED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')
RENAMED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${RENAMED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')
TYPE_CHANGED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${TYPE_CHANGED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')
UNMERGED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${UNMERGED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')
UNKNOWN=$(IFS=$INPUT_SEPARATOR; eval 'echo "${UNKNOWN_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')
ALL_CHANGED_AND_MODIFIED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${ALL_CHANGED_AND_MODIFIED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')
ALL_MODIFIED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${ALL_MODIFIED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')

ALL_OTHER_MODIFIED_FILES=$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
ALL_OTHER_MODIFIED=$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")

IFS=" " read -r -a UNIQUE_ALL_MODIFIED_FILES_ARRAY <<< "$(echo "${ALL_MODIFIED_FILES_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")"
IFS=" " read -r -a OTHER_MODIFIED_FILES_ARRAY <<< "$(echo "${ALL_OTHER_MODIFIED_FILES[@]}" "${UNIQUE_ALL_MODIFIED_FILES_ARRAY[@]}" | tr " " "\n" | sort | uniq -u | tr "\n" " ")"
IFS=" " read -r -a UNIQUE_ALL_MODIFIED_ARRAY <<< "$(echo "${ALL_MODIFIED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0)"
IFS=" " read -r -a OTHER_MODIFIED_ARRAY <<< "$(echo "${ALL_OTHER_MODIFIED[@]}" "${UNIQUE_ALL_MODIFIED_ARRAY[@]}" | tr " " "\n" | sort | uniq -u | xargs -0)"

OTHER_MODIFIED_FILES=$(IFS=$INPUT_SEPARATOR; eval 'echo "${OTHER_MODIFIED_FILES_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
OTHER_MODIFIED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${OTHER_MODIFIED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')

echo "Matching modified files: ${UNIQUE_ALL_MODIFIED_FILES_ARRAY[*]}"
echo "Matching modified files: ${UNIQUE_ALL_MODIFIED_ARRAY[*]}"

if [[ -n "${UNIQUE_ALL_MODIFIED_FILES_ARRAY[*]}" ]]; then
if [[ -n "${UNIQUE_ALL_MODIFIED_ARRAY[*]}" ]]; then
echo "::set-output name=any_changed::true"
else
echo "::set-output name=any_changed::false"
fi

if [[ -n "${OTHER_MODIFIED_FILES_ARRAY[*]}" ]]; then
echo "Non Matching modified files: ${OTHER_MODIFIED_FILES_ARRAY[*]}"
if [[ -n "${OTHER_MODIFIED_ARRAY[*]}" ]]; then
echo "Non Matching modified files: ${OTHER_MODIFIED_ARRAY[*]}"
echo "::set-output name=only_changed::false"
echo "::set-output name=other_changed_files::$OTHER_MODIFIED_FILES"
elif [[ -n "${UNIQUE_ALL_MODIFIED_FILES_ARRAY[*]}" ]]; then
echo "::set-output name=other_changed_files::$OTHER_MODIFIED"
elif [[ -n "${UNIQUE_ALL_MODIFIED_ARRAY[*]}" ]]; then
echo "::set-output name=only_changed::true"
fi

OTHER_DELETED_FILES=$(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
OTHER_DELETED=$(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")

IFS=" " read -r -a UNIQUE_DELETED_FILES_ARRAY <<< "$(echo "${DELETED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")"
IFS=" " read -r -a OTHER_DELETED_FILES_ARRAY <<< "$(echo "${OTHER_DELETED_FILES[@]}" "${UNIQUE_DELETED_FILES_ARRAY[@]}" | tr " " "\n" | sort | uniq -u | tr "\n" " ")"
IFS=" " read -r -a UNIQUE_DELETED_ARRAY <<< "$(echo "${DELETED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0)"
IFS=" " read -r -a OTHER_DELETED_ARRAY <<< "$(echo "${OTHER_DELETED[@]}" "${UNIQUE_DELETED_ARRAY[@]}" | tr " " "\n" | sort | uniq -u | xargs -0)"

OTHER_DELETED_FILES=$(IFS=$INPUT_SEPARATOR; eval 'echo "${OTHER_DELETED_FILES_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " "')
OTHER_DELETED=$(IFS=$INPUT_SEPARATOR; eval 'echo "${OTHER_DELETED_ARRAY[*]}" | tr " " "\n" | sort -u | xargs -0')

echo "Matching deleted files: ${UNIQUE_DELETED_FILES_ARRAY[*]}"
echo "Matching deleted files: ${UNIQUE_DELETED_ARRAY[*]}"

if [[ -n "${UNIQUE_DELETED_FILES_ARRAY[*]}" ]]; then
if [[ -n "${UNIQUE_DELETED_ARRAY[*]}" ]]; then
echo "::set-output name=any_deleted::true"
else
echo "::set-output name=any_deleted::false"
fi

if [[ -n "${OTHER_DELETED_FILES_ARRAY[*]}" ]]; then
echo "Non Matching deleted files: ${OTHER_DELETED_FILES_ARRAY[*]}"
if [[ -n "${OTHER_DELETED_ARRAY[*]}" ]]; then
echo "Non Matching deleted files: ${OTHER_DELETED_ARRAY[*]}"
echo "::set-output name=only_deleted::false"
echo "::set-output name=other_deleted_files::$OTHER_DELETED_FILES"
elif [[ -n "${UNIQUE_DELETED_FILES_ARRAY[*]}" ]]; then
echo "::set-output name=other_deleted_files::$OTHER_DELETED"
elif [[ -n "${UNIQUE_DELETED_ARRAY[*]}" ]]; then
echo "::set-output name=only_deleted::true"
fi
fi
Expand All @@ -182,7 +192,7 @@ echo "Type Changed files: $TYPE_CHANGED"
echo "Unmerged files: $UNMERGED"
echo "Unknown files: $UNKNOWN"
echo "All changed files: $ALL_CHANGED_AND_MODIFIED"
echo "All modified files: $ALL_MODIFIED_FILES"
echo "All modified files: $ALL_MODIFIED"

git remote remove temp_changed_files

Expand All @@ -195,6 +205,6 @@ echo "::set-output name=type_changed_files::$TYPE_CHANGED"
echo "::set-output name=unmerged_files::$UNMERGED"
echo "::set-output name=unknown_files::$UNKNOWN"
echo "::set-output name=all_changed_and_modified_files::$ALL_CHANGED_AND_MODIFIED"
echo "::set-output name=all_modified_files::$ALL_MODIFIED_FILES"
echo "::set-output name=all_modified_files::$ALL_MODIFIED"

echo "::endgroup::"

0 comments on commit b36bc2c

Please sign in to comment.