Skip to content

Commit fda469d

Browse files
authored
Handle spaces in filenames (#121)
* 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
1 parent 6114092 commit fda469d

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

.github/workflows/test.yml

+15-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ jobs:
2929
steps:
3030
- name: Checkout
3131
uses: actions/checkout@v2
32+
- name: Test sql file has no changes an no warning with autocrlf
33+
uses: ./
34+
id: changed_files_not_expected_autocrlf
35+
with:
36+
autocrlf: true
37+
files: |
38+
test/new.txt
39+
test/new.sql
40+
test/new/.(sql|txt)
41+
- name: Display changed files
42+
if: steps.changed_files_not_expected_autocrlf.outputs.files_changed == 'true'
43+
run: |
44+
echo "Changed files (Not expected): ${{ steps.changed_files_not_expected_autocrlf.outputs.changed_files }}"
45+
exit 1
3246
- name: Test sql file has no changes
3347
uses: ./
3448
id: changed_files_not_expected
@@ -40,11 +54,7 @@ jobs:
4054
- name: Display changed files
4155
if: steps.changed_files_not_expected.outputs.files_changed == 'true'
4256
run: |
43-
echo "Changed files: ${{ steps.changed_files_not_expected.outputs.changed_files }}"
44-
- name: Verify Changes
45-
if: steps.changed_files_not_expected.outputs.files_changed == 'true'
46-
run: |
47-
echo "Changes found: (Not expected)"
57+
echo "Changed files (Not expected): ${{ steps.changed_files_not_expected.outputs.changed_files }}"
4858
exit 1
4959
- name: Make changes
5060
run: |

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Support this project with a :star:
104104
| 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) |
105105
| files | `string[]` OR `string` | `true` | | Check for uncommited changes <br> using only <br> these list of file(s) |
106106
| 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). |
107+
| separator | `string` | `true` | `' '` | Output string separator |
107108

108109
## Outputs
109110

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ inputs:
1313
description: Modify the core.autocrlf setting possible values (true, false, input)
1414
default: 'input'
1515
required: true
16+
separator:
17+
description: 'Split character for array output'
18+
required: true
19+
default: " "
1620

1721
outputs:
1822
files_changed:
@@ -38,6 +42,7 @@ runs:
3842
INPUT_TOKEN: ${{ inputs.token }}
3943
INPUT_FILES: ${{ inputs.files }}
4044
INPUT_AUTO_CRLF: ${{ inputs.autocrlf }}
45+
INPUT_SEPARATOR: ${{ inputs.separator }}
4146
4247
branding:
4348
icon: file-text

entrypoint.sh

+15-10
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,31 @@ FILES=$(echo "${ALL_FILES[*]}" | awk '{gsub(/ /,"\n"); print $0;}' | awk -v d="|
1010

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

13-
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}')
13+
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}')
1414

15-
# Find unstaged changes
16-
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}'
15+
# Find untracked changes
16+
UNTRACKED_FILES=$(git ls-files --others --exclude-standard | grep -E "(${FILES})" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
1717

1818
CHANGED_FILES=""
1919

20-
if [[ -n "$STAGED_FILES" && -n "$UNSTAGED_FILES" ]]; then
21-
CHANGED_FILES="$STAGED_FILES|$UNSTAGED_FILES"
22-
elif [[ -n "$STAGED_FILES" && -z "$UNSTAGED_FILES" ]]; then
23-
CHANGED_FILES="$STAGED_FILES"
24-
elif [[ -n "$UNSTAGED_FILES" && -z "$STAGED_FILES" ]]; then
25-
CHANGED_FILES="$UNSTAGED_FILES"
20+
if [[ -n "$TRACKED_FILES" && -n "$UNTRACKED_FILES" ]]; then
21+
CHANGED_FILES="$TRACKED_FILES|$UNTRACKED_FILES"
22+
elif [[ -n "$TRACKED_FILES" && -z "$UNTRACKED_FILES" ]]; then
23+
CHANGED_FILES="$TRACKED_FILES"
24+
elif [[ -n "$UNTRACKED_FILES" && -z "$TRACKED_FILES" ]]; then
25+
CHANGED_FILES="$UNTRACKED_FILES"
2626
fi
2727

28+
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}')
29+
2830
if [[ -n "$CHANGED_FILES" ]]; then
2931
echo "Found uncommited changes"
3032
echo "---------------"
31-
printf '%s\n' "$(echo $CHANGED_FILES | awk '{gsub(/\|/," "); print $0;}')"
33+
echo "$CHANGED_FILES" | awk '{gsub(/\|/,"\n"); print $0;}'
3234
echo "---------------"
35+
36+
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}')
37+
3338
echo "::set-output name=files_changed::true"
3439
echo "::set-output name=changed_files::$CHANGED_FILES"
3540
else

0 commit comments

Comments
 (0)