mirror of
https://github.com/tj-actions/changed-files
synced 2024-12-16 19:27:39 +00:00
Added support for detecting deleted files. (#188)
This commit is contained in:
parent
81037a4f7b
commit
5e2a2f1923
4 changed files with 125 additions and 14 deletions
71
.github/workflows/test.yml
vendored
71
.github/workflows/test.yml
vendored
|
@ -172,7 +172,7 @@ jobs:
|
|||
echo '${{ toJSON(steps.changed-files-specific.outputs) }}'
|
||||
shell:
|
||||
bash
|
||||
- name: Verify any_changed files
|
||||
- name: Verify any_changed for specific files
|
||||
if: "!contains(steps.changed-files-specific.outputs.all_modified_files, 'action.yml') && !contains(steps.changed-files-specific.outputs.all_modified_files, '.github/workflows/test.yml')"
|
||||
run: |
|
||||
if [[ "${{ steps.changed-files-specific.outputs.any_changed }}" != "false" ]]; then
|
||||
|
@ -181,6 +181,15 @@ jobs:
|
|||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Verify any_deleted for specific files
|
||||
if: "!contains(steps.changed-files-specific.outputs.deleted_files, 'action.yml') && !contains(steps.changed-files-specific.outputs.deleted_files, '.github/workflows/test.yml')"
|
||||
run: |
|
||||
if [[ "${{ steps.changed-files-specific.outputs.any_deleted }}" != "false" ]]; then
|
||||
echo "Invalid output: Expected (false) got (${{ steps.changed-files-specific.outputs.any_deleted }})"
|
||||
exit 1
|
||||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Run changed-files with specific files comma check duplicates
|
||||
id: changed-files-specific-duplicate-output
|
||||
uses: ./
|
||||
|
@ -222,6 +231,15 @@ jobs:
|
|||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Verify any_deleted files comma separator
|
||||
if: "!contains(steps.changed-files-specific-comma.outputs.deleted_files, 'action.yml') && !contains(steps.changed-files-specific-comma.outputs.deleted_files, '.github/workflows/test.yml')"
|
||||
run: |
|
||||
if [[ "${{ steps.changed-files-specific-comma.outputs.any_deleted }}" != "false" ]]; then
|
||||
echo "Invalid output: Expected (false) got (${{ steps.changed-files-specific-comma.outputs.any_deleted }})"
|
||||
exit 1
|
||||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Run changed-files with specific files pipe separator
|
||||
id: changed-files-specific-pipe
|
||||
uses: ./
|
||||
|
@ -244,6 +262,15 @@ jobs:
|
|||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Verify any_deleted files comma separator
|
||||
if: "!contains(steps.changed-files-specific-pipe.outputs.deleted_files, 'action.yml') && !contains(steps.changed-files-specific-pipe.outputs.deleted_files, '.github/workflows/test.yml')"
|
||||
run: |
|
||||
if [[ "${{ steps.changed-files-specific-pipe.outputs.any_deleted }}" != "false" ]]; then
|
||||
echo "Invalid output: Expected (false) got (${{ steps.changed-files-specific-pipe.outputs.any_deleted }})"
|
||||
exit 1
|
||||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Run changed-files with specific files forward slash separator
|
||||
id: changed-files-specific-forward-slash
|
||||
uses: ./
|
||||
|
@ -266,6 +293,15 @@ jobs:
|
|||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Verify any_deleted files comma separator
|
||||
if: "!contains(steps.changed-files-specific-forward-slash.outputs.deleted_files, 'action.yml') && !contains(steps.changed-files-specific-forward-slash.outputs.deleted_files, '.github/workflows/test.yml')"
|
||||
run: |
|
||||
if [[ "${{ steps.changed-files-specific.outputs.any_deleted }}" != "false" ]]; then
|
||||
echo "Invalid output: Expected (false) got (${{ steps.changed-files-specific-forward-slash.outputs.any_deleted }})"
|
||||
exit 1
|
||||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Run changed-files with specific files from a source file
|
||||
id: changed-files-specific-source-file
|
||||
uses: ./
|
||||
|
@ -275,7 +311,7 @@ jobs:
|
|||
test/changed-files-list.txt
|
||||
files: |
|
||||
.github/workflows/rebase.yml
|
||||
- name: Verify any_changed files
|
||||
- name: Verify any_changed from source files
|
||||
if: "!contains(steps.changed-files-specific-source-file.outputs.all_modified_files, 'action.yml') && !contains(steps.changed-files-specific-source-file.outputs.all_modified_files, '.github/workflows/test.yml')"
|
||||
run: |
|
||||
if [[ "${{ steps.changed-files-specific-source-file.outputs.any_changed }}" != "false" ]]; then
|
||||
|
@ -284,6 +320,15 @@ jobs:
|
|||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Verify any_deleted from source files
|
||||
if: "!contains(steps.changed-files-specific-source-file.outputs.deleted_files, 'action.yml') && !contains(steps.changed-files-specific-source-file.outputs.deleted_files, '.github/workflows/test.yml')"
|
||||
run: |
|
||||
if [[ "${{ steps.changed-files-specific-source-file.outputs.any_deleted }}" != "false" ]]; then
|
||||
echo "Invalid output: Expected (false) got (${{ steps.changed-files-specific-source-file.outputs.any_deleted }})"
|
||||
exit 1
|
||||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Show output
|
||||
run: |
|
||||
echo '${{ toJSON(steps.changed-files-specific-source-file.outputs) }}'
|
||||
|
@ -296,6 +341,11 @@ jobs:
|
|||
files_from_source_file: |
|
||||
test/changed-files-list.txt
|
||||
separator: ","
|
||||
- name: Show output
|
||||
run: |
|
||||
echo '${{ toJSON(steps.changed-files-specific-comma-source-file.outputs) }}'
|
||||
shell:
|
||||
bash
|
||||
- name: Verify any_changed files comma separator
|
||||
if: "!contains(steps.changed-files-specific-comma-source-file.outputs.all_modified_files, 'action.yml') && !contains(steps.changed-files-specific-comma-source-file.outputs.all_modified_files, '.github/workflows/test.yml')"
|
||||
run: |
|
||||
|
@ -305,9 +355,13 @@ jobs:
|
|||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Show output
|
||||
- name: Verify any_deleted files with comma separator
|
||||
if: "!contains(steps.changed-files-specific-comma-source-file.outputs.deleted_files, 'action.yml') && !contains(steps.changed-files-specific-comma-source-file.outputs.deleted_files, '.github/workflows/test.yml')"
|
||||
run: |
|
||||
echo '${{ toJSON(steps.changed-files-specific-comma-source-file.outputs) }}'
|
||||
if [[ "${{ steps.changed-files-specific-comma-source-file.outputs.any_deleted }}" != "false" ]]; then
|
||||
echo "Invalid output: Expected (false) got (${{ steps.changed-files-specific-comma-source-file.outputs.any_deleted }})"
|
||||
exit 1
|
||||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Run changed-files with custom sha
|
||||
|
@ -354,6 +408,15 @@ jobs:
|
|||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Verify only_deleted files
|
||||
if: steps.changed-files-specific-only-changed.outputs.other_deleted_files != ''
|
||||
run: |
|
||||
if [[ "${{ steps.changed-files-specific-only-changed.outputs.only_deleted }}" != "false" ]]; then
|
||||
echo "Invalid output: Expected (false) got (${{ steps.changed-files-specific-only-changed.outputs.only_deleted }})"
|
||||
exit 1
|
||||
fi
|
||||
shell:
|
||||
bash
|
||||
- name: Show output
|
||||
run: |
|
||||
echo '${{ toJSON(steps.changed-files-specific-only-changed.outputs) }}'
|
||||
|
|
17
README.md
17
README.md
|
@ -83,6 +83,8 @@ jobs:
|
|||
|:--------------------:|:------------:|:----------------------------------:|:----------------------------------------:|
|
||||
| any_changed | `string` | `true` OR `false` | Returns `true` when any <br /> of the filenames provided using <br /> the `files` input has changed. <br /> i.e. *using a combination of all added, <br />copied, modified and renamed files (ACMR).* |
|
||||
| only_changed | `string` | `true` OR `false` | Returns `true` when only <br /> files provided using <br /> the `files` input have changed. |
|
||||
| any_deleted | `string` | `true` OR `false` | Returns `true` when any <br /> of the filenames provided using <br /> the `files` input has been deleted. |
|
||||
| only_deleted | `string` | `true` OR `false` | Returns `true` when only <br /> files provided using <br /> the `files` input has been deleted. |
|
||||
| other_changed_files | `string` | `'new.txt path/to/file.png ...'` | Select all other changed files <br/> not listed in the files input <br /> i.e. *a combination of all added, <br /> copied and modified files (ACMR).* |
|
||||
| all_modified_files | `string` | `'new.txt path/to/file.png ...'` | Select all modified files <br /> i.e. *a combination of all added, <br />copied, modified and renamed files (ACMR).* |
|
||||
| all_changed_and_modified_files | `string` | `'new.txt path/to/file.png ...'` | Select all changed <br /> and modified files <br /> i.e. *a combination of (ACMRDTUX).* |
|
||||
|
@ -164,6 +166,20 @@ jobs:
|
|||
run: |
|
||||
echo "Only files listed above have changed."
|
||||
|
||||
- name: Run step if any of the listed files above is deleted
|
||||
if: steps.changed-files.outputs.any_deleted == "true"
|
||||
run: |
|
||||
for file in "${{ steps.changed-files.outputs.deleted_files }}"; do
|
||||
echo "$file was deleted"
|
||||
done
|
||||
|
||||
- name: Run step if all listed files above have been deleted
|
||||
if: steps.changed-files.outputs.only_deleted == "true"
|
||||
run: |
|
||||
for file in "${{ steps.changed-files.outputs.deleted_files }}"; do
|
||||
echo "$file was deleted"
|
||||
done
|
||||
|
||||
- name: Use a source file or list of file(s) to populate to files input.
|
||||
id: changed-files-specific-source-file
|
||||
uses: tj-actions/changed-files@v1.1.0
|
||||
|
@ -203,7 +219,6 @@ jobs:
|
|||
uses: tj-actions/changed-files@v1.1.0
|
||||
with:
|
||||
path: subfolder
|
||||
|
||||
```
|
||||
|
||||
### Running [pre-commit](https://pre-commit.com/) on all modified files
|
||||
|
|
11
action.yml
11
action.yml
|
@ -64,11 +64,20 @@ outputs:
|
|||
description: Return true only when any files provided using the files input have changed.
|
||||
value: ${{ steps.changed-files.outputs.any_changed }}
|
||||
only_changed:
|
||||
description: Return true only when only files provided using the files input have changed.
|
||||
description: Return true when all files provided using the files input have changed.
|
||||
value: ${{ steps.changed-files.outputs.only_changed }}
|
||||
other_changed_files:
|
||||
description: Return list of changed files not listed in the files input.
|
||||
value: ${{ steps.changed-files.outputs.other_changed_files }}
|
||||
any_deleted:
|
||||
description: Return true only when any files provided using the files input have been deleted.
|
||||
value: ${{ steps.changed-files.outputs.any_deleted }}
|
||||
only_deleted:
|
||||
description: Return true when all files provided using the files input have been deleted.
|
||||
value: ${{ steps.changed-files.outputs.only_deleted }}
|
||||
other_deleted_files:
|
||||
description: Return list of deleted files not listed in the files input.
|
||||
value: ${{ steps.changed-files.outputs.other_deleted_files }}
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
|
|
|
@ -125,11 +125,12 @@ else
|
|||
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}')
|
||||
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}')
|
||||
|
||||
ALL_OTHER_CHANGED_FILES=$(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_CHANGED_FILES_ARRAY <<< "$(echo "${ALL_OTHER_CHANGED_FILES[@]}" "${UNIQUE_ALL_MODIFIED_FILES[@]}" | tr " " "\n" | sort | uniq -u | tr "\n" " ")"
|
||||
ALL_OTHER_MODIFIED_FILES=$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
|
||||
|
||||
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}')
|
||||
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" " ")"
|
||||
|
||||
OTHER_MODIFIED_FILES=$(echo "${OTHER_MODIFIED_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[*]}"
|
||||
|
||||
|
@ -139,13 +140,36 @@ else
|
|||
echo "::set-output name=any_changed::false"
|
||||
fi
|
||||
|
||||
if [[ -n "${OTHER_CHANGED_FILES_ARRAY[*]}" ]]; then
|
||||
echo "Non Matching modified files: ${OTHER_CHANGED_FILES_ARRAY[*]}"
|
||||
if [[ -n "${OTHER_MODIFIED_FILES_ARRAY[*]}" ]]; then
|
||||
echo "Non Matching modified files: ${OTHER_MODIFIED_FILES_ARRAY[*]}"
|
||||
echo "::set-output name=only_changed::false"
|
||||
echo "::set-output name=other_changed_files::$OTHER_CHANGED_FILES"
|
||||
else
|
||||
echo "::set-output name=other_changed_files::$OTHER_MODIFIED_FILES"
|
||||
elif [[ -n "${UNIQUE_ALL_MODIFIED_FILES_ARRAY[*]}" ]]; then
|
||||
echo "::set-output name=only_changed::true"
|
||||
fi
|
||||
|
||||
OTHER_DELETED_FILES=$(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" " ")"
|
||||
|
||||
OTHER_DELETED_FILES=$(echo "${OTHER_DELETED_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_DELETED_FILES_ARRAY[*]}"
|
||||
|
||||
if [[ -n "${UNIQUE_DELETED_FILES_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 modified files: ${OTHER_DELETED_FILES_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=only_deleted::true"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Added files: $ADDED"
|
||||
|
|
Loading…
Reference in a new issue