From c4322970b4f055ede155b95586b04562796f83b7 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 22 Aug 2022 22:57:27 -0600 Subject: [PATCH] feat: switch to use pattern file and fixed bug with excluded paths (#202) --- .github/workflows/test.yml | 24 ++++++++++++++++++++++++ action.yml | 4 ++-- entrypoint.sh | 15 ++++++--------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a13e56..453daeb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -97,3 +97,27 @@ jobs: run: | echo "No Changes found: (Not expected)" exit 1 + - name: Test unstaged file changes are ignored + uses: ./ + id: changed_unstaged_files_not_expected + with: + files: | + !test/new.txt + !unstaged.txt + - name: Verify Changes to unstaged.txt are ignored + if: steps.changed_unstaged_files_not_expected.outputs.files_changed != 'false' + run: | + echo "Changes found: (Not expected)" + exit 1 + - name: Test unstaged file has changes + uses: ./ + id: changed_unstaged2_files_expected + with: + files: | + !test/new.txt + unstaged.txt + - name: Verify Changes to unstaged.txt are ignored + if: steps.changed_unstaged2_files_expected.outputs.files_changed != 'true' + run: | + echo "No Changes found: (Not expected)" + exit 1 diff --git a/action.yml b/action.yml index f251237..c3c53ec 100644 --- a/action.yml +++ b/action.yml @@ -26,7 +26,7 @@ runs: using: 'composite' steps: - name: Glob match - uses: tj-actions/glob@v11 + uses: tj-actions/glob@v12 id: glob with: files: ${{ inputs.files }} @@ -40,7 +40,7 @@ runs: GITHUB_REPOSITORY: ${{ github.repository }} # INPUT_ is not available in Composite run steps # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 - INPUT_FILES: ${{ steps.glob.outputs.paths }} + INPUT_FILES_PATTERN_FILE: ${{ steps.glob.outputs.paths-output-file }} INPUT_AUTO_CRLF: ${{ inputs.autocrlf }} INPUT_SEPARATOR: ${{ inputs.separator }} diff --git a/entrypoint.sh b/entrypoint.sh index c533df1..276dffa 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,15 +2,15 @@ set -e +echo "::group::verify-changed-files" + git config --local core.autocrlf "$INPUT_AUTO_CRLF" -if [[ -n "$INPUT_FILES" ]]; then - echo "Checking for file changes: \"${INPUT_FILES}\"..." - - TRACKED_FILES=$(git diff --diff-filter=ACMUXTRD --name-only | grep -E "(${INPUT_FILES})" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') +if [[ -n "$INPUT_FILES_PATTERN_FILE" ]]; then + TRACKED_FILES=$(git diff --diff-filter=ACMUXTRD --name-only | grep -x -E -f "$INPUT_FILES_PATTERN_FILE" | 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 "(${INPUT_FILES})" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') + UNTRACKED_FILES=$(git ls-files --others --exclude-standard | grep -x -E -f "$INPUT_FILES_PATTERN_FILE" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') else TRACKED_FILES=$(git diff --diff-filter=ACMUXTRD --name-only | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') @@ -32,9 +32,6 @@ CHANGED_FILES=$(echo "$CHANGED_FILES" | awk '{gsub(/\|/,"\n"); print $0;}' | so if [[ -n "$CHANGED_FILES" ]]; then echo "Found uncommited changes" - echo "---------------" - echo "$CHANGED_FILES" | awk '{gsub(/\|/,"\n"); print $0;}' - echo "---------------" CHANGED_FILES=$(echo "$CHANGED_FILES" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') @@ -45,4 +42,4 @@ else echo "::set-output name=files_changed::false" fi -exit 0; +echo "::endgroup::"