-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
76 lines (59 loc) · 2.14 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
PREFIX?=$(shell pwd)
NAME := pomerium-cli
PKG := github.com/pomerium/cli
BUILDDIR := ${PREFIX}/dist
BINDIR := ${PREFIX}/bin
GITCOMMIT := $(shell git rev-parse --short HEAD)
BUILDMETA:=
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GITUNTRACKEDCHANGES),)
BUILDMETA := dirty
endif
# Keep cgo disabled on Linux, to avoid the cgo version of the Go standard
# library 'net' package. On macOS and Windows we need cgo for the system cert
# store integrations, but as of Go 1.20 the 'net' package does not use cgo on
# macOS, and the 'net' package never used cgo on Windows (see
# https://go.dev/doc/go1.20#cgo).
ifeq ($(shell uname),Linux)
export CGO_ENABLED=0
endif
CTIMEVAR=-X $(PKG)/version.GitCommit=$(GITCOMMIT) \
-X $(PKG)/version.BuildMeta=$(BUILDMETA) \
-X $(PKG)/version.ProjectName=$(NAME) \
-X $(PKG)/version.ProjectURL=$(PKG)
GO ?= "go"
GO_LDFLAGS=-ldflags "-s -w $(CTIMEVAR)"
GOOSARCHES = linux/amd64 darwin/amd64 windows/amd64
.PHONY: all
all: clean lint test build
.PHONY: test
test: ## test everything
go test ./...
.PHONY: lint
lint:
@echo "@==> $@"
@VERSION=$$(go run github.com/mikefarah/yq/[email protected] '.jobs.lint.steps[] | select(.uses == "golangci/golangci-lint-action*") | .with.version' .github/workflows/lint.yml) && \
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$$VERSION run ./...
.PHONY: tidy
tidy: ## run go mod tidy
go mod tidy -compat=1.19
.PHONY: tools
tools: ## generate protobuff files
go install google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
buf generate
.PHONY: clean
clean: ## Cleanup any build binaries or packages.
@echo "==> $@"
$(RM) -r $(BINDIR)
$(RM) -r $(BUILDDIR)
.PHONY: build
build: ## Build everything.
@echo "==> $@"
@go build -tags "$(BUILDTAGS)" $(GO_LDFLAGS) -o $(BINDIR)/$(NAME) ./cmd/"$(NAME)"
.PHONY: snapshot
snapshot: ## Create release snapshot
APPARITOR_GITHUB_TOKEN=foo VERSION_FLAGS="$(CTIMEVAR)" goreleaser release --snapshot --rm-dist
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'