Skip to content

Commit

Permalink
Handle spaces in filenames (#121)
Browse files Browse the repository at this point in the history
* Handle spaces in filenames

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update entrypoint.sh

* Update test.yml

* Update test.yml

* Update test.yml

* Update entrypoint.sh

* Update entrypoint.sh

* Update action.yml

* Update README.md

* Update test.yml
  • Loading branch information
jackton1 authored Nov 25, 2021
1 parent 6114092 commit fda469d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Test sql file 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)
- 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
uses: ./
id: changed_files_not_expected
Expand All @@ -40,11 +54,7 @@ jobs:
- name: Display changed files
if: steps.changed_files_not_expected.outputs.files_changed == 'true'
run: |
echo "Changed files: ${{ steps.changed_files_not_expected.outputs.changed_files }}"
- name: Verify Changes
if: steps.changed_files_not_expected.outputs.files_changed == 'true'
run: |
echo "Changes found: (Not expected)"
echo "Changed files (Not expected): ${{ steps.changed_files_not_expected.outputs.changed_files }}"
exit 1
- name: Make changes
run: |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Support this project with a :star:
| token | `string` | `true` | `${{ github.token }}` <br/> | [GITHUB\_TOKEN](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow) <br /> or a repo scoped <br /> [Personal Access Token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) |
| files | `string[]` OR `string` | `true` | | Check for uncommited changes <br> using only <br> these list of file(s) |
| autocrlf | `string` | `true` | `input` | Modify the [core.autocrlf](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_core_autocrlf) <br> setting possible values <br> (true, false, input). |
| separator | `string` | `true` | `' '` | Output string separator |

## Outputs

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ inputs:
description: Modify the core.autocrlf setting possible values (true, false, input)
default: 'input'
required: true
separator:
description: 'Split character for array output'
required: true
default: " "

outputs:
files_changed:
Expand All @@ -38,6 +42,7 @@ runs:
INPUT_TOKEN: ${{ inputs.token }}
INPUT_FILES: ${{ inputs.files }}
INPUT_AUTO_CRLF: ${{ inputs.autocrlf }}
INPUT_SEPARATOR: ${{ inputs.separator }}
branding:
icon: file-text
Expand Down
25 changes: 15 additions & 10 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,31 @@ FILES=$(echo "${ALL_FILES[*]}" | awk '{gsub(/ /,"\n"); print $0;}' | awk -v d="|

echo "Checking for file changes: \"${FILES}\"..."

STAGED_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 "(${FILES})" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')

# Find unstaged changes
UNSTAGED_FILES+=$(git status --porcelain | awk '{$1=""; print $0 }' | grep -E "(${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}')

CHANGED_FILES=""

if [[ -n "$STAGED_FILES" && -n "$UNSTAGED_FILES" ]]; then
CHANGED_FILES="$STAGED_FILES|$UNSTAGED_FILES"
elif [[ -n "$STAGED_FILES" && -z "$UNSTAGED_FILES" ]]; then
CHANGED_FILES="$STAGED_FILES"
elif [[ -n "$UNSTAGED_FILES" && -z "$STAGED_FILES" ]]; then
CHANGED_FILES="$UNSTAGED_FILES"
if [[ -n "$TRACKED_FILES" && -n "$UNTRACKED_FILES" ]]; then
CHANGED_FILES="$TRACKED_FILES|$UNTRACKED_FILES"
elif [[ -n "$TRACKED_FILES" && -z "$UNTRACKED_FILES" ]]; then
CHANGED_FILES="$TRACKED_FILES"
elif [[ -n "$UNTRACKED_FILES" && -z "$TRACKED_FILES" ]]; then
CHANGED_FILES="$UNTRACKED_FILES"
fi

CHANGED_FILES=$(echo "$CHANGED_FILES" | awk '{gsub(/\|/,"\n"); print $0;}' | sort -u | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')

if [[ -n "$CHANGED_FILES" ]]; then
echo "Found uncommited changes"
echo "---------------"
printf '%s\n' "$(echo $CHANGED_FILES | awk '{gsub(/\|/," "); print $0;}')"
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}')

echo "::set-output name=files_changed::true"
echo "::set-output name=changed_files::$CHANGED_FILES"
else
Expand Down

0 comments on commit fda469d

Please sign in to comment.