forked from rhdhorchestrator/serverless-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
48 lines (36 loc) · 1.13 KB
/
check-whitespace.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
name: Check trailing white spaces before merge
on:
pull_request:
push:
branches: [ "main" ]
paths:
- .github/workflows/check-whitespace.yaml
- '**/application.properties'
jobs:
check-whitespace:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get Changed Files
run: |
git diff --name-only ${{ github.event.before }} ${{ github.sha }} > changed_files.txt
- name: Check white spaces scripts
run: |
CHANGED_FILES="${{ steps.changed-files.outputs.files }}"
tw_lines=""
for file in $CHANGED_FILES
do
lines=$(egrep -rnIH " +$" $file | cut -f-2 -d ":")
if [ ! -z "$lines" ]; then
tw_lines+=$([[ -z "$tw_lines" ]] && echo "$lines" || echo $'\n'"$lines")
fi
done
exit_code=0
# If tw_lines is not empty, change the exit code to 1 to fail the CI.
if [ ! -z "$tw_lines" ]; then
echo -e "\n***** Lines containing trailing whitespace *****\n"
echo -e "${tw_lines[@]}"
echo -e "\nFailed.\n"
exit_code=1
fi
exit $exit_code