diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8a1a2c0..d0013e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,28 +29,30 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Test sql file has no changes an no warning with autocrlf + - name: Test files has no changes an no warning with autocrlf uses: ./ id: changed_files_not_expected_autocrlf with: autocrlf: true files: | - test/new.txt - test/new.sql - test/new/.(sql|txt) + test/*.txt + test/*.sql + test/**/*.txt + test/**/*.sql - name: Display changed files if: steps.changed_files_not_expected_autocrlf.outputs.files_changed == 'true' run: | echo "Changed files (Not expected): ${{ steps.changed_files_not_expected_autocrlf.outputs.changed_files }}" exit 1 - - name: Test sql file has no changes + - name: Test files has no changes uses: ./ id: changed_files_not_expected with: files: | - test/new.txt - test/new.sql - test/new/.(sql|txt) + test/*.txt + test/*.sql + test/**/*.txt + test/**/*.sql - name: Display changed files if: steps.changed_files_not_expected.outputs.files_changed == 'true' run: | @@ -64,9 +66,10 @@ jobs: id: changed_files_expected with: files: | - test/new.txt - test/new.sql - test/new/.(sql|txt) + test/*.txt + test/*.sql + test/**/*.txt + test/**/*.sql - name: Display changed files if: steps.changed_files_expected.outputs.files_changed == 'true' run: | diff --git a/README.md b/README.md index ad9566c..daa979f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Verify that certain files or directories did or did not change during the workfl * Boolean output for detecting uncommited changes. * List all files that changed during the workflow execution. * Restrict change detection to a subset of files. - * [Regex pattern](https://www.gnu.org/software/grep/manual/grep.html#Regular-Expressions) matching on a subset of files. + * Using [Glob pattern](https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet) matching. ## Usage @@ -50,11 +50,12 @@ Verify that certain files or directories did or did not change during the workfl id: verify-changed-files with: files: | - new.txt + *.txt test_directory - .(py|jpeg)$ - \.sql$ - ^(mynewfile|custom) + action.yml + **/*.py + **/*.jpeg + *.sql - name: Run step only when files change. if: steps.verify-changed-files.outputs.files_changed == 'true' diff --git a/action.yml b/action.yml index b498095..4e0b2b1 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,12 @@ outputs: runs: using: 'composite' steps: + - name: Glob match + uses: tj-actions/glob@v7.4 + id: glob + with: + files: ${{ inputs.files }} + separator: "|" - run: | bash $GITHUB_ACTION_PATH/entrypoint.sh id: verify-changed-files @@ -39,7 +45,7 @@ runs: # INPUT_ is not available in Composite run steps # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 INPUT_TOKEN: ${{ inputs.token }} - INPUT_FILES: ${{ inputs.files }} + INPUT_FILES: ${{ steps.glob.outputs.paths }} INPUT_AUTO_CRLF: ${{ inputs.autocrlf }} INPUT_SEPARATOR: ${{ inputs.separator }} diff --git a/entrypoint.sh b/entrypoint.sh index c2c8b0e..a00cb1f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,16 +4,12 @@ set -e git config --local core.autocrlf "$INPUT_AUTO_CRLF" -IFS=" " read -r -a ALL_FILES <<< "$(echo "${INPUT_FILES[@]}" | sort -u | tr "\n" " ")" +echo "Checking for file changes: \"${INPUT_FILES}\"..." -FILES=$(echo "${ALL_FILES[*]}" | awk '{gsub(/ /,"\n"); print $0;}' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') - -echo "Checking for file changes: \"${FILES}\"..." - -TRACKED_FILES=$(git diff --diff-filter=ACMUXTR --name-only | grep -E "(${FILES})" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') +TRACKED_FILES=$(git diff --diff-filter=ACMUXTR --name-only | grep -E "(${INPUT_FILES})" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') # Find untracked changes -UNTRACKED_FILES=$(git ls-files --others --exclude-standard | grep -E "(${FILES})" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') +UNTRACKED_FILES=$(git ls-files --others --exclude-standard | grep -E "(${INPUT_FILES})" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') CHANGED_FILES=""