forked from aziontech/azion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
106 lines (88 loc) · 3.04 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
GO := $(shell which go)
PATH := $(dir $(GO)):$(PATH)
SHELL := env PATH=$(PATH) /bin/bash
NAME := azion
ifeq (, $(GO))
$(error "No go binary found in your system, please install go 1.17 before continuing")
endif
GOPATH ?= $(shell $(GO) env GOPATH)
GOBIN ?= $(GOPATH)/bin
GOSEC ?= $(GOBIN)/gosec
GOLINT ?= $(GOBIN)/golint
GOFMT ?= $(GOBIN)/gofmt
RELOAD ?= $(GOBIN)/CompileDaemon
# Variables for token endpoints
ENVFILE ?= ./env/prod
BIN := azion
# Version Info
BIN_VERSION=$(shell git describe --tags)
# The variables with $$ should be sourced from an envfile
LDFLAGS=-X github.com/aziontech/azion-cli/pkg/cmd/version.BinVersion=$(BIN_VERSION) \
-X github.com/aziontech/azion-cli/pkg/constants.StorageApiURL=$$STORAGE_URL \
-X github.com/aziontech/azion-cli/pkg/constants.AuthURL=$$AUTH_URL \
-X github.com/aziontech/azion-cli/pkg/constants.ApiURL=$$API_URL \
-X github.com/aziontech/azion-cli/pkg/cmd/edge_applications/init.TemplateBranch=$$TEMPLATE_BRANCH \
-X github.com/aziontech/azion-cli/pkg/cmd/edge_applications/init.TemplateMajor=$$TEMPLATE_MAJOR
LDFLAGS_STRIP=-s -w
NAME_WITH_VERSION=$(NAME)-$(BIN_VERSION)
.PHONY : all
all: deps build
.PHONY : deps
deps: ## verify projects dependencies
@ $(GO) env -w GOPRIVATE=github.com/aziontech/*
@ $(GO) mod verify
@ $(GO) mod tidy
.PHONY : clean
clean: ## delete additional files
@ rm -rf cover
.PHONY: lint
lint: get-lint-deps ## running GoLint
@ $(GOBIN)/golangci-lint run ./... --verbose
.PHONY: dev
dev: dev-deps
$(RELOAD) -build 'make build' -exclude-dir '.git'
.PHONY: dev-deps
dev-deps:
$(GO) install github.com/githubnemo/[email protected]
.PHONY: get-lint-deps
get-lint-deps:
@if [ ! -x $(GOBIN)/golangci-lint ]; then\
curl -sfL \
https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.54.1 ;\
fi
.PHONY: test
test:
@ echo Running GO tests
@ mkdir -p cover
@$(GO) test -v -failfast -coverprofile "./cover/$(NAME)coverage.out" -coverpkg=./... ./...
@$(GO) tool cover -html="./cover/$(NAME)coverage.out" -o ./cover/$(NAME)coverage.html
@$(GO) tool cover -func "./cover/$(NAME)coverage.out"
@echo Done
.PHONY: docs
docs:
$(GO) run ./cmd/gen_docs/main.go --doc-path ./docs --file-type md
.PHONY: sec
sec: get-gosec-deps ## running GoSec
@ -$(GOSEC) ./...
.PHONY: get-gosec-deps
get-gosec-deps:
@ cd $(GOPATH); \
$(GO) get -u github.com/securego/gosec/cmd/gosec
.PHONY : build
build: ## build application
@ $(GO) version
@ source $(ENVFILE) && $(GO) build -ldflags "$(LDFLAGS)" -o ./bin/$(NAME) ./cmd/$(BIN)
.PHONY : cross-build
cross-build: ## cross-compile for all platforms/architectures.
@ $(GO) version
set -e;\
source $(ENVFILE); \
while read spec; \
do\
distro=$$(echo $${spec} | cut -d/ -f1);\
goarch=$$(echo $${spec} | cut -d/ -f2);\
arch=$$(echo $${goarch} | sed 's/386/x86_32/g; s/amd64/x86_64/g; s/arm$$/arm32/g');\
echo $$distro/$$arch;\
mkdir -p dist/$$distro/$$arch;\
CGO_ENABLED=0 GOOS=$$distro GOARCH=$$goarch $(GO) build -ldflags "$(LDFLAGS)" -o ./dist/$$distro/$$arch/$(NAME_WITH_VERSION) ./cmd/$(BIN); \
done < BUILD