From 4e27c2e1f47829fe080ef358844fbabe1592a2fb Mon Sep 17 00:00:00 2001 From: "Bora M. Alper" Date: Fri, 27 Nov 2020 19:49:26 +0000 Subject: [PATCH] fix Makefile and go.yml --- .github/workflows/go.yml | 7 +++++-- Makefile | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0e7f53d..bde7ce1 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,7 +7,6 @@ on: branches: [ master ] jobs: - build: name: Build runs-on: ubuntu-latest @@ -33,7 +32,11 @@ jobs: - name: Test run: | make test - + - name: Lint + run: | + make staticcheck + + - name: Check Formatting run: | make check-formatting diff --git a/Makefile b/Makefile index 43ebceb..c1bf77d 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,17 @@ format: # Because `read` is a bash command. # https://stackoverflow.com/a/589300/4466589 # +# How to ignore bindata.go +# Due to irrational insistence of some Go developers, gofmt, like many +# other tools of Go ecosystem, does not have flags for common scenarios +# such as ignoring certain files by pattern etc. Thus we use `go list` +# and grep together to achieve the desired result. +# +# The original query is this: +# gofmt -l $(go list -f $'{{range .GoFiles}}{{$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go) +# +# The original query is then escaped for Makefile (by repeating dollar signs $ -> $$). check-formatting: SHELL:=/bin/bash # HERE: this is setting the shell for check-formatting only check-formatting: - ! gofmt -l ./cmd/ 2>&1 | tee /dev/fd/2 | read - ! gofmt -l ./pkg/ 2>&1 | tee /dev/fd/2 | read + ! gofmt -l $$(go list -f $$'{{range .GoFiles}}{{$$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go) 2>&1 | tee /dev/fd/2 | read + ! gofmt -l $$(go list -f $$'{{range .GoFiles}}{{$$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go) 2>&1 | tee /dev/fd/2 | read