3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2024-12-17 13:47:20 +00:00
changed-files/action.yml

175 lines
8.7 KiB
YAML
Raw Normal View History

2021-04-04 13:00:53 +00:00
name: Changed files
description: Get all changed files
2021-03-05 02:36:52 +00:00
author: tj-actions
inputs:
token:
description: 'Github token'
required: true
default: ${{ github.token }}
2021-03-05 12:25:17 +00:00
separator:
description: 'Split character for array output'
2021-03-05 02:36:52 +00:00
required: true
2021-03-05 12:25:17 +00:00
default: " "
files:
description: 'Check for file changes for all files listed (Defaults to the entire repo)'
required: false
default: ""
2021-03-05 12:25:17 +00:00
2021-03-05 03:43:17 +00:00
outputs:
added_files:
description: List of added files.
2021-04-23 10:13:11 +00:00
value: ${{ steps.changed_files.outputs.added_files }}
2021-03-05 03:43:17 +00:00
copied_files:
description: List of copied files.
2021-04-23 10:13:11 +00:00
value: ${{ steps.changed_files.outputs.copied_files }}
2021-03-05 03:43:17 +00:00
deleted_files:
description: List of deleted files.
2021-04-23 10:13:11 +00:00
value: ${{ steps.changed_files.outputs.deleted_files }}
2021-03-05 03:43:17 +00:00
modified_files:
2021-03-05 11:03:04 +00:00
description: List of modified files.
2021-04-23 10:13:11 +00:00
value: ${{ steps.changed_files.outputs.modified_files }}
2021-03-05 03:43:17 +00:00
renamed_files:
description: List of renamed files.
2021-04-23 10:13:11 +00:00
value: ${{ steps.changed_files.outputs.renamed_files }}
2021-03-05 03:43:17 +00:00
changed_files:
2021-03-05 11:03:04 +00:00
description: List of changed files.
2021-04-23 10:13:11 +00:00
value: ${{ steps.changed_files.outputs.changed_files }}
2021-03-05 03:43:17 +00:00
unmerged_files:
description: List of unmerged files.
2021-04-23 10:13:11 +00:00
value: ${{ steps.changed_files.outputs.unmerged_files }}
2021-03-05 03:43:17 +00:00
unknown_files:
description: List of unknown files.
2021-04-23 10:13:11 +00:00
value: ${{ steps.changed_files.outputs.unknown_files }}
2021-03-05 03:43:17 +00:00
all_changed_files:
description: List of all changed files.
2021-04-23 10:13:11 +00:00
value: ${{ steps.changed_files.outputs.all_changed_files }}
2021-04-11 21:54:10 +00:00
all_modified_files:
2021-04-11 22:06:58 +00:00
description: List of all copied modified and added files
2021-04-23 10:13:11 +00:00
value: ${{ steps.changed_files.outputs.all_modified_files }}
2021-05-01 17:32:09 +00:00
any_changed:
description: Return true only when any files provided using the files input have changed.
value: ${{ steps.changed_files.outputs.any_changed }}
2021-03-05 02:36:52 +00:00
runs:
2021-03-05 03:50:33 +00:00
using: 'composite'
steps:
2021-04-23 10:13:11 +00:00
- id: changed_files
2021-03-05 03:50:33 +00:00
run: |
2021-05-01 23:00:26 +00:00
set -e
git remote set-url origin "https://${{ inputs.token }}@github.com/${{ github.repository }}"
2021-05-01 23:00:26 +00:00
2021-05-01 19:14:25 +00:00
export INPUT_FILES="${{ inputs.files }}"
export INPUT_SEPARATOR="${{ inputs.separator }}"
2021-05-01 19:49:20 +00:00
echo "Getting head sha..."
if [[ -z $GITHUB_BASE_REF ]]; then
HEAD_SHA=$(git rev-parse HEAD^1 || true)
else
TARGET_BRANCH=${GITHUB_BASE_REF}
git fetch --depth=1 origin "${TARGET_BRANCH}":"${TARGET_BRANCH}"
HEAD_SHA=$(git rev-parse "${TARGET_BRANCH}" || true)
fi
if [[ -z $HEAD_SHA ]]; then
echo "::warning::Unable to determine the head sha: $HEAD_SHA."
2021-05-09 00:06:24 +00:00
echo "::warning::You seem to be missing `fetch-depth: 0` or `fetch-depth: 2`"
2021-05-01 19:49:20 +00:00
else
echo "Using head sha: $HEAD_SHA..."
if [[ -z "$INPUT_FILES" ]]; then
echo "Getting diff..."
ADDED=$(git diff --diff-filter=A --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
COPIED=$(git diff --diff-filter=C --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
DELETED=$(git diff --diff-filter=D --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
MODIFIED=$(git diff --diff-filter=M --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
RENAMED=$(git diff --diff-filter=R --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
CHANGED=$(git diff --diff-filter=T --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
UNMERGED=$(git diff --diff-filter=U --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
UNKNOWN=$(git diff --diff-filter=X --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
ALL_CHANGED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
ALL_MODIFIED_FILES=$(git diff --diff-filter="ACM" --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
else
ADDED_ARRAY=()
COPIED_ARRAY=()
DELETED_ARRAY=()
MODIFIED_ARRAY=()
RENAMED_ARRAY=()
CHANGED_ARRAY=()
UNMERGED_ARRAY=()
UNKNOWN_ARRAY=()
ALL_CHANGED_ARRAY=()
ALL_MODIFIED_FILES_ARRAY=()
2021-05-06 21:31:39 +00:00
for path in ${INPUT_FILES}
do
echo "Checking for file changes: \"${path}\"..."
IFS=" "
ADDED_ARRAY+=("$(git diff --diff-filter=A --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs printf "%s$INPUT_SEPARATOR" || true)")
COPIED_ARRAY+=("$(git diff --diff-filter=C --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs printf "%s$INPUT_SEPARATOR" || true)")
DELETED_ARRAY+=("$(git diff --diff-filter=D --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs printf "%s$INPUT_SEPARATOR" || true)")
MODIFIED_ARRAY+=("$(git diff --diff-filter=M --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs printf "%s$INPUT_SEPARATOR" || true)")
RENAMED_ARRAY+=("$(git diff --diff-filter=R --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs printf "%s$INPUT_SEPARATOR" || true)")
CHANGED_ARRAY+=("$(git diff --diff-filter=T --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs printf "%s$INPUT_SEPARATOR" || true)")
UNMERGED_ARRAY+=("$(git diff --diff-filter=U --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs printf "%s$INPUT_SEPARATOR" || true)")
UNKNOWN_ARRAY+=("$(git diff --diff-filter=X --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs printf "%s$INPUT_SEPARATOR" || true)")
ALL_CHANGED_ARRAY+=("$(git diff --diff-filter="*ACDMRTUX" --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs printf "%s$INPUT_SEPARATOR" || true)")
ALL_MODIFIED_FILES_ARRAY+=("$(git diff --diff-filter="ACM" --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs printf "%s$INPUT_SEPARATOR" || true)")
done
2021-05-01 23:09:08 +00:00
ADDED=$(echo "${ADDED_ARRAY[@]}" | sed -E "s/($INPUT_SEPARATOR)$//" | xargs)
COPIED=$(echo "${COPIED_ARRAY[@]}" | sed -E "s/($INPUT_SEPARATOR)$//" | xargs)
DELETED=$(echo "${DELETED_ARRAY[@]}" | sed -E "s/($INPUT_SEPARATOR)$//" | xargs)
MODIFIED=$(echo "${MODIFIED_ARRAY[@]}" | sed -E "s/($INPUT_SEPARATOR)$//" | xargs)
RENAMED=$(echo "${RENAMED_ARRAY[@]}" | sed -E "s/($INPUT_SEPARATOR)$//" | xargs)
CHANGED=$(echo "${CHANGED_ARRAY[@]}" | sed -E "s/($INPUT_SEPARATOR)$//" | xargs)
UNMERGED=$(echo "${UNMERGED_ARRAY[@]}" | sed -E "s/($INPUT_SEPARATOR)$//" | xargs)
UNKNOWN=$(echo "${UNKNOWN_ARRAY[@]}" | sed -E "s/($INPUT_SEPARATOR)$//" | xargs)
ALL_CHANGED=$(echo "${ALL_CHANGED_ARRAY[@]}" | sed -E "s/($INPUT_SEPARATOR)$//" | xargs)
ALL_MODIFIED_FILES=$(echo "${ALL_MODIFIED_FILES_ARRAY[@]}" | sed -E "s/($INPUT_SEPARATOR)$//" | xargs)
fi
2021-05-01 23:00:26 +00:00
fi
2021-05-01 23:09:08 +00:00
2021-05-01 23:00:26 +00:00
echo "Added files: $ADDED"
echo "Copied files: $COPIED"
echo "Deleted files: $DELETED"
echo "Modified files: $MODIFIED"
echo "Renamed files: $RENAMED"
echo "Changed files: $CHANGED"
echo "Unmerged files: $UNMERGED"
echo "Unknown files: $UNKNOWN"
echo "All changed files: $ALL_CHANGED"
echo "All modified files: $ALL_MODIFIED_FILES"
2021-05-01 23:09:08 +00:00
2021-05-01 23:00:26 +00:00
if [[ -n "$INPUT_FILES" ]]; then
2021-05-01 23:09:08 +00:00
# shellcheck disable=SC2001
OUTPUT_ALL_MODIFIED_FILES=$(echo "$ALL_MODIFIED_FILES" | tr "$INPUT_SEPARATOR" " " | xargs)
2021-05-01 23:58:35 +00:00
ALL_INPUT_FILES=$(echo "$INPUT_FILES" | tr "\n" " " | xargs)
echo "Input files: ${ALL_INPUT_FILES[@]}"
2021-05-13 20:57:44 +00:00
echo "Matching modified files: ${OUTPUT_ALL_MODIFIED_FILES[@]}"
2021-05-01 23:58:35 +00:00
2021-05-13 20:57:44 +00:00
if [[ ${#OUTPUT_ALL_MODIFIED_FILES[@]} -gt 0 ]]; then
2021-05-01 19:49:20 +00:00
echo "::set-output name=any_changed::true"
else
echo "::set-output name=any_changed::false"
fi
fi
2021-05-06 21:31:39 +00:00
2021-05-01 19:49:20 +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"
echo "::set-output name=changed_files::$CHANGED"
echo "::set-output name=unmerged_files::$UNMERGED"
echo "::set-output name=unknown_files::$UNKNOWN"
echo "::set-output name=all_changed_files::$ALL_CHANGED"
echo "::set-output name=all_modified_files::$ALL_MODIFIED_FILES"
2021-05-01 19:14:25 +00:00
unset INPUT_FILES
unset INPUT_SEPARATOR
2021-03-05 03:50:33 +00:00
shell: bash
2021-03-05 10:58:42 +00:00
2021-03-05 02:36:52 +00:00
branding:
2021-04-23 10:55:01 +00:00
icon: file-text
2021-03-05 02:36:52 +00:00
color: white