Skip to content

Commit

Permalink
Merge pull request #1 from Rotendahl/test-action
Browse files Browse the repository at this point in the history
Make option for excluding directories
  • Loading branch information
erclu authored Sep 22, 2020
2 parents d7d8f63 + 9a126c0 commit 80bfd16
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 25 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test this action

on: push

jobs:
test:
name: Test action
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- run: |
sh test.sh
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:
path: ./a-custom-path
```
## Contributors
Most of the work was done by @Rotendahl, I mainly copy-pasted stuff from stack overflow :)
<!--
TODO check if it's possible to use the virtual host bash instead of docker
TODO rewrite using js (better performance)
-->
10 changes: 5 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ runs:
image: "Dockerfile"
args:
- ${{ inputs.path }}
- ${{ inputs.exclude }}

inputs:
path:
description: Path to check
required: false
default: "."
#
# # TODO return exact number?
# outputs:
# files-found:
# description: Number of files with CRLF endings
exclude:
description: Space-separated list of dirs to exclude
required: false
default: ""
41 changes: 22 additions & 19 deletions entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
echo "searching for CRLF endings in: $1"
#!/bin/bash

printf "searching for CRLF endings in: $1\n"
# TODO allow multiple paths with $@ instead of $1

BOLD_RED='\033[1;31m'
BOLD_GREEN='\033[1;32m'
NC='\033[0m'

ERROR_COUNT=0
FILES_TYPES="$(\
find . ! -path "./.git/*" -not -type d -exec file "{}" ";"
)"

if \
grep \
--recursive \
--files-with-matches \
--binary \
--binary-files=without-match \
--max-count=1 \
--exclude-dir="\.git" \
$'\r' \
$1 \
; then
# TODO exit status should be number of files with wrong endings found
echo -e "${BOLD_RED}Found at least a file with CRLF endings.${NC}"
exit 1
fi
FILES_WITH_CRLF=$(echo "$FILES_TYPES" | grep " CRLF " | cut -d " " -f 1 | cut -d ":" -f 1)

echo -e "${BOLD_GREEN}No files with CRLF endings found.${NC}"
exit 0
for word in $2
do
FILES_WITH_CRLF=$(echo "$FILES_WITH_CRLF" | grep "^./$word" --invert-match)
done

if [ -z "$FILES_WITH_CRLF" ]
then
echo "${BOLD_GREEN}No files with CRLF endings found.${NC}"
exit 0
else
NR_FILES=$(echo "$FILES_WITH_CRLF" | wc -l)
echo "${BOLD_RED}Found $NR_FILES files with CRLF endings.${NC}"
echo "$FILES_WITH_CRLF"
exit $NR_FILES
fi
18 changes: 18 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# this is a sorry excuse for a test, but hey, it kinda works

mkdir -p "temp"

printf "\r\n" > "temp/bad"
printf "\r\n" > "temp/ignored"
printf "\n" > "temp/good"

./entrypoint.sh . "temp/ignored"

RESULT="$?"

rm -r "temp"

# is there a better way to do this?
[ $RESULT -eq 1 ]
exit $?

0 comments on commit 80bfd16

Please sign in to comment.