2021-05-21 12:39:56 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2021-06-26 14:20:56 +00:00
|
|
|
echo "::group::changed-files"
|
|
|
|
|
2021-08-28 01:53:03 +00:00
|
|
|
echo "Resolving repository path..."
|
|
|
|
|
|
|
|
if [[ -n $INPUT_PATH ]]; then
|
|
|
|
REPO_DIR="$GITHUB_WORKSPACE/$INPUT_PATH"
|
|
|
|
if [[ ! -d "$REPO_DIR" ]]; then
|
|
|
|
echo "::warning::Invalid repository path"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cd "$REPO_DIR"
|
|
|
|
fi
|
|
|
|
|
2021-08-18 00:03:07 +00:00
|
|
|
git remote add temp_changed_files "https://${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY}"
|
2021-05-21 12:39:56 +00:00
|
|
|
|
2021-06-09 21:52:54 +00:00
|
|
|
echo "Getting HEAD info..."
|
|
|
|
|
2021-07-14 20:57:17 +00:00
|
|
|
if [[ -z $INPUT_SHA ]]; then
|
2021-07-17 15:46:59 +00:00
|
|
|
CURRENT_SHA=$(git rev-parse HEAD 2>&1) && exit_status=$? || exit_status=$?
|
2021-06-09 21:52:54 +00:00
|
|
|
else
|
2021-07-17 15:46:59 +00:00
|
|
|
CURRENT_SHA=$INPUT_SHA
|
2021-06-09 21:52:54 +00:00
|
|
|
fi
|
2021-05-21 12:39:56 +00:00
|
|
|
|
2021-06-09 22:11:27 +00:00
|
|
|
if [[ $exit_status -ne 0 ]]; then
|
|
|
|
echo "::warning::Unable to determine the current head sha"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-05-21 12:39:56 +00:00
|
|
|
if [[ -z $GITHUB_BASE_REF ]]; then
|
2021-07-17 15:46:59 +00:00
|
|
|
if [[ -z $INPUT_BASE_SHA ]]; then
|
|
|
|
PREVIOUS_SHA=$(git rev-parse HEAD^1 2>&1) && exit_status=$? || exit_status=$?
|
|
|
|
else
|
|
|
|
PREVIOUS_SHA=$INPUT_BASE_SHA
|
|
|
|
fi
|
2021-06-25 18:58:59 +00:00
|
|
|
TARGET_BRANCH=${GITHUB_REF/refs\/heads\//}
|
|
|
|
CURRENT_BRANCH=$TARGET_BRANCH
|
2021-08-28 01:53:03 +00:00
|
|
|
|
2021-06-09 22:11:27 +00:00
|
|
|
if [[ $exit_status -ne 0 ]]; then
|
|
|
|
echo "::warning::Unable to determine the previous commit sha"
|
|
|
|
echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-05-21 12:39:56 +00:00
|
|
|
else
|
2021-07-17 15:46:59 +00:00
|
|
|
TARGET_BRANCH=$GITHUB_BASE_REF
|
2021-06-25 18:58:59 +00:00
|
|
|
CURRENT_BRANCH=$GITHUB_HEAD_REF
|
2021-08-18 00:03:07 +00:00
|
|
|
git fetch temp_changed_files "${TARGET_BRANCH}":"${TARGET_BRANCH}"
|
2021-07-17 15:46:59 +00:00
|
|
|
if [[ -z $INPUT_BASE_SHA ]]; then
|
|
|
|
PREVIOUS_SHA=$(git rev-parse "${TARGET_BRANCH}" 2>&1) && exit_status=$? || exit_status=$?
|
|
|
|
else
|
|
|
|
PREVIOUS_SHA=$INPUT_BASE_SHA
|
|
|
|
fi
|
2021-08-28 01:53:03 +00:00
|
|
|
|
2021-06-09 22:11:27 +00:00
|
|
|
if [[ $exit_status -ne 0 ]]; then
|
|
|
|
echo "::warning::Unable to determine the base ref sha for ${TARGET_BRANCH}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-05-21 12:39:56 +00:00
|
|
|
fi
|
|
|
|
|
2021-07-17 15:46:59 +00:00
|
|
|
echo "Retrieving changes between $PREVIOUS_SHA ($TARGET_BRANCH) → $CURRENT_SHA ($CURRENT_BRANCH)"
|
2021-05-25 04:30:19 +00:00
|
|
|
|
2021-09-04 13:08:20 +00:00
|
|
|
if [[ -z "${INPUT_FILES[*]}" ]]; then
|
2021-05-25 04:30:19 +00:00
|
|
|
echo "Getting diff..."
|
2021-09-04 13:08:20 +00:00
|
|
|
ADDED=$(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
COPIED=$(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
DELETED=$(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
MODIFIED=$(git diff --diff-filter=M --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
RENAMED=$(git diff --diff-filter=R --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
TYPE_CHANGED=$(git diff --diff-filter=T --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
UNMERGED=$(git diff --diff-filter=U --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
UNKNOWN=$(git diff --diff-filter=X --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
2021-09-04 13:42:11 +00:00
|
|
|
ALL_CHANGED_AND_MODIFIED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
2021-09-04 13:08:20 +00:00
|
|
|
ALL_MODIFIED_FILES=$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
2021-05-21 12:39:56 +00:00
|
|
|
else
|
2021-05-25 04:30:19 +00:00
|
|
|
ADDED_ARRAY=()
|
|
|
|
COPIED_ARRAY=()
|
|
|
|
DELETED_ARRAY=()
|
|
|
|
MODIFIED_ARRAY=()
|
|
|
|
RENAMED_ARRAY=()
|
2021-06-18 23:28:02 +00:00
|
|
|
TYPE_CHANGED_ARRAY=()
|
2021-05-25 04:30:19 +00:00
|
|
|
UNMERGED_ARRAY=()
|
|
|
|
UNKNOWN_ARRAY=()
|
|
|
|
ALL_CHANGED_ARRAY=()
|
|
|
|
ALL_MODIFIED_FILES_ARRAY=()
|
2021-07-17 14:51:08 +00:00
|
|
|
|
2021-09-04 13:31:19 +00:00
|
|
|
echo "Input files: ${INPUT_FILES[*]}"
|
|
|
|
|
2021-09-04 13:08:20 +00:00
|
|
|
for path in ${INPUT_FILES}
|
2021-05-25 04:30:19 +00:00
|
|
|
do
|
|
|
|
echo "Checking for file changes: \"${path}\"..."
|
|
|
|
IFS=" "
|
|
|
|
# shellcheck disable=SC2207
|
2021-08-28 02:59:23 +00:00
|
|
|
ADDED_ARRAY+=($(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
|
2021-05-25 04:30:19 +00:00
|
|
|
# shellcheck disable=SC2207
|
2021-08-28 02:59:23 +00:00
|
|
|
COPIED_ARRAY+=($(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
|
2021-05-25 04:30:19 +00:00
|
|
|
# shellcheck disable=SC2207
|
2021-08-28 02:59:23 +00:00
|
|
|
DELETED_ARRAY+=($(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
|
2021-05-25 04:30:19 +00:00
|
|
|
# shellcheck disable=SC2207
|
2021-08-28 02:59:23 +00:00
|
|
|
MODIFIED_ARRAY+=($(git diff --diff-filter=M --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
|
2021-05-25 04:30:19 +00:00
|
|
|
# shellcheck disable=SC2207
|
2021-08-28 02:59:23 +00:00
|
|
|
RENAMED_ARRAY+=($(git diff --diff-filter=R --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
|
2021-05-25 04:30:19 +00:00
|
|
|
# shellcheck disable=SC2207
|
2021-08-28 02:59:23 +00:00
|
|
|
TYPE_CHANGED_ARRAY+=($(git diff --diff-filter=T --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
|
2021-05-25 04:30:19 +00:00
|
|
|
# shellcheck disable=SC2207
|
2021-08-28 02:59:23 +00:00
|
|
|
UNMERGED_ARRAY+=($(git diff --diff-filter=U --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
|
2021-05-25 04:30:19 +00:00
|
|
|
# shellcheck disable=SC2207
|
2021-08-28 02:59:23 +00:00
|
|
|
UNKNOWN_ARRAY+=($(git diff --diff-filter=X --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
|
2021-05-25 04:30:19 +00:00
|
|
|
# shellcheck disable=SC2207
|
2021-08-28 02:59:23 +00:00
|
|
|
ALL_CHANGED_ARRAY+=($(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
|
2021-05-25 04:30:19 +00:00
|
|
|
# shellcheck disable=SC2207
|
2021-08-28 02:59:23 +00:00
|
|
|
ALL_MODIFIED_FILES_ARRAY+=($(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
|
2021-05-25 04:30:19 +00:00
|
|
|
done
|
2021-05-21 12:39:56 +00:00
|
|
|
|
2021-09-04 13:08:20 +00:00
|
|
|
ADDED=$(echo "${ADDED_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
COPIED=$(echo "${COPIED_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
DELETED=$(echo "${DELETED_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
MODIFIED=$(echo "${MODIFIED_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
RENAMED=$(echo "${RENAMED_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
TYPE_CHANGED=$(echo "${TYPE_CHANGED_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
UNMERGED=$(echo "${UNMERGED_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
UNKNOWN=$(echo "${UNKNOWN_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
2021-09-04 13:42:11 +00:00
|
|
|
ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
2021-09-04 13:08:20 +00:00
|
|
|
ALL_MODIFIED_FILES=$(echo "${ALL_MODIFIED_FILES_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
2021-05-21 12:39:56 +00:00
|
|
|
|
2021-08-09 12:57:25 +00:00
|
|
|
ALL_OTHER_CHANGED_FILES=$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
|
2021-09-04 13:31:19 +00:00
|
|
|
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_CHANGED_FILES_ARRAY <<< "$(echo "${ALL_OTHER_CHANGED_FILES[@]}" "${UNIQUE_ALL_MODIFIED_FILES[@]}" | tr " " "\n" | sort | uniq -u | tr "\n" " ")"
|
2021-07-17 19:13:26 +00:00
|
|
|
|
2021-09-04 13:31:19 +00:00
|
|
|
OTHER_CHANGED_FILES=$(echo "${OTHER_CHANGED_FILES_ARRAY[*]}" | tr " " "\n" | sort -u | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
|
|
|
|
|
|
|
|
echo "Matching modified files: ${UNIQUE_ALL_MODIFIED_FILES_ARRAY[*]}"
|
2021-05-21 12:39:56 +00:00
|
|
|
|
2021-09-04 13:31:19 +00:00
|
|
|
if [[ -n "${UNIQUE_ALL_MODIFIED_FILES_ARRAY[*]}" ]]; then
|
2021-05-21 12:39:56 +00:00
|
|
|
echo "::set-output name=any_changed::true"
|
|
|
|
else
|
|
|
|
echo "::set-output name=any_changed::false"
|
|
|
|
fi
|
2021-07-17 19:13:26 +00:00
|
|
|
|
2021-09-04 13:31:19 +00:00
|
|
|
if [[ -n "${OTHER_CHANGED_FILES_ARRAY[*]}" ]]; then
|
|
|
|
echo "Non Matching modified files: ${OTHER_CHANGED_FILES_ARRAY[*]}"
|
2021-07-17 19:13:26 +00:00
|
|
|
echo "::set-output name=only_changed::false"
|
|
|
|
echo "::set-output name=other_changed_files::$OTHER_CHANGED_FILES"
|
|
|
|
else
|
|
|
|
echo "::set-output name=only_changed::true"
|
|
|
|
fi
|
2021-05-21 12:39:56 +00:00
|
|
|
fi
|
|
|
|
|
2021-09-04 13:08:20 +00:00
|
|
|
echo "Added files: $ADDED"
|
|
|
|
echo "Copied files: $COPIED"
|
|
|
|
echo "Deleted files: $DELETED"
|
|
|
|
echo "Modified files: $MODIFIED"
|
|
|
|
echo "Renamed files: $RENAMED"
|
|
|
|
echo "Type Changed files: $TYPE_CHANGED"
|
|
|
|
echo "Unmerged files: $UNMERGED"
|
|
|
|
echo "Unknown files: $UNKNOWN"
|
2021-09-04 13:42:11 +00:00
|
|
|
echo "All changed files: $ALL_CHANGED_AND_MODIFIED"
|
2021-09-04 13:08:20 +00:00
|
|
|
echo "All modified files: $ALL_MODIFIED_FILES"
|
|
|
|
|
2021-08-18 00:03:07 +00:00
|
|
|
git remote remove temp_changed_files
|
|
|
|
|
2021-05-21 12:39:56 +00:00
|
|
|
echo "::set-output name=added_files::$ADDED"
|
|
|
|
echo "::set-output name=copied_files::$COPIED"
|
|
|
|
echo "::set-output name=deleted_files::$DELETED"
|
|
|
|
echo "::set-output name=modified_files::$MODIFIED"
|
|
|
|
echo "::set-output name=renamed_files::$RENAMED"
|
2021-06-18 23:28:02 +00:00
|
|
|
echo "::set-output name=type_changed_files::$TYPE_CHANGED"
|
2021-05-21 12:39:56 +00:00
|
|
|
echo "::set-output name=unmerged_files::$UNMERGED"
|
|
|
|
echo "::set-output name=unknown_files::$UNKNOWN"
|
2021-09-04 13:42:11 +00:00
|
|
|
echo "::set-output name=all_changed_and_modified_files::$ALL_CHANGED_AND_MODIFIED"
|
2021-05-21 12:39:56 +00:00
|
|
|
echo "::set-output name=all_modified_files::$ALL_MODIFIED_FILES"
|
2021-06-26 14:20:56 +00:00
|
|
|
|
|
|
|
echo "::endgroup::"
|