-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
73 lines (55 loc) · 2.07 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
include project.mk
include boilerplate/generated-includes.mk
SHELL := /usr/bin/env bash
# Verbosity
AT_ = @
AT = $(AT_$(V))
# /Verbosity
GIT_HASH := $(shell git rev-parse --short=7 HEAD)
BINARY_FILE ?= build/_output/compliance-audit-router
GO_SOURCES := $(find $(CURDIR) -type f -name "*.go" -print)
EXTRA_DEPS := $(find $(CURDIR)/build -type f -print) Makefile
# Containers may default GOFLAGS=-mod=vendor which would break us since
# we're using modules.
unexport GOFLAGS
GOOS?=linux
GOARCH?=amd64
GOENV=GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 GOFLAGS=
GOBUILDFLAGS=-gcflags="all=-trimpath=${GOPATH}" -asmflags="all=-trimpath=${GOPATH}"
TESTOPTS ?=-v
.PHONY: test
test: vet $(GO_SOURCES)
$(AT)go test $(TESTOPTS) $(shell go list -mod=readonly -e ./...)
.PHONY: clean
clean:
$(AT)rm -f $(BINARY_FILE)
.PHONY: serve
serve:
$(AT)go run ./cmd/main.go
.PHONY: vet
vet:
$(AT)gofmt -s -l $(shell go list -f '{{ .Dir }}' ./... ) | grep ".*\.go"; if [ "$$?" = "0" ]; then gofmt -s -d $(shell go list -f '{{ .Dir }}' ./... ); exit 1; fi
$(AT)go vet ./cmd/... ./pkg/...
.PHONY: build
build: $(BINARY_FILE)
$(BINARY_FILE): $(GO_SOURCES)
mkdir -p $(shell dirname $(BINARY_FILE))
$(GOENV) go build $(GOBUILDFLAGS) -o $(BINARY_FILE) ./cmd
# This is a helper for local development, not to be used for CI/CD
.PHONY: build-image
build-image: isclean
${CONTAINER_ENGINE} build -f $(DOCKERFILE) -t $(IMAGE_NAME):$(IMAGE_TAG) .
${CONTAINER_ENGINE} tag $(IMAGE_NAME):$(IMAGE_TAG) $(IMAGE_NAME):latest
.PHONY: boilerplate-update
boilerplate-update:
@boilerplate/update
# Just a helper to list all available make targets
.PHONY: list
list:
@LC_ALL=C $(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/(^|\n)# Files(\n|$$)/,/(^|\n)# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | grep -E -v -e '^[^[:alnum:]]' -e '^$@$$'
# Helper to ensure license text
# Requires https://github.com/google/addlicense
# `go install github.com/google/addlicense@latest`
.PHONY: license
license:
@addlicense -c "Red Hat, Inc." -l apache -v -y 2021-2024 .*go **/*.go **/**/*.go