Skip to content

Commit

Permalink
makefile: Add whitespace check
Browse files Browse the repository at this point in the history
Signed-off-by: Or Shoval <oshoval@redhat.com>
  • Loading branch information
oshoval committed Dec 6, 2022
1 parent ad7d075 commit 5df687d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ jobs:
uses: actions/checkout@v2
- name: Run unit tests
run: make test
whitespace-check:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Run whitespace check
run: make whitespace-check
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ create-nodeport:
bump-kubevirtci:
./hack/bump-kubevirtci.sh

whitespace:
./hack/whitespace.sh --fix

whitespace-check:
./hack/whitespace.sh

vendor: $(GO)
$(GO) mod tidy
$(GO) mod vendor
Expand All @@ -86,5 +92,7 @@ vendor: $(GO)
cluster-clean \
create-nodeport \
bump-kubevirtci \
whitespace \
whitespace-check \
vendor

23 changes: 23 additions & 0 deletions hack/whitespace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

function fix() {
git ls-files -- ':!vendor/' | xargs sed --follow-symlinks -i 's/[[:space:]]*$//'
}

function check() {
invalid_files=$(git ls-files -- ':!vendor/' | xargs egrep -Hn " +$" || true)
if [[ $invalid_files ]]; then
echo 'Found trailing whitespaces. Please remove trailing whitespaces using `make fmt`:'
echo "$invalid_files"
return 1
fi
}

if [ "$1" == "--fix" ]; then
fix
else
check
fi

0 comments on commit 5df687d

Please sign in to comment.