Skip to content

Commit

Permalink
feat: bump rules.mk
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Feb 20, 2020
1 parent 0e20210 commit 5def216
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ endif

ifneq ($(wildcard .git/HEAD),)
.PHONY: generate.authors
generate.authors:
generate.authors: AUTHORS
AUTHORS: .git/
echo "# This file lists all individuals having contributed content to the repository." > AUTHORS
echo "# For how it is generated, see 'https://github.com/moul/rules.mk'" >> AUTHORS
echo >> AUTHORS
Expand All @@ -67,7 +68,9 @@ endif
ifdef GOPKG
GO ?= go
GOPATH ?= $(HOME)/go
GOLIBS ?= $(shell find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq)
GO_INSTALL_OPTS ?=
GO_TEST_OPTS ?= -test.timeout=30s

ifdef GOBINS
.PHONY: go.install
Expand All @@ -86,50 +89,56 @@ go.release:
RELEASE_STEPS += go.release
endif

.PHONY: go.unittest
go.unittest:
echo "" > /tmp/coverage.txt
@set -e; for dir in `find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
.PHONY: go.unittest coverage.txt
go.unittest: coverage.txt
coverage.txt:
@rm -f /tmp/coverage.txt
@touch /tmp/coverage.txt
@set -e; for dir in $(GOLIBS); do ( set -xe; \
cd $$dir; \
$(GO) test -v -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...; \
$(GO) test $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...; \
if [ -f /tmp/profile.out ]; then \
cat /tmp/profile.out >> /tmp/coverage.txt; \
rm -f /tmp/profile.out; \
fi); done
mv /tmp/coverage.txt .

.PHONY: go.coverfunc
go.coverfunc: coverage.txt
go tool cover -func=./coverage.txt | grep -v .pb.go: | grep -v .pb.gw.go:

.PHONY: go.lint
go.lint:
@set -e; for dir in `find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
@set -e; for dir in $(GOLIBS); do ( set -xe; \
cd $$dir; \
golangci-lint run --verbose ./...; \
); done

.PHONY: go.tidy
go.tidy:
@set -e; for dir in `find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
@set -e; for dir in $(GOLIBS); do ( set -xe; \
cd $$dir; \
$(GO) mod tidy; \
); done

.PHONY: go.build
go.build:
@set -e; for dir in `find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
@set -e; for dir in $(GOLIBS); do ( set -xe; \
cd $$dir; \
$(GO) build ./...; \
); done

.PHONY: go.bump-deps
go.bumpdeps:
@set -e; for dir in `find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
@set -e; for dir in $(GOLIBS); do ( set -xe; \
cd $$dir; \
$(GO) get -u ./...; \
); done

.PHONY: go.bump-deps
go.fmt:
if ! command -v goimports &>/dev/null; then GO111MODULE=off go get golang.org/x/tools/cmd/goimports; fi
@set -e; for dir in `find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
@set -e; for dir in $(GOLIBS); do ( set -xe; \
cd $$dir; \
goimports -w . \
); done
Expand Down

0 comments on commit 5def216

Please sign in to comment.