diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 3290a077..28f61de9 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -125,6 +125,45 @@ jobs:
fi
shell:
bash
+ - name: Run changed-files with specific files from a source file
+ id: changed-files-specific-source-file
+ uses: ./
+ with:
+ files-from-source-file: |
+ test/changed-files-list.txt
+ test/changed-files-list.txt
+ files: |
+ .github/workflows/rebase.yml
+ - name: Verify any_changed 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
+ echo "Invalid output: Expected (false) got (${{ steps.changed-files-specific.outputs.any_changed }})"
+ exit 1
+ fi
+ shell:
+ bash
+ - name: Show output
+ run: |
+ echo "${{ toJSON(steps.changed-files-specific.outputs) }}"
+ shell:
+ bash
+ - name: Run changed-files with specific files from a source file using a comma separator
+ id: changed-files-specific-comma-source-file
+ uses: ./
+ with:
+ files-from-source-file: |
+ test/changed-files-list.txt
+ separator: ","
+ - name: Verify any_changed files comma separator
+ if: "!contains(steps.changed-files-specific-comma.outputs.all_modified_files, 'action.yml') && !contains(steps.changed-files-specific-comma.outputs.all_modified_files, '.github/workflows/test.yml')"
+ run: |
+ if [[ "${{ steps.changed-files-specific.outputs.any_changed }}" != "false" ]]; then
+ echo "Invalid output: Expected (false) got (${{ steps.changed-files-specific.outputs.any_changed }})"
+ exit 1
+ fi
+ shell:
+ bash
- name: Show output
run: |
echo "${{ toJSON(steps.changed-files-specific-comma.outputs) }}"
diff --git a/README.md b/README.md
index 4e700b18..3f03ee22 100644
--- a/README.md
+++ b/README.md
@@ -99,6 +99,7 @@ jobs:
| separator | `string` | `true` | `' '` | Output string separator |
| files | `string` OR `string[]` | `false` | | Check for changes
using only these list of file(s)
(Defaults to the entire repo) |
| sha | `string` | `true` | `${{ github.sha }}` | Specify a different
commit SHA used for comparing changes |
+| files-from-source-file | `string` | `false` | | Source file used populate
the files input. |
## Example
@@ -150,6 +151,22 @@ jobs:
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
echo "One or more files listed above has changed."
+
+ - name: Use a source file or list of file(s) to populate to files input.
+ id: changed-files-specific-source-file
+ uses: ./
+ with:
+ files-from-source-file: |
+ test/changed-files-list.txt
+
+ - name: Use a source file or list of file(s) to populate to files input and optionally specify more files.
+ id: changed-files-specific-source-file-and-specify-files
+ uses: ./
+ with:
+ files-from-source-file: |
+ test/changed-files-list.txt
+ files: |
+ .github/workflows/rebase.yml
- name: Use a different commit SHA
id: changed-files-comma
diff --git a/action.yml b/action.yml
index 33d31016..f19591d6 100644
--- a/action.yml
+++ b/action.yml
@@ -10,6 +10,10 @@ inputs:
description: 'Split character for array output'
required: true
default: " "
+ files-from-source-file:
+ description: 'Source file to populate the files input'
+ required: false
+ default: ""
files:
description: 'Check for changes using only this list of files (Defaults to the entire repo)'
required: false
@@ -57,6 +61,22 @@ outputs:
runs:
using: 'composite'
steps:
+ - run: |
+ FILES=()
+
+ if [[ -n $INPUT_FILES_FROM_SOURCE_FILE ]]; then
+ for file in $INPUT_FILES_FROM_SOURCE_FILE
+ do
+ FILES+=$(cat $file | sort -u | tr "\n" " " )
+ done
+ fi
+
+ echo "::set-output name=files::$FILES"
+ id: source-input-files
+ shell: bash
+ env:
+ INPUT_FILES: ${{ inputs.files }}
+ INPUT_FILES_FROM_SOURCE_FILE: ${{ inputs.files-from-source-file }}
- run: |
bash $GITHUB_ACTION_PATH/entrypoint.sh
id: changed-files
@@ -68,7 +88,7 @@ runs:
# https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611
INPUT_SHA: ${{ inputs.sha }}
INPUT_TOKEN: ${{ inputs.token }}
- INPUT_FILES: ${{ inputs.files }}
+ INPUT_FILES: ${{ join(format('{0} {1}', inputs.files, steps.source-input-files.outputs.files), ' ') }}
INPUT_SEPARATOR: ${{ inputs.separator }}
branding:
diff --git a/entrypoint.sh b/entrypoint.sh
index 390eb7b3..57759ee8 100755
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -43,7 +43,9 @@ fi
echo "Retrieving changes between $PREV_SHA ($TARGET_BRANCH) → $CURR_SHA ($CURRENT_BRANCH)"
-if [[ -z "$INPUT_FILES" ]]; then
+UNIQUE_FILES=$(echo "$INPUT_FILES" | tr ' ' '\n' | sort -u | xargs)
+
+if [[ -z "$UNIQUE_FILES" ]]; then
echo "Getting diff..."
ADDED=$(git diff --diff-filter=A --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
COPIED=$(git diff --diff-filter=C --name-only "$PREV_SHA" "$CURR_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
@@ -66,7 +68,8 @@ else
UNKNOWN_ARRAY=()
ALL_CHANGED_ARRAY=()
ALL_MODIFIED_FILES_ARRAY=()
- for path in ${INPUT_FILES}
+
+ for path in ${UNIQUE_FILES}
do
echo "Checking for file changes: \"${path}\"..."
IFS=" "
@@ -125,9 +128,9 @@ echo "Unknown files: $UNKNOWN"
echo "All changed files: $ALL_CHANGED"
echo "All modified files: $ALL_MODIFIED_FILES"
-if [[ -n "$INPUT_FILES" ]]; then
+if [[ -n "$UNIQUE_FILES" ]]; then
# shellcheck disable=SC2001
- ALL_INPUT_FILES=$(echo "$INPUT_FILES" | tr "\n" " " | xargs)
+ ALL_INPUT_FILES=$(echo "$UNIQUE_FILES" | tr "\n" " " | xargs)
echo "Input files: ${ALL_INPUT_FILES[*]}"
echo "Matching modified files: ${ALL_MODIFIED_FILES[*]}"
diff --git a/test/changed-files-list.txt b/test/changed-files-list.txt
new file mode 100644
index 00000000..3852a74e
--- /dev/null
+++ b/test/changed-files-list.txt
@@ -0,0 +1,4 @@
+.github/workflows/test.yml
+action.yml
+action.yml
+test/changed-files-list.txt
\ No newline at end of file