From 8c6f276ea5961fa51474aaa203c6d06226acbaa8 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 17 Jul 2021 15:13:26 -0400 Subject: [PATCH] Added support for detecting non specific file changes. (#137) --- .github/workflows/test.yml | 20 ++++++++++++++++++++ README.md | 4 +++- action.yml | 6 ++++++ entrypoint.sh | 13 +++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 096fb90a..99282d9a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/README.md b/README.md index d8657655..d65b763e 100644 --- a/README.md +++ b/README.md @@ -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
not listed in the files input
i.e. *a combination of all added,
copied and modified files (ACM).* | | all_modified_files | `string` | `'new.txt path/to/file.png ...'` | Select all modified files
i.e. *a combination of all added,
copied and modified files (ACM).* | | all_changed_files | `string` | `'new.txt path/to/file.png ...'` | Select all paths (\*)
i.e. *a combination of all options below.* | | added_files | `string` | `'new.txt path/to/file.png ...'` | Select only files that are Added (A) | diff --git a/action.yml b/action.yml index e9d3c199..d800295d 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/entrypoint.sh b/entrypoint.sh index db26ceed..8fca7be4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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"