Skip to content

Commit

Permalink
Extend makefile with 'make goimports' target
Browse files Browse the repository at this point in the history
So the target can be run in CI and fail in case files are not properly goimport formated.
  • Loading branch information
ingvagabund committed Aug 21, 2019
1 parent 117d609 commit 4f0751a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ lint: ## Go lint your code
fmt: ## Go fmt your code
hack/go-fmt.sh .

.PHONY: goimports
goimports: ## Go fmt your code
hack/goimports.sh .

.PHONY: vet
vet: ## Apply go vet to all go files
hack/go-vet.sh ./...
Expand Down
16 changes: 16 additions & 0 deletions hack/goimports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

REPO_NAME=$(basename "${PWD}")
if [ "$IS_CONTAINER" != "" ]; then
for TARGET in "${@}"; do
find "${TARGET}" -name '*.go' ! -path '*/vendor/*' ! -path '*/.build/*' -exec goimports -w {} \+
done
git diff --exit-code
else
docker run -it --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/go/src/sigs.k8s.io/${REPO_NAME}:z" \
--workdir "/go/src/sigs.k8s.io/${REPO_NAME}" \
openshift/origin-release:golang-1.12 \
./hack/goimports.sh "${@}"
fi

0 comments on commit 4f0751a

Please sign in to comment.