-
Notifications
You must be signed in to change notification settings - Fork 104
/
Makefile
137 lines (97 loc) · 4.23 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
VERSION ?= $(shell git describe --tags --always --dirty)
BIN ?= ec2-instance-selector
IMG ?= amazon/amazon-ec2-instance-selector
REPO_FULL_NAME ?= aws/amazon-ec2-instance-selector
IMG_TAG ?= ${VERSION}
IMG_W_TAG = ${IMG}:${IMG_TAG}
DOCKERHUB_USERNAME ?= ""
DOCKERHUB_TOKEN ?= ""
GOOS ?= $(uname | tr '[:upper:]' '[:lower:]')
GOARCH ?= amd64
GOPROXY ?= "https://proxy.golang.org,direct"
MAKEFILE_PATH = $(dir $(realpath -s $(firstword $(MAKEFILE_LIST))))
BUILD_DIR_PATH = ${MAKEFILE_PATH}/build
SUPPORTED_PLATFORMS ?= "windows/amd64,darwin/amd64,darwin/arm64,linux/amd64,linux/arm64,linux/arm"
SELECTOR_PKG_VERSION_VAR=github.com/aws/amazon-ec2-instance-selector/v3/pkg/selector.versionID
LATEST_RELEASE_TAG=$(shell git describe --tags --abbrev=0)
PREVIOUS_RELEASE_TAG=$(shell git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
$(shell mkdir -p ${BUILD_DIR_PATH} && touch ${BUILD_DIR_PATH}/_go.mod)
repo-full-name:
@echo ${REPO_FULL_NAME}
compile:
go build -a -ldflags "-s -w -X main.versionID=${VERSION} -X ${SELECTOR_PKG_VERSION_VAR}=${VERSION}" -tags="aeis${GOOS}" -o ${BUILD_DIR_PATH}/${BIN} ${MAKEFILE_PATH}/cmd/main.go
clean:
rm -rf ${BUILD_DIR_PATH}/ && go clean -testcache ./...
fmt:
goimports -w ./ && gofmt -s -w ./
docker-build:
${MAKEFILE_PATH}/scripts/build-docker-images -p ${GOOS}/${GOARCH} -r ${IMG} -v ${VERSION}
docker-run:
docker run ${IMG_W_TAG}
docker-push:
@docker login -u ${DOCKERHUB_USERNAME} -p="${DOCKERHUB_TOKEN}"
docker push ${IMG_W_TAG}
build-docker-images:
${MAKEFILE_PATH}/scripts/build-docker-images -p ${SUPPORTED_PLATFORMS} -r ${IMG} -v ${VERSION}
push-docker-images:
@docker login -u ${DOCKERHUB_USERNAME} -p="${DOCKERHUB_TOKEN}"
${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS} -r ${IMG} -v ${VERSION} -m
version:
@echo ${VERSION}
latest-release-tag:
@echo ${LATEST_RELEASE_TAG}
previous-release-tag:
@echo ${PREVIOUS_RELEASE_TAG}
image:
@echo ${IMG_W_TAG}
license-test:
${MAKEFILE_PATH}/test/license-test/run-license-test.sh
spellcheck:
${MAKEFILE_PATH}/test/readme-test/run-readme-spellcheck
shellcheck:
${MAKEFILE_PATH}/test/shellcheck/run-shellcheck
## requires aws credentials
readme-codeblock-test:
${MAKEFILE_PATH}/test/readme-test/run-readme-codeblocks
build-binaries:
${MAKEFILE_PATH}/scripts/build-binaries -p ${SUPPORTED_PLATFORMS} -v ${VERSION}
## requires a github token
upload-resources-to-github:
${MAKEFILE_PATH}/scripts/upload-resources-to-github
## requires a dockerhub token
sync-readme-to-dockerhub:
${MAKEFILE_PATH}/scripts/sync-readme-to-dockerhub
unit-test:
go test -bench=. ./... -v -coverprofile=coverage.out -covermode=atomic -outputdir=${BUILD_DIR_PATH}
## requires aws credentials
e2e-test: build
${MAKEFILE_PATH}/test/e2e/run-test
## requires aws credentials
integ-test: e2e-test readme-codeblock-test
homebrew-sync-dry-run:
${MAKEFILE_PATH}/scripts/sync-to-aws-homebrew-tap -d -b ${BIN} -r ${REPO_FULL_NAME} -p ${SUPPORTED_PLATFORMS} -v ${LATEST_RELEASE_TAG}
homebrew-sync:
${MAKEFILE_PATH}/scripts/sync-to-aws-homebrew-tap -b ${BIN} -r ${REPO_FULL_NAME} -p ${SUPPORTED_PLATFORMS}
build: compile
release: build-binaries upload-resources-to-github
test: spellcheck shellcheck unit-test license-test e2e-test readme-codeblock-test
help:
@grep -E '^[a-zA-Z_-]+:.*$$' $(MAKEFILE_LIST) | sort
## Targets intended to be run in preparation for a new release
create-local-release-tag-major:
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -m
create-local-release-tag-minor:
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -i
create-local-release-tag-patch:
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -p
create-release-prep-pr:
${MAKEFILE_PATH}/scripts/prepare-for-release
create-release-prep-pr-draft:
${MAKEFILE_PATH}/scripts/prepare-for-release -d
release-prep-major: create-local-release-tag-major create-release-prep-pr
release-prep-minor: create-local-release-tag-minor create-release-prep-pr
release-prep-patch: create-local-release-tag-patch create-release-prep-pr
release-prep-custom: # Run make NEW_VERSION=v1.2.3 release-prep-custom to prep for a custom release version
ifdef NEW_VERSION
$(shell echo "${MAKEFILE_PATH}/scripts/create-local-tag-for-release -v $(NEW_VERSION) && echo && make create-release-prep-pr")
endif