Added support for detecting non specific file changes. (#137)

This commit is contained in:
Tonye Jack 2021-07-17 15:13:26 -04:00 committed by GitHub
parent cb4914b39a
commit 8c6f276ea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 1 deletions

View File

@ -198,3 +198,23 @@ jobs:
echo "${{ toJSON(steps.changed-files-custom-base-sha.outputs) }}"
shell:
bash
- name: Run changed-files with specific files (only-changed)
id: changed-files-specific-only-changed
uses: ./
with:
files: |
.github/workflows/test.yml
- name: Verify only_changed files
if: steps.changed-files-specific-only-changed.outputs.other_changed_files != ''
run: |
if [[ "${{ steps.changed-files-specific-only-changed.outputs.only_changed }}" != "false" ]]; then
echo "Invalid output: Expected (false) got (${{ steps.changed-files-specific-only-changed.outputs.only_changed }})"
exit 1
fi
shell:
bash
- name: Show output
run: |
echo "${{ toJSON(steps.changed-files-specific-only-changed.outputs) }}"
shell:
bash

View File

@ -79,7 +79,9 @@ jobs:
| Output | type | example | description |
|:--------------------:|:------------:|:----------------------------------:|:----------------------------------------:|
| any_changed | `string` | `true` OR `false` | Returns `true` when any of the filenames provided using the `files` input has changed |
| any_changed | `string` | `true` OR `false` | Returns `true` when any of the filenames provided using the `files` input has changed |
| only_changed | `string` | `true` OR `false` | Returns `true` when only files provided using the `files` input have changed. |
| other_changed_files | `string` | `'new.txt path/to/file.png ...'` | Select all modified files <br/> not listed in the files input <br /> i.e. *a combination of all added, <br /> copied and modified files (ACM).* |
| all_modified_files | `string` | `'new.txt path/to/file.png ...'` | Select all modified files <br /> i.e. *a combination of all added, <br />copied and modified files (ACM).* |
| all_changed_files | `string` | `'new.txt path/to/file.png ...'` | Select all paths (\*) <br /> i.e. *a combination of all options below.* |
| added_files | `string` | `'new.txt path/to/file.png ...'` | Select only files that are Added (A) |

View File

@ -60,6 +60,12 @@ outputs:
any_changed:
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.
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 }}
runs:
using: 'composite'

View File

@ -139,14 +139,27 @@ echo "All modified files: $ALL_MODIFIED_FILES"
if [[ -n "$UNIQUE_FILES" ]]; then
# shellcheck disable=SC2001
ALL_INPUT_FILES=$(echo "$UNIQUE_FILES" | tr "\n" " " | xargs)
ALL_OTHER_CHANGED_FILES=$(git diff --diff-filter="ACM" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
OTHER_CHANGED_FILES=$(echo "${ALL_OTHER_CHANGED_FILES[@]}" "${ALL_MODIFIED_FILES[@]}" | tr ' ' '\n' | sort | uniq -u | tr "\n" " " | xargs)
echo "Input files: ${ALL_INPUT_FILES[*]}"
echo "Matching modified files: ${ALL_MODIFIED_FILES[*]}"
if [[ -n "$ALL_MODIFIED_FILES" ]]; then
echo "::set-output name=any_changed::true"
else
echo "::set-output name=any_changed::false"
fi
if [[ -n "$OTHER_CHANGED_FILES" ]]; then
echo "Non Matching modified files: ${OTHER_CHANGED_FILES[*]}"
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
fi
echo "::set-output name=added_files::$ADDED"