-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
184 lines (163 loc) · 6.23 KB
/
Copy pathMakefile
File metadata and controls
184 lines (163 loc) · 6.23 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
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
181
182
183
184
# Makefile for the Evolution DevServices CLI (eds).
#
# Targets:
# make build - build for the current GOOS/GOARCH into ./bin/eds
# make build-all - cross-compile the default matrix into ./dist/
# make build-one - helper invoked by build-all (GOOS=... GOARCH=...)
# make clean - remove ./bin and ./dist
# make test - run `go test ./...`
# make tidy - run `go mod tidy`
# make install - `go install` into $GOBIN
# make release - build-all + sha256 sums
# make upload - build-all + publish to S3-compatible storage
# make upload-latest - only update the `latest` pointer in the bucket
# make help - print the list of targets
#
# GitHub Releases (primary distribution channel) are cut manually or via CI
# with `gh release create <tag> dist/* --generate-notes` after `make release`.
# `make upload`/`make upload-latest` are for an optional secondary mirror on
# S3-compatible storage.
#
# Overrides:
# make build-all OSES="linux darwin" ARCHS="amd64 arm64"
# make build VERSION=v0.2.0
# make upload BUCKET=my-bucket PREFIX=evolution-devservices-cli VERSION=v0.2.0
BINARY := eds
PKG := github.com/cloud-ru/evolution-devservices-cli
BUILD_DIR := bin
DIST_DIR := dist
# Target platforms: Linux + macOS (developers locally + CI runners).
DEFAULT_OSES := darwin linux
DEFAULT_ARCHS := amd64 arm64
OSES ?= $(DEFAULT_OSES)
ARCHS ?= $(DEFAULT_ARCHS)
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GOFLAGS ?=
CGO_ENABLED ?= 0
# Must come after VERSION: LDFLAGS uses immediate (:=) expansion, so it has
# to be defined once VERSION is already resolved, or it silently bakes in
# an empty version string.
LDFLAGS := -s -w -X main.version=$(VERSION)
# ---- targets --------------------------------------------------------------
.PHONY: all
all: lint test build
.PHONY: build
build:
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) \
-trimpath -ldflags '$(LDFLAGS)' \
-o $(BUILD_DIR)/$(BINARY) .
@echo "Built $(BUILD_DIR)/$(BINARY) (version=$(VERSION))"
# Helper target - invoke recursively for each os/arch combination.
# Usage: make build-one GOOS=darwin GOARCH=arm64
.PHONY: build-one
build-one:
@mkdir -p $(DIST_DIR)
$(eval EXE := $(if $(filter windows,$(GOOS)),.exe,))
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \
go build $(GOFLAGS) -trimpath -ldflags '$(LDFLAGS)' \
-o $(DIST_DIR)/$(BINARY)-$(GOOS)-$(GOARCH)$(EXE) .
@echo " ✔ $(DIST_DIR)/$(BINARY)-$(GOOS)-$(GOARCH)$(EXE)"
.PHONY: build-all
build-all:
@status=0; \
for os in $(OSES); do \
for arch in $(ARCHS); do \
if ! $(MAKE) --no-print-directory build-one GOOS=$$os GOARCH=$$arch; then \
status=1; \
fi; \
done; \
done; \
exit $$status
@echo
@echo "Artifacts in $(DIST_DIR)/:"
@ls -1 $(DIST_DIR)
.PHONY: release
release: clean build-all
@cd $(DIST_DIR) && shasum -a 256 $(BINARY)-* > checksums.txt
@echo
@echo "Checksums:"
@cat $(DIST_DIR)/checksums.txt
# --- publish to S3-compatible object storage --------------------------------
#
# Requires the `aws` CLI configured with the right endpoint and credentials,
# for example:
#
# export AWS_ENDPOINT_URL=https://storage.cloud.ru
# export AWS_ACCESS_KEY_ID=...
# export AWS_SECRET_ACCESS_KEY=...
#
# Layout produced in the bucket:
#
# s3://BUCKET/PREFIX/VERSION/eds-<os>-<arch>[.exe]
# s3://BUCKET/PREFIX/latest # contains VERSION
# s3://BUCKET/PREFIX/install.sh # copy of scripts/install.sh
#
# Usage:
# make upload BUCKET=my-bucket PREFIX=evolution-devservices-cli VERSION=v0.2.0
# make upload-latest BUCKET=my-bucket PREFIX=evolution-devservices-cli VERSION=v0.2.0
BUCKET ?=
PREFIX ?= evolution-devservices-cli
S3_OPTS := $(if $(AWS_ENDPOINT_URL),--endpoint-url $(AWS_ENDPOINT_URL),)
.PHONY: upload
upload: build-all
@if [[ -z "$(BUCKET)" ]]; then \
echo "BUCKET is required, e.g. make upload BUCKET=my-bucket VERSION=v0.2.0"; \
exit 1; \
fi
@echo "Uploading version=$(VERSION) to s3://$(BUCKET)/$(PREFIX)/"
@for f in $(DIST_DIR)/$(BINARY)-*; do \
name=$$(basename $$f); \
aws $(S3_OPTS) s3 cp $$f s3://$(BUCKET)/$(PREFIX)/$(VERSION)/$$name \
--acl public-read >/dev/null && \
echo " ✔ s3://$(BUCKET)/$(PREFIX)/$(VERSION)/$$name"; \
done
@aws $(S3_OPTS) s3 cp scripts/install.sh s3://$(BUCKET)/$(PREFIX)/install.sh \
--acl public-read >/dev/null && \
echo " ✔ s3://$(BUCKET)/$(PREFIX)/install.sh"
@printf "%s\n" "$(VERSION)" > $(DIST_DIR)/.latest && \
aws $(S3_OPTS) s3 cp $(DIST_DIR)/.latest s3://$(BUCKET)/$(PREFIX)/latest \
--acl public-read --content-type "text/plain" >/dev/null && \
rm -f $(DIST_DIR)/.latest && \
echo " ✔ s3://$(BUCKET)/$(PREFIX)/latest -> $(VERSION)"
.PHONY: upload-latest
upload-latest:
@if [[ -z "$(BUCKET)" ]]; then \
echo "BUCKET is required"; exit 1; \
fi
@printf "%s\n" "$(VERSION)" > $(DIST_DIR)/.latest && \
aws $(S3_OPTS) s3 cp $(DIST_DIR)/.latest s3://$(BUCKET)/$(PREFIX)/latest \
--acl public-read --content-type "text/plain" >/dev/null && \
rm -f $(DIST_DIR)/.latest && \
echo " ✔ latest -> $(VERSION)"
.PHONY: install
install:
CGO_ENABLED=$(CGO_ENABLED) go install $(GOFLAGS) \
-trimpath -ldflags '$(LDFLAGS)' $(PKG)
.PHONY: test
test:
go test $(GOFLAGS) ./...
.PHONY: tidy
tidy:
go mod tidy
.PHONY: clean
clean:
rm -rf $(BUILD_DIR) $(DIST_DIR)
.PHONY: help
help:
@echo "Targets:"
@echo " build build for the current platform into ./bin/"
@echo " build-all cross-compile darwin/linux × amd64/arm64 into ./dist/"
@echo " build-one helper for build-all (GOOS=... GOARCH=...)"
@echo " release build-all + sha256 checksums"
@echo " upload build-all + publish to S3 (BUCKET=... VERSION=...)"
@echo " upload-latest only update the 'latest' pointer in the bucket"
@echo " install go install into \$$GOBIN"
@echo " lint run golangci-lint"
@echo " test, tidy standard Go targets"
@echo " clean remove ./bin and ./dist"
openapi-generator:
openapi-generator-cli generate -i openapi-public.yaml -g go -o ./internal/workflow_client -c .openapi-generator.yaml
.PHONY: lint
lint:
golangci-lint run --fix