-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
96 lines (77 loc) · 2.59 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# `make`, with no args, should do most of the things, assuming go is installed.
# it must be run from the project repository's base directory.
MAKEFLAGS += --warn-undefined-variables
VERBOSE = -v
GOCMD = go
GOFMT = gofmt
GOMOD = $(GOCMD) mod
GOBUILD = $(GOCMD) build
GOCLEAN = $(GOCMD) clean
GOTEST = $(GOCMD) test
GOINSTALL = $(GOCMD) install
CMDDIR = cmd
DISTDIR = dist
TARGET = terrajux
MAIN = $(CMDDIR)/$(TARGET)/main.go
SOURCES = $(wildcard **/*.go)
GOFMTL = $(shell $(GOFMT) -l .)
.PHONY: tools clean tidy test unit static snapshot release check mod-outdated help
# don't `tidy` by default or `tools` will break
all: check clean tools test build
help:
# all: do the needful (default, try this first)
# check: pre-flight check
# clean: clean up targets, object code, test cache, etc.
# tidy: go mod tidy
# tools: install packages needed for test and release
# test: run all tests
# unit: run go test
# static: run static analysis tests (lint, security, etc.)
# snapshot: build a release snapshot of the current working directory
# release: build a release from the tag of the current checkout
# mod-outdated: list direct module dependencies with available upgrades
check:
ifeq ($(strip $(DISTDIR)),)
$(error DISTDIR must be a non-empty value. a bug may exist in the Makefile)
endif
$(GOCMD) version
$(DISTDIR):
mkdir -p $(DISTDIR)
$(DISTDIR)/$(TARGET): $(DISTDIR) $(SOURCES) test
$(GOBUILD) $(VERBOSE) -o $(DISTDIR)/$(TARGET) $(MAIN)
clean: check
$(GOCLEAN) $(VERBOSE)
$(GOCLEAN) $(VERBOSE) -testcache
rm -rf ./$(DISTDIR)/
tools: check $(DISTDIR)/tools-stamp
$(DISTDIR)/tools-stamp: $(DISTDIR)
$(GOINSTALL) $(VERBOSE) github.com/securego/gosec/v2/cmd/gosec@latest
ifneq ($(strip $(CI)),true)
$(GOINSTALL) $(VERBOSE) github.com/goreleaser/goreleaser@latest
$(GOINSTALL) $(VERBOSE) github.com/golangci/golangci-lint/cmd/golangci-lint@latest
else
$(warning CI=$(CI): skip installing golangci-lint+goreleaser, will run as GitHub Action)
endif
touch $@
test: tools static unit
static: check tools $(SOURCES)
ifneq ($(strip $(GOFMTL)),)
$(error invalid formatting detected. please run `go fmt ./...`)
endif
ifneq ($(strip $(CI)),true)
golangci-lint run
else
$(warning CI=$(CI): skip golangci-lint, will run as GitHub Action)
endif
gosec ./...
unit: check tools $(SOURCES)
$(GOTEST) $(VERBOSE) ./...
build: check $(DISTDIR)/$(TARGET)
tidy: check
$(GOMOD) tidy
release: tools $(SOURCES)
goreleaser --rm-dist
snapshot: tools $(SOURCES)
goreleaser --snapshot --rm-dist
mod-outdated:
go list -u -m -f '{{if not .Indirect}}{{.}}{{end}}' all