forked from young-yang03/cloud-mta-build-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
151 lines (122 loc) · 4.68 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
# Make build for local usage
# The artifact is bin for each OS and copied to the go/bin dir
# Execute go generate to generate files to *.go to inclue as binary
# Execute go build
# Copy files to machine go/bin folder (temp target to avoid manual steps when developing locally)
all:format clean dir gen build-linux build-linux-arm build-darwin build-darwin-arm build-windows install-cyclonedx install-pkg install-micromatch-wrapper copy tests
.PHONY: build-darwin-arm build-darwin build-linux build-linux-arm build-windows tests
GOCMD=go
GOBUILD=$(GOCMD) build
GOLANGCI_VERSION = 1.21.0
# Binary names
BINARY_NAME=mbt
BUILD = $(CURDIR)/release
# cyclonedx-cli
CYCLONEDX_CLI_BINARY = cyclonedx
CYCLONEDX_CLI_VERSION = 0.24.2
# cyclonedx-gomod
CYCLONEDX_GOMOD_BINARY = cyclonedx-gomod
CYCLONEDX_GOMOD_VERSION = latest
# cyclonedx-bom
CYCLONEDX_BOM_BINARY = cyclonedx-bom
# pkg
PKG_NAME=pkg
# micromatch wrapper
MICROMATCH_WRAPPER_DIR=$(CURDIR)/micromatch
MICROMATCH_WRAPPER_BINARY_NAME=micromatch-wrapper
ifeq ($(OS),Windows_NT)
CYCLONEDX_OS=win
MICROMATCH_WRAPPER_OS=win
else ifeq ($(shell uname -s), Linux)
CYCLONEDX_OS=linux
MICROMATCH_WRAPPER_OS=linux
else ifeq ($(shell uname -s), Darwin)
CYCLONEDX_OS=osx
MICROMATCH_WRAPPER_OS=macos
endif
ifeq ($(shell uname -m),x86_64)
CYCLONEDX_ARCH=x64
else ifeq ($(shell uname -m),arm64)
CYCLONEDX_ARCH=arm64
else ifeq ($(shell uname -m),i386)
CYCLONEDX_ARCH=x86
else
CYCLONEDX_ARCH=x64
endif
ifeq ($(OS),Windows_NT)
CYCLONEDX_BINARY_SUFFIX = .exe
MICROMATCH_WRAPPER_SUFFIX = .exe
else
CYCLONEDX_BINARY_SUFFIX =
MICROMATCH_WRAPPER_SUFFIX =
endif
format :
go fmt ./...
tools:
@echo "download golangci-lint"
curl -sLO https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_VERSION}/golangci-lint-${GOLANGCI_VERSION}-linux-amd64.tar.gz
tar -xzvf golangci-lint-${GOLANGCI_VERSION}-linux-amd64.tar.gz
cp golangci-lint-${GOLANGCI_VERSION}-linux-amd64/golangci-lint $(GOPATH)/bin
@echo "done"
lint:
@echo "Start project linting"
golangci-lint run --config .golangci.yml
@echo "done linting"
# execute general tests
tests:
go test -v -count=1 -timeout 30m ./...
# check code coverage
cover:
go test -v -coverprofile cover.out ./...
go tool cover -html=cover.out -o cover.html
open cover.html
clean:
rm -rf $(BUILD)
dir:
mkdir $(BUILD)
gen:
go generate
# build for each platform
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o release/$(BINARY_NAME)_linux -v
build-linux-arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GOBUILD) -o release/$(BINARY_NAME)_linux_arm -v
build-darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -o release/$(BINARY_NAME) -v
build-darwin-arm:
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(GOBUILD) -o release/$(BINARY_NAME)_darwin_arm -v
build-windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o release/$(BINARY_NAME)_windows -v
# use for local development - > copy the new bin to go/bin path to use new compiled version
# build and install micromatch wrapper
install-pkg:
npm install -g $(PKG_NAME)
echo "$(PKG_NAME) version:"
$(PKG_NAME) --version
install-micromatch-wrapper:
@cd $(MICROMATCH_WRAPPER_DIR) && npm install && cd -
pkg $(MICROMATCH_WRAPPER_DIR) --out-path $(MICROMATCH_WRAPPER_DIR)
cp $(MICROMATCH_WRAPPER_DIR)/$(MICROMATCH_WRAPPER_BINARY_NAME)-$(MICROMATCH_WRAPPER_OS)$(MICROMATCH_WRAPPER_SUFFIX) $(GOPATH)/bin/$(MICROMATCH_WRAPPER_BINARY_NAME)$(MICROMATCH_WRAPPER_SUFFIX)
echo "$(MICROMATCH_WRAPPER_BINARY_NAME) version:"
$(MICROMATCH_WRAPPER_BINARY_NAME) --version
copy:
ifeq ($(OS),Windows_NT)
cp $(CURDIR)/release/$(BINARY_NAME)_windows $(GOPATH)/bin/$(BINARY_NAME).exe
else
cp $(CURDIR)/release/$(BINARY_NAME) $(GOPATH)/bin/
cp $(CURDIR)/release/$(BINARY_NAME) $~/usr/local/bin/
endif
# use for local development - > install cyclonedx-gomod, cyclonedx-cli and cyclonedx-bom
install-cyclonedx:
# install cyclonedx-gomod
go install github.com/CycloneDX/cyclonedx-gomod/cmd/${CYCLONEDX_GOMOD_BINARY}@${CYCLONEDX_GOMOD_VERSION}
echo "${CYCLONEDX_GOMOD_BINARY} version"
${CYCLONEDX_GOMOD_BINARY} version
# install cyclonedx-cli
curl -fsSLO --compressed "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v${CYCLONEDX_CLI_VERSION}/${CYCLONEDX_CLI_BINARY}-${CYCLONEDX_OS}-${CYCLONEDX_ARCH}${CYCLONEDX_BINARY_SUFFIX}"
mv ${CYCLONEDX_CLI_BINARY}-${CYCLONEDX_OS}-${CYCLONEDX_ARCH}${CYCLONEDX_BINARY_SUFFIX} $(GOPATH)/bin/${CYCLONEDX_CLI_BINARY}${CYCLONEDX_BINARY_SUFFIX}
echo "${CYCLONEDX_CLI_BINARY} version:"
${CYCLONEDX_CLI_BINARY} --version
# install cyclonedx-bom
echo "${CYCLONEDX_BOM_BINARY} -h"
npx ${CYCLONEDX_BOM_BINARY} -h