-
Notifications
You must be signed in to change notification settings - Fork 28
/
Makefile
180 lines (149 loc) · 5.41 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
PKG_PATH = "github.com/containers/podman-tui"
GO := go
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
GOPKGDIR := $(FIRST_GOPATH)/src/$(PKG_PATH)
GOPKGBASEDIR ?= $(shell dirname "$(GOPKGDIR)")
GOBIN := $(shell $(GO) env GOBIN)
BUILDFLAGS := -mod=vendor $(BUILDFLAGS)
BUILDTAGS := "exclude_graphdriver_devicemapper exclude_graphdriver_btrfs btrfs_noversion containers_image_openpgp remote"
COVERAGE_PATH ?= .coverage
TARGET = podman-tui
BIN = ./bin
DESTDIR = /usr/bin
SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)
PKG_MANAGER ?= $(shell command -v dnf yum|head -n1)
PRE_COMMIT = $(shell command -v bin/venv/bin/pre-commit ~/.local/bin/pre-commit pre-commit | head -n1)
GINKO_CLI_VERSION = $(shell grep 'ginkgo/v2' go.mod | grep -o ' v.*' | sed 's/ //g')
# Default to the native OS type and architecture unless otherwise specified
NATIVE_GOOS := $(shell env -u GOOS $(GO) env GOOS)
GOOS ?= $(call err_if_empty,NATIVE_GOOS)
# Default to the native architecture type
NATIVE_GOARCH := $(shell env -u GOARCH $(GO) env GOARCH)
GOARCH ?= $(NATIVE_GOARCH)
.PHONY: default
default: all
.PHONY: all
all: binary binary-win binary-darwin
.PHONY: binary
binary: $(TARGET) ## Build podman-tui binary
@true
.PHONY: $(TARGET)
$(TARGET): $(SRC)
@mkdir -p $(BIN)
@echo "running go build"
@env CGO_ENABLED=0 $(GO) build $(BUILDFLAGS) -o $(BIN)/$(TARGET) -tags $(BUILDTAGS)
.PHONY: binary-win
binary-win: ## Build podman-tui.exe windows binary
@mkdir -p $(BIN)/windows/
@echo "running go build for windows"
@env CGO_ENABLED=0 GOOS=windows GOARCH=$(GOARCH) $(GO) build $(BUILDFLAGS) -o $(BIN)/windows/$(TARGET).exe -tags $(BUILDTAGS)
.PHONY: binary-darwin
binary-darwin: ## Build podman-tui for darwin
@mkdir -p $(BIN)/darwin/
@echo "running go build for darwin"
@env CGO_ENABLED=0 GOOS=darwin GOARCH=$(GOARCH) $(GO) build $(BUILDFLAGS) -o $(BIN)/darwin/$(TARGET) -tags $(BUILDTAGS)
.PHONY: clean
clean:
@rm -rf $(BIN)
.PHONY: install
install: ## Install podman-tui binary
@install ${SELINUXOPT} -D -m0755 $(BIN)/$(TARGET) $(DESTDIR)/$(TARGET)
.PHONY: uninstall
uninstall: ## Uninstall podman-tui binary
@rm -f $(DESTDIR)/$(TARGET)
#=================================================
# Required tools installation tartgets
#=================================================
.PHONY: install.tools
install.tools: .install.ginkgo .install.bats .install.pre-commit .install.codespell .install.golangci-lint ## Install needed tools
.PHONY: .install.ginkgo
.install.ginkgo:
if [ ! -x "$(GOBIN)/ginkgo" ]; then \
$(GO) install -mod=mod github.com/onsi/ginkgo/v2/ginkgo@$(GINKO_CLI_VERSION) ; \
fi
.PHONY: .install.bats
.install.bats:
sudo ${PKG_MANAGER} -y install bats
.PHONY: .install.pre-commit
.install.pre-commit:
if [ -z "$(PRE_COMMIT)" ]; then \
python3 -m pip install --user pre-commit; \
fi
.PHONY: .install.golangci-lint
.install.golangci-lint:
VERSION=1.61.0 ./hack/install_golangci.sh
.PHONY: .install.codespell
.install.codespell:
sudo ${PKG_MANAGER} -y install codespell
#=================================================
# Testing (units, functionality, ...) targets
#=================================================
.PHONY: test
test: test-unit test-functionality
.PHONY: test-unit
test-unit: ## Run unit tests
rm -rf ${COVERAGE_PATH} && mkdir -p ${COVERAGE_PATH}
$(GOBIN)/ginkgo \
-r \
--skip-package test/ \
--cover \
--covermode atomic \
--coverprofile coverprofile \
--output-dir ${COVERAGE_PATH} \
--succinct
$(GO) tool cover -html=${COVERAGE_PATH}/coverprofile -o ${COVERAGE_PATH}/coverage.html
$(GO) tool cover -func=${COVERAGE_PATH}/coverprofile > ${COVERAGE_PATH}/functions
cat ${COVERAGE_PATH}/functions | sed -n 's/\(total:\).*\([0-9][0-9].[0-9]\)/\1 \2/p'
.PHONY: test-functionality
test-functionality: ## Run functionality tests
@bats test/
.PHONY: package
package: ## Build rpm package
rpkg local
.PHONY: package-install
package-install: package ## Install rpm package
sudo ${PKG_MANAGER} -y install ${HOME}/rpmbuild/RPMS/*/*.rpm
/usr/bin/podman-tui version
#=================================================
# Linting/Formatting/Code Validation targets
#=================================================
.PHONY: validate
validate: gofmt lint pre-commit ## Validate podman-tui code (fmt, lint, ...)
.PHONY: vendor
vendor: ## Check vendor
$(GO) mod tidy
$(GO) mod vendor
$(GO) mod verify
@bash ./hack/tree_status.sh
.PHONY: lint
lint: ## Run golangci-lint
@echo "running golangci-lint"
$(BIN)/golangci-lint version
$(BIN)/golangci-lint run
.PHONY: pre-commit
pre-commit: ## Run pre-commit
ifeq ($(PRE_COMMIT),)
@echo "FATAL: pre-commit was not found, make .install.pre-commit to installing it." >&2
@exit 2
endif
$(PRE_COMMIT) run -a
.PHONY: gofmt
gofmt: ## Run gofmt
@echo -e "gofmt check and fix"
@gofmt -w $(SRC)
.PHONY: codespell
codespell: ## Run codespell
@echo "running codespell"
@codespell -S ./vendor,go.mod,go.sum,./.git,*_test.go
_HLP_TGTS_RX = '^[[:print:]]+:.*?\#\# .*$$'
_HLP_TGTS_CMD = grep -E $(_HLP_TGTS_RX) $(MAKEFILE_LIST)
_HLP_TGTS_LEN = $(shell $(_HLP_TGTS_CMD) | cut -d : -f 1 | wc -L)
_HLPFMT = "%-$(_HLP_TGTS_LEN)s %s\n"
.PHONY: help
help: ## Print listing of key targets with their descriptions
@printf $(_HLPFMT) "Target:" "Description:"
@printf $(_HLPFMT) "--------------" "--------------------"
@$(_HLP_TGTS_CMD) | sort | \
awk 'BEGIN {FS = ":(.*)?## "}; \
{printf $(_HLPFMT), $$1, $$2}'