Added support for retrieving the files input using a source file. (#132)
This commit is contained in:
parent
256e64f4cc
commit
bd55e90a0a
39
.github/workflows/test.yml
vendored
39
.github/workflows/test.yml
vendored
@ -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) }}"
|
||||
|
17
README.md
17
README.md
@ -99,6 +99,7 @@ jobs:
|
||||
| separator | `string` | `true` | `' '` | Output string separator |
|
||||
| files | `string` OR `string[]` | `false` | | Check for changes <br> using only these list of file(s) <br> (Defaults to the entire repo) |
|
||||
| sha | `string` | `true` | `${{ github.sha }}` | Specify a different <br> commit SHA used for comparing changes |
|
||||
| files-from-source-file | `string` | `false` | | Source file used populate <br> the files input. |
|
||||
|
||||
## Example
|
||||
|
||||
@ -151,6 +152,22 @@ jobs:
|
||||
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
|
||||
uses: tj-actions/changed-files@v8.5
|
||||
|
22
action.yml
22
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:
|
||||
|
@ -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[*]}"
|
||||
|
4
test/changed-files-list.txt
Normal file
4
test/changed-files-list.txt
Normal file
@ -0,0 +1,4 @@
|
||||
.github/workflows/test.yml
|
||||
action.yml
|
||||
action.yml
|
||||
test/changed-files-list.txt
|
Loading…
x
Reference in New Issue
Block a user