-
Notifications
You must be signed in to change notification settings - Fork 50
/
Makefile
262 lines (213 loc) · 7.9 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
SHELL := /bin/bash
ANDROID_BUILDER_TAG=d5425480c925
ifeq ($(origin DOCKER_REGISTRY),undefined)
IMAGE_ANDROID_BUILDER=avitotech/android-builder:$(ANDROID_BUILDER_TAG)
else
IMAGE_ANDROID_BUILDER=$(DOCKER_REGISTRY)/android/builder:$(ANDROID_BUILDER_TAG)
endif
GRADLE_HOME_DIR=$(HOME)/.gradle
# only need dependencies: https://docs.gradle.org/current/userguide/dependency_resolution.html#sub:ephemeral-ci-cache
GRADLE_CACHE_DIR=$(GRADLE_HOME_DIR)/caches/modules-2
GRADLE_WRAPPER_DIR=$(GRADLE_HOME_DIR)/wrapper
USER_ID=$(shell id -u $(USER))
docker=false
infra?=
ci?=false
log_level?=-w
kubernetesContext?=
testFilter?=
includePrefix?=
includeAnnotation?=
dry_run=false
instrumentation=Ui
stacktrace?=
offline?=
# see Logging.md#Verbose-mode
verbose?=
docker_command?=
ifeq ($(docker),true)
define docker_command
make clear_gradle_lock_files
make clear_docker_containers
docker run --rm \
--volume "$(shell pwd)":/app \
--volume "$(shell pwd)/ci/gradle.properties":/gradle/gradle.properties \
--volume "$(GRADLE_CACHE_DIR)":/gradle/caches/modules-2 \
--volume "$(GRADLE_WRAPPER_DIR)":/gradle/wrapper \
--workdir /app \
--env TZ="Europe/Moscow" \
--env LOCAL_USER_ID="$(USER_ID)" \
--env GRADLE_USER_HOME=/gradle \
$(IMAGE_ANDROID_BUILDER)
endef
endif
params?=
ifdef offline
params +=--offline
endif
ifdef testFilter
params +=-PcustomFilter=$(testFilter)
endif
ifdef includePrefix
params +=-PincludePrefix=$(includePrefix)
endif
ifdef includeAnnotation
params +=-PincludeAnnotation=$(includeAnnotation)
endif
ifdef infra
params +=-PinfraVersion=$(infra)
endif
ifdef verbose
params +=-Pavito.logging.verbosity=$(verbose)
endif
params +=-Pci=$(ci)
params +=$(log_level)
ifdef kubernetesContext
params +=-PkubernetesContext=$(kubernetesContext)
endif
ifeq ($(gradle_debug),true)
params +=-Dorg.gradle.debug=true --no-daemon
endif
ifeq ($(CONFIG_CACHE),true)
params +=--configuration-cache
endif
ifdef AVITO_REGISTRY
params +=-Pavito.registry=$(AVITO_REGISTRY)
endif
ifeq ($(dry_run),true)
params +=--dry-run
endif
ifdef stacktrace
params +=--stacktrace
endif
ifdef ARTIFACTORY_URL
params +=-PartifactoryUrl=$(ARTIFACTORY_URL)
endif
# from: https://stackoverflow.com/questions/10858261/abort-makefile-if-variable-not-set
#
# Check that given variables are set and all have non-empty values,
# die with an error otherwise.
#
# Params:
# 1. Variable name(s) to test.
# 2. (optional) Error message to print.
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined argument: $1$(if $2, ($2))))
clean_build:
rm -rf `find . -type d -name build`
clean_configuration_cache:
rm -rf .gradle/configuration-cache
clean_build_cache:
rm -rf ~/.gradle/caches/build-cache-1/
unsafe_clean:
git clean -fdx
# Warning. Hack!
# Мы можем удалять эти локи, т.к. гарантированно никакие другие процессы не используют этот шаренный кеш на начало новой сборки
# см. clearDockerContainers
# То что лок файлы остаются от предыдущих сборок, означает что мы где-то неправильно останавливаем процесс
# '|| true' необходим для свеже-поднятых агентов, где еще не создана папка с кешами
clear_gradle_lock_files:
find "$(GRADLE_HOME_DIR)" \( -name "*.lock" -o -name "*.lck" \) -delete || true
# По разным причинам работа контейнера при прошлой сборке может не завершиться
# Здесь мы перестраховываемся и останавливаем все работающие контейнеры
# Перед сборкой не должно быть других контейнеров в любом случае
clear_docker_containers:
containers=$(docker container ls -aq)
if [[ ! -z "$(containers)" ]]; then \
docker container rm --force $(containers); \
fi
publish_to_maven_local:
$(docker_command) ./gradlew $(params) publishToMavenLocal -PprojectVersion=10000000.0-local --no-configuration-cache
stage_ui_tests:
make publish_to_maven_local
./gradlew $(params) :subprojects:android-test:ui-testing-core-app:instrumentationUi -DinfraVersion=local
compile:
$(docker_command) ./gradlew $(params) compileAll
assemble:
$(docker_command) ./gradlew $(params) assemble
# Configuration cache fails in instrumentation tasks: MBS-11856
check:
$(docker_command) ./gradlew $(params) check
.PHONY: build
build:
$(docker_command) ./gradlew $(params) build
# Analyze modules dependencies issues
# https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/wiki/Tasks#build-health
build_health:
$(docker_command) ./gradlew $(params) buildHealth
# Precondition: installed graphviz: https://graphviz.org/download/
#
# Builds dependencies graph
# https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin
# Example: make project_graph_report id=:test-runner:client
project_graph_report:
$(call check_defined, id)
$(docker_command) ./gradlew $(params) projectGraphReport --id $(id)
cd build/reports/dependency-analysis && \
dot -Tsvg merged-graph.gv -o merged-graph.svg && \
dot -Tsvg merged-graph-rev.gv -o merged-graph-rev.svg && \
dot -Tsvg merged-graph-rev-sub.gv -o merged-graph-rev-sub.svg && \
echo "See artifacts in build/reports/dependency-analysis"
.PHONY: docs
docs:
./ci/documentation/lint.sh
./ci/documentation/preview.sh
clear_k8s_deployments_by_namespaces:
$(docker_command) ./gradlew subprojects\:test-runner\:k8s-deployments-cleaner\:clearByNamespaces -PteamcityApiPassword=$(teamcityApiPassword) $(log_level)
clear_k8s_deployments_by_names:
$(docker_command) ./gradlew subprojects\:test-runner\:k8s-deployments-cleaner\:deleteByNames -Pci=true $(log_level)
# Clear local branches that not on remote
# from: https://stackoverflow.com/a/17029936/981330
unsafe_clear_local_branches:
git fetch --prune && \
git branch -r | awk '{print $$1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | \
awk '{print $$1}' | xargs git branch -D
# Precondition:
# - installed CLI: https://cli.github.com/
# - push $(version) branch
#
# Post actions:
# - Go to a link in output
# - Edit notes
# - Publish the release
draft_release:
$(call check_defined, version)
$(call check_defined, prev_version)
git fetch --all
gh release create v$(version) \
--draft \
--target $(version) \
--title $(version) \
--notes "$$(git log --pretty=format:%s origin/$(prev_version)..origin/$(version) | cat)"
dynamic_properties:
$(eval keepFailedTestsFromReport?=)
$(eval skipSucceedTestsFromPreviousRun=true)
$(eval testFilter?=empty)
$(eval dynamicPrefixFilter?=)
check_avito_configuration:
make publish_to_maven_local
cd ../avito-android && ./gradlew tasks -DinfraVersion=local
dependency_updates:
$(docker_command) ./gradlew $(params) dependencyUpdates -Drevision=release
benchmark_fast_check:
gradle-profiler --benchmark --scenario-file gradle/performance.scenarios fastCheck
benchmark_gradle_test:
gradle-profiler --benchmark --scenario-file gradle/performance.scenarios gradleTest
## Gradle cache node
GRADLE_CACHE_NODE_TAG=13.2
# publish to internal repo to avoid rate limits problems
internal_publish_gradle_cache_node_image:
$(call check_defined, DOCKER_REGISTRY)
$(call check_defined, DOCKER_LOGIN)
$(call check_defined, DOCKER_PASSWORD)
echo $(DOCKER_PASSWORD) | docker login --username $(DOCKER_LOGIN) --password-stdin $(DOCKER_REGISTRY) && \
docker pull gradle/build-cache-node:$(GRADLE_CACHE_NODE_TAG) && \
docker tag gradle/build-cache-node:$(GRADLE_CACHE_NODE_TAG) $(DOCKER_REGISTRY)/android/gradle-cache-node:$(GRADLE_CACHE_NODE_TAG) && \
docker push $(DOCKER_REGISTRY)/android/gradle-cache-node:$(GRADLE_CACHE_NODE_TAG)
# Update depenedency lock-files after dependency update
write_locks:
./gradlew dependencyGuardBaseline