Skip to content

Commit

Permalink
Added support for detecting non specific file changes. (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Jul 17, 2021
1 parent cb4914b commit 8c6f276
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -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
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -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) |
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Expand Up @@ -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'
Expand Down
13 changes: 13 additions & 0 deletions entrypoint.sh
Expand Up @@ -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"
Expand Down

0 comments on commit 8c6f276

Please sign in to comment.