forked from antoine-de/mimirsbrunn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
old_Makefile
189 lines (149 loc) · 7.01 KB
/
old_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
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
185
186
187
#
# Based on Makefile from https://github.com/mvanholsteijn/docker-makefile
# Based on https://gist.github.com/mpneuried/0594963ad38e68917ef189b4e6a269db
#
#
# Import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
export $(shell sed 's/=.*//' $(dpl))
# HELP
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
RELEASE_SUPPORT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/.make-release-support
VERSION=$(shell . $(RELEASE_SUPPORT) ; getVersion)
DOCKERS = $(patsubst ./docker/%/,%, $(dir $(wildcard ./docker/*/)))
DOCKER_TAGS=$(shell . $(RELEASE_SUPPORT) ; getDockerTags)
TAG=$(shell . $(RELEASE_SUPPORT); getTag)
SHELL=/bin/bash
.PHONY: \
pre-build docker-build post-build build \
release patch-prerelease minor-prerelease major-prerelease tag check-status check-release \
push pre-push do-push post-push \
changelog
build: pre-build docker-build post-build ## Build one or more docker images
check: pre-build ## Runs several tests (alias for pre-build)
pre-build: fmt lint test
@echo "docker repo: $(DOCKER_REPO)"
post-build:
pre-push:
post-push:
docker-build:
$(info $$DOCKERS is [${DOCKERS}])
$(info $(DOCKER_REPO))
@for DOCKER in $(DOCKERS); do \
for ENV in $(BUILD_ENV); do \
TAGS=""; \
SPL=$${ENV/:/ }; \
DEB=$$(echo $$SPL | awk '{print $$1;}'); \
RST=$$(echo $$SPL | awk '{print $$2;}'); \
echo "Building $$DOCKER for debian $$DEB / rust $$RST"; \
ARG_DEB="--build-arg DEBIAN_VERSION=$$DEB"; \
ARG_RST="--build-arg RUST_VERSION=$$RST"; \
for DOCKER_TAG in $(DOCKER_TAGS); do \
TAGS=$$TAGS" --tag $(DOCKER_REPO)$$DOCKER:$$DOCKER_TAG-$$DEB"; \
done; \
FIRST_ENV=$$(echo $(BUILD_ENV) | awk '{print $$1;}'); \
if [ $$FIRST_ENV = $$ENV ]; then \
for DOCKER_TAG in $(DOCKER_TAGS); do \
TAGS=$$TAGS" --tag $(DOCKER_REPO)$$DOCKER:$$DOCKER_TAG"; \
done; \
TAGS=$$TAGS" --tag $(DOCKER_REPO)$$DOCKER:latest"; \
fi; \
echo "docker build $(DOCKER_BUILD_ARGS) $$ARG_DEB $$ARG_RST $$TAGS -f docker/$$DOCKER/Dockerfile ."; \
docker build $(DOCKER_BUILD_ARGS) $$ARG_DEB $$ARG_RST $$TAGS -f docker/$$DOCKER/Dockerfile . ; \
done; \
done
release: check-status check-release build push
push: pre-push do-push post-push
do-push:
@for DOCKER in $(DOCKERS); do \
for ENV in $(BUILD_ENV); do \
SPL=$${ENV/:/ }; \
DEB=$$(echo $$SPL | awk '{print $$1;}'); \
for DOCKER_TAG in $(DOCKER_TAGS); do \
docker push $(DOCKER_REPO)$$DOCKER:$$DOCKER_TAG-$$DEB; \
done; \
FIRST_ENV=$$(echo $(BUILD_ENV) | awk '{print $$1;}'); \
if [ $$FIRST_ENV = $$ENV ]; then \
for DOCKER_TAG in $(DOCKER_TAGS); do \
docker push $(DOCKER_REPO)$$DOCKER:$$DOCKER_TAG; \
done; \
docker push $(DOCKER_REPO)$$DOCKER:latest; \
fi; \
done; \
done
snapshot: DOCKER_REPO := $(SNAPSHOT_REPO)/
snapshot: build push
tag-new-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextRelease)
tag-new-release: MSG := $(shell . $(RELEASE_SUPPORT); getReleaseMessage)
tag-new-release: changelog tag
tag-new-prerelease: VERSION := $(shell . $(RELEASE_SUPPORT); nextPrerelease)
tag-new-prerelease: MSG := new prerelease
tag-new-prerelease: tag
tag-patch-prerelease: VERSION := $(shell . $(RELEASE_SUPPORT); nextPatchPrerelease)
tag-patch-prerelease: MSG := new patch prerelease
tag-patch-prerelease: tag
tag-minor-prerelease: VERSION := $(shell . $(RELEASE_SUPPORT); nextMinorPrerelease)
tag-minor-prerelease: MSG := new minor prerelease
tag-minor-prerelease: tag
tag-major-prerelease: VERSION := $(shell . $(RELEASE_SUPPORT); nextMajorPrerelease)
tag-major-prerelease: MSG := new major prerelease
tag-major-prerelease: tag
new-release: DOCKER_REPO := $(RELEASE_REPO)/
new-release: tag-new-release release ## Drop the prerelease suffix and release
@echo $(VERSION)
new-prerelease: DOCKER_REPO := $(PRERELEASE_REPO)/
new-prerelease: tag-new-prerelease release ## Increment the prerelease count and release
@echo "version $(VERSION) released on $(DOCKER_REPO)"
patch-prerelease: DOCKER_REPO := $(PRERELEASE_REPO)/
patch-prerelease: tag-patch-prerelease release ## Increment the patch version number and release
@echo "version $(VERSION) released on $(DOCKER_REPO)"
minor-prerelease: DOCKER_REPO := $(PRERELEASE_REPO)/
minor-prerelease: tag-minor-prerelease release ## Increment the minor version number and release
@echo "version $(VERSION) released on $(DOCKER_REPO)"
major-prerelease: DOCKER_REPO := $(PRERELEASE_REPO)/
major-prerelease: tag-major-prerelease release ## Increment the major version number and release
@echo "version $(VERSION) released on $(DOCKER_REPO)"
tag: TAG=$(shell . $(RELEASE_SUPPORT); getTag $(VERSION))
tag: check-status ## Check that the tag does not already exist, changes the version in Cargo.toml, commit, and tag.
@. $(RELEASE_SUPPORT) ; ! tagExists $(TAG) || (echo "ERROR: tag $(TAG) for version $(VERSION) already tagged in git" >&2 && exit 1) ;
@. $(RELEASE_SUPPORT) ; setRelease $(VERSION)
cargo check # We need to add this cargo check which will update Cargo.lock. Otherwise Cargo.lock will be modified after,
# and the release will seem dirty.
git add .
git commit -m "[Versioned] $(MSG) $(VERSION)" ;
git tag -a $(TAG) -m "Version $(VERSION)";
@ if [ -n "$(shell git remote -v)" ] ; then git push --tags ; else echo 'no remote to push tags to' ; fi
check-status: ## Check that there are no outstanding changes. (uses git status)
@. $(RELEASE_SUPPORT) ; ! hasChanges \
|| (echo "Status ERROR: there are outstanding changes" >&2 && exit 1) \
&& (echo "Status OK" >&2 ) ;
check-release: TAG=$(shell . $(RELEASE_SUPPORT); getTag $(VERSION))
check-release: ## Check that the current git tag matches the one in Cargo.toml and there are no outstanding changes.
$(info $$VERSION is [${VERSION}])
$(info $$TAG is [${TAG}])
@. $(RELEASE_SUPPORT) ; tagExists $(TAG) || (echo "ERROR: version not yet tagged in git. make [minor,major,patch]-release." >&2 && exit 1) ;
@. $(RELEASE_SUPPORT) ; ! differsFromRelease $(TAG) || (echo "ERROR: current directory differs from tagged $(TAG). make [minor,major,patch]-release." ; exit 1)
changelog: LAST_TAG := $(shell . $(RELEASE_SUPPORT); getLastTag)
changelog: TAG=$(shell . $(RELEASE_SUPPORT); getTag $(VERSION))
changelog: check-status
@. $(RELEASE_SUPPORT) ; generateChangelog $(TAG) $(LAST_TAG) ;
######### Debug
check-tag:
@echo $(TAG)
check-version:
@echo $(VERSION)
### RUST related rules
fmt: format ## Check formatting of the code (alias for 'format')
format: ## Check formatting of the code
cargo fmt --all -- --check
clippy: lint ## Check quality of the code (alias for 'lint')
lint: ## Check quality of the code
cargo clippy --all-features --all-targets -- --warn clippy::cargo --allow clippy::multiple_crate_versions --deny warnings
test: ## Launch all tests
cargo test --all-targets # `--all-targets` but no doctests