Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (110 loc) · 5.57 KB
/
Copy pathMakefile
File metadata and controls
140 lines (110 loc) · 5.57 KB
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
# Default VERSION comes from the tracked version file; an explicit VERSION on the
# command line or in the environment still takes precedence.
VERSION_FILE := $(CURDIR)/version
DEFAULT_VERSION := $(strip $(shell cat $(VERSION_FILE) 2>/dev/null))
export VERSION ?= $(DEFAULT_VERSION)
ifeq ($(strip $(VERSION)),)
$(error VERSION is empty: pass VERSION=<x.y.z> or provide a non-empty version file at $(VERSION_FILE))
endif
export RELEASE_PATH="releases/aliyun-cli-${VERSION}"
MODULE := github.com/aliyun/aliyun-cli/v3
META_DIR := $(CURDIR)/aliyun-openapi-meta
META_TAG := aliyun_cli_packed_meta
RUNTIME_DIR := $(CURDIR)/aliyun-openapi-runtime
LDFLAGS := -X '$(MODULE)/cli.Version=$(VERSION)'
all: build
publish: build build_mac build_linux build_windows build_linux_arm64 gen_version
deps:
git submodule update --init --recursive
clean:
rm -rf out/*
rm -rf bundledmeta/.generated
run: deps
ALIYUN_CLI_META_DIR="$(META_DIR)" go run ./main
meta-pack: deps
go generate ./bundledmeta
build: meta-pack
mkdir -p out
CGO_ENABLED=0 go build -tags "$(META_TAG)" -ldflags "$(LDFLAGS)" -o out/aliyun ./main
install: build
cp out/aliyun /usr/local/bin
build_mac: meta-pack
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -tags "$(META_TAG)" -ldflags "$(LDFLAGS)" -o out/aliyun ./main
tar zcvf out/aliyun-cli-macosx-${VERSION}-amd64.tgz -C out aliyun
aliyun oss cp out/aliyun-cli-macosx-${VERSION}-amd64.tgz oss://aliyun-cli --force --profile oss
build_linux: meta-pack
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags "$(META_TAG)" -ldflags "$(LDFLAGS)" -o out/aliyun ./main
tar zcvf out/aliyun-cli-linux-${VERSION}-amd64.tgz -C out aliyun
aliyun oss cp out/aliyun-cli-linux-${VERSION}-amd64.tgz oss://aliyun-cli --force --profile oss
build_windows: meta-pack
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags "$(META_TAG)" -ldflags "$(LDFLAGS)" -o aliyun.exe ./main
zip -r out/aliyun-cli-windows-${VERSION}-amd64.zip aliyun.exe
aliyun oss cp out/aliyun-cli-windows-${VERSION}-amd64.zip oss://aliyun-cli --force --profile oss
rm aliyun.exe
build_linux_arm64: meta-pack
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags "$(META_TAG)" -ldflags "$(LDFLAGS)" -o out/aliyun ./main
tar zcvf out/aliyun-cli-linux-${VERSION}-arm64.tgz -C out aliyun
aliyun oss cp out/aliyun-cli-linux-${VERSION}-arm64.tgz oss://aliyun-cli --force --profile oss
# Legacy manual publish. Stable history is the JSON object written by tools/finish_release.sh.
# This target still writes only the single-version pointer.
gen_version:
-rm out/version
echo ${VERSION} >> out/version
aliyun oss cp out/version oss://aliyun-cli --force --profile oss
git_release: clean build make_release_dir release_mac release_linux release_linux_arm64 release_windows
make_release_dir:
mkdir -p ${RELEASE_PATH}
release_mac: meta-pack
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -tags "$(META_TAG)" -ldflags "$(LDFLAGS)" -o out/aliyun ./main
tar zcvf ${RELEASE_PATH}/aliyun-cli-darwin-amd64.tar.gz -C out aliyun
release_mac_arm64: meta-pack
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -tags "$(META_TAG)" -ldflags "$(LDFLAGS)" -o out/aliyun ./main
tar zcvf ${RELEASE_PATH}/aliyun-cli-darwin-arm64.tar.gz -C out aliyun
release_linux: meta-pack
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags "$(META_TAG)" -ldflags "$(LDFLAGS)" -o out/aliyun ./main
tar zcvf ${RELEASE_PATH}/aliyun-cli-linux-amd64.tar.gz -C out aliyun
release_linux_arm64: meta-pack
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags "$(META_TAG)" -ldflags "$(LDFLAGS)" -o out/aliyun ./main
tar zcvf ${RELEASE_PATH}/aliyun-cli-linux-arm64.tar.gz -C out aliyun
release_windows: meta-pack
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags "$(META_TAG)" -ldflags "$(LDFLAGS)" -o aliyun.exe ./main
zip -r ${RELEASE_PATH}/aliyun-cli-windows-amd64.exe.zip aliyun.exe
rm aliyun.exe
fmt:
go fmt ./bundledmeta/... ./util/... ./cli/... ./config/... ./i18n/... ./main/... ./openapi/... ./oss/... ./resource/... ./meta/... ./export/...
check-fmt:
@files="$$(gofmt -l .)"; \
if [ -n "$$files" ]; then \
echo "The following Go files are not formatted with gofmt:"; \
echo "$$files"; \
exit 1; \
fi
test-runtime:
cd "$(RUNTIME_DIR)" && go test -race -coverprofile="$(CURDIR)/coverage-runtime.txt" -covermode=atomic ./...
check-runtime: test-runtime
test: deps
# Ensure every package under the module is listable/vettable (catches stale go:embed in submodules).
# The live OSS gocheck runner is excluded separately by test-oss.
go list ./... >/dev/null
go vet ./...
ALIYUN_CLI_META_DIR="$(META_DIR)" LANG="en_US.UTF-8" go test -race -coverprofile=coverage.txt -covermode=atomic \
./bundledmeta ./canonicalmeta ./internal/... \
./util/... ./cli/... ./config/... \
./i18n/... ./main/... ./openapi/... ./meta/... ./export/... \
./sysconfig/... ./mcpproxy ./cloudsso ./cliext/... ./tools/...
go tool cover -html=coverage.txt -o coverage.html
$(MAKE) test-oss
test-release: meta-pack
LANG="en_US.UTF-8" go test -tags "$(META_TAG)" ./bundledmeta ./meta ./export ./openapi/runtimehost
.PHONY: all publish install
.PHONY: deps clean run fmt check-fmt test-runtime check-runtime test test-release
.PHONY: meta-pack build build_mac build_linux build_windows build_linux_arm64
.PHONY: gen_version git_release make_release_dir
.PHONY: release_mac release_mac_arm64 release_linux release_linux_arm64 release_windows
# Only Test is the legacy gocheck runner requiring real cloud resources.
test-oss:
go test -race -coverprofile=coverage-oss.txt -covermode=atomic ./oss/lib -skip '^Test$$'
check-entrypoint:
mkdir -p out
go build -o out/aliyun-single-file ./main/main.go
.PHONY: test-oss check-entrypoint