Update: I’m now shamelessly hooked on PHONY Makefiles now just because of the completion. It’s just so simple. The drug of tab completion makes the reality of unnecessary complexity in a Makefile somehow palatable. The addiction is real.
SuperTorpedo suggested that the reason for unnecessary Makefiles that could more sustainably, safely, and easily be written as shell scripts are so prevalent: make <TAB>
completes the different possibilities (for people who don’t know about complete -C
). I could almost be convinced that is enough reason if the project may someday have something that actually warrants the use of make
(build chain dependencies like with C dynamically linked libraries, which is why make
was created).
Here’s a sample of what I mean by “unnecessary”:
dev_build_version=$(shell git describe --tags --always --dirty)
export PATH := $(shell pwd)/.tmp/protoc/bin:$(PATH)
export PROTOC_VERSION := 22.0
# TODO: run golint and errcheck, but only to catch *new* violations and
# decide whether to change code or not (e.g. we need to be able to whitelist
# violations already in the code). They can be useful to catch errors, but
# they are just too noisy to be a requirement for a CI -- we don't even *want*
# to fix some of the things they consider to be violations.
.PHONY: ci
ci: deps checkgofmt checkgenerate vet staticcheck ineffassign predeclared test
.PHONY: deps
deps:
go get -d -v -t ./...
.PHONY: updatedeps
updatedeps:
go get -d -v -t -u -f ./...
.PHONY: install
install:
go install -ldflags '-X "main.version=dev build $(dev_build_version)"' ./...
.PHONY: release
release:
@go install github.com/goreleaser/goreleaser@v1.5.0
goreleaser release --rm-dist
.PHONY: docker
docker:
@echo $(dev_build_version) > VERSION
docker build -t fullstorydev/grpcurl:$(dev_build_version) .
@rm VERSION
.PHONY: generate
generate: .tmp/protoc/bin/protoc
@go install google.golang.org/protobuf/cmd/protoc-gen-go@a709e31e5d12
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
go generate ./...
.PHONY: checkgenerate
checkgenerate: generate
git status --porcelain
@if [ -n "$$(git status --porcelain)" ]; then \
exit 1; \
fi
.PHONY: checkgofmt
checkgofmt:
gofmt -s -l .
@if [ -n "$$(gofmt -s -l .)" ]; then \
exit 1; \
fi
.PHONY: vet
vet:
go vet ./...
.PHONY: staticcheck
staticcheck:
@go install honnef.co/go/tools/cmd/staticcheck@v0.4.3
staticcheck ./...
.PHONY: ineffassign
ineffassign:
@go install github.com/gordonklaus/ineffassign@7953dde2c7bf
ineffassign .
.PHONY: predeclared
predeclared:
@go install github.com/nishanths/predeclared@5f2f810c9ae6
predeclared ./...
# Intentionally omitted from CI, but target here for ad-hoc reports.
.PHONY: golint
golint:
@go install golang.org/x/lint/golint@v0.0.0-20210508222113-6edffad5e616
golint -min_confidence 0.9 -set_exit_status ./...
# Intentionally omitted from CI, but target here for ad-hoc reports.
.PHONY: errcheck
errcheck:
@go install github.com/kisielk/errcheck@v1.2.0
errcheck ./...
.PHONY: test
test:
go test -race ./...
.tmp/protoc/bin/protoc: ./Makefile ./download_protoc.sh
./download_protoc.sh