Skip to content

Commit

Permalink
Add support for using github's glob pattern syntax (#304)
Browse files Browse the repository at this point in the history
* Add support for using github's glob pattern syntax

Fixes: #264 #265

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update action.yml

* Update action.yml

* Update action.yml

* Update action.yml

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update sourcefiles.sh

* Update action.yml

* Update test.yml

* Update changed-files-list.txt

* Update changed-files-list.txt

* Update action.yml

* Update action.yml

* Update entrypoint.sh

* Update test.yml

* Update README.md

* Update test.yml

* Update entrypoint.sh

* Update test.yml

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jackton1 and github-actions[bot] committed Jan 5, 2022
1 parent 9b119a2 commit 4e8540c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Expand Up @@ -342,7 +342,7 @@ jobs:
uses: ./
with:
files: |
.github/workflows/test.yml
**/test.yml
action.yml
separator: "|"
- name: Show output
Expand Down Expand Up @@ -425,7 +425,7 @@ jobs:
test/changed-files-list.txt
test/changed-files-list.txt
files: |
.github/workflows/rebase.yml
**/workflows/rebase.yml
- name: Verify any_changed from source files
if: |
(
Expand Down Expand Up @@ -555,7 +555,7 @@ jobs:
uses: ./
with:
files: |
.github/workflows/test.yml
.github/**/test.yml
- name: Verify only_changed files
if: steps.changed-files-specific-only-changed.outputs.other_changed_files != ''
run: |
Expand Down
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -31,7 +31,7 @@ Retrieve all changed files relative to the default branch (`pull_request*` based
* Between the last remote branch commit and the current HEAD.
* Restrict change detection to a subset of files.
* Report on files that have at least one change.
* [Regex pattern](https://www.gnu.org/software/grep/manual/grep.html#Regular-Expressions) matching on a subset of files.
* [Glob pattern](https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet) matching on a subset of files.

## Usage

Expand Down Expand Up @@ -173,10 +173,10 @@ Support this project with a :star:
test.txt
new.txt
test_directory
\.sh$
.(png|jpeg)$
.(sql|py)$
^(mynewfile|custom)
*.sh
*.png
*.jpeg
**/migrate-*.sql
- name: Run step if any of the listed files above change
if: steps.changed-files-specific.outputs.any_changed == "true"
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Expand Up @@ -108,6 +108,12 @@ runs:
# https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611
INPUT_FILES: ${{ inputs.files }}
INPUT_FILES_FROM_SOURCE_FILE: ${{ inputs.files_from_source_file }}
- name: Glob match
uses: tj-actions/glob@v2
id: glob
with:
files: ${{ steps.source-input-files.outputs.files }}
files-separator: " "
- run: |
# "Set base sha..."
if [[ -n "${{ inputs.base_sha }}" ]]; then
Expand All @@ -134,7 +140,7 @@ runs:
INPUT_SHA: ${{ inputs.sha }}
INPUT_BASE_SHA: ${{ steps.base-sha.outputs.base_sha }}
INPUT_TOKEN: ${{ inputs.token }}
INPUT_FILES: ${{ steps.source-input-files.outputs.files }}
INPUT_FILES: ${{ steps.glob.outputs.paths }}
INPUT_SEPARATOR: ${{ inputs.separator }}
INPUT_PATH: ${{ inputs.path }}
Expand Down
14 changes: 9 additions & 5 deletions sourcefiles.sh
Expand Up @@ -4,22 +4,26 @@ set -e

echo "::group::changed-files-from-source-file"

IFS=" " read -r -a FILES <<< "$(echo "${INPUT_FILES[@]}" | sort -u | tr "\n" " ")"
RAW_FILES=()

if [[ -n $INPUT_FILES_FROM_SOURCE_FILE ]]; then
for file in $INPUT_FILES_FROM_SOURCE_FILE
do
while read -r fileName; do
FILES+=("$fileName")
RAW_FILES+=("$fileName")
done <"$file"
done
fi

echo "Input Files: ${FILES[*]}"
IFS=" " read -r -a CLEAN_FILES <<< "$(echo "${RAW_FILES[*]}" | tr "\r\n" "\n" | tr " " "\n" | sort -u | awk -v d=" " '{s=(NR==1?s:s d)$0}END{print s}')"

IFS=" " read -r -a ALL_UNIQUE_FILES <<< "$(echo "${FILES[@]}" | tr " " "\n" | sort -u | tr "\n" " ")"
IFS=" " read -r -a CLEAN_INPUT_FILES <<< "$(echo "${INPUT_FILES}" | tr "\r\n" "\n" | tr " " "\n" | sort -u | awk -v d=" " '{s=(NR==1?s:s d)$0}END{print s}')"

echo "All Unique Input files: ${ALL_UNIQUE_FILES[*]}"
FILES=("${CLEAN_FILES[@]}" "${CLEAN_INPUT_FILES[@]}")

IFS=" " read -r -a ALL_UNIQUE_FILES <<< "$(echo "${FILES[@]}" | tr "\r\n" "\n" | tr " " "\n" | sort -u | awk -v d=" " '{s=(NR==1?s:s d)$0}END{print s}')"

echo "Input files: ${ALL_UNIQUE_FILES[*]}"

echo "::set-output name=files::${ALL_UNIQUE_FILES[*]}"

Expand Down
1 change: 1 addition & 0 deletions test/changed-files-list.txt
Expand Up @@ -2,3 +2,4 @@
action.yml
action.yml
action.yml
!*.txt

0 comments on commit 4e8540c

Please sign in to comment.