Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch to use pattern file and fixed bug with excluded paths #202

Merged
merged 10 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -40,7 +40,7 @@ runs:
GITHUB_REPOSITORY: ${{ github.repository }}
# INPUT_<VARIABLE_NAME> 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 }}

Expand Down
15 changes: 6 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

Expand All @@ -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}')

Expand All @@ -45,4 +42,4 @@ else
echo "::set-output name=files_changed::false"
fi

exit 0;
echo "::endgroup::"