Makefile 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. SHELL := /bin/bash
  2. ELASTICSEARCH_DEFAULT_BUILD_VERSION = "7.17.10-SNAPSHOT"
  3. ##@ Test
  4. test-unit: ## Run unit tests
  5. @printf "\033[2m→ Running unit tests...\033[0m\n"
  6. ifdef race
  7. $(eval testunitargs += "-race")
  8. endif
  9. $(eval testunitargs += "-cover" "-coverprofile=tmp/unit.cov" "./...")
  10. @mkdir -p tmp
  11. @if which gotestsum > /dev/null 2>&1 ; then \
  12. echo "gotestsum --format=short-verbose --junitfile=tmp/unit-report.xml --" $(testunitargs); \
  13. gotestsum --format=short-verbose --junitfile=tmp/unit-report.xml -- $(testunitargs); \
  14. else \
  15. echo "go test -v" $(testunitargs); \
  16. go test -v $(testunitargs); \
  17. fi;
  18. test: test-unit
  19. test-integ: ## Run integration tests
  20. @printf "\033[2m→ Running integration tests...\033[0m\n"
  21. $(eval testintegtags += "integration")
  22. ifdef multinode
  23. $(eval testintegtags += "multinode")
  24. endif
  25. ifdef race
  26. $(eval testintegargs += "-race")
  27. endif
  28. $(eval testintegargs += "-cover" "-coverprofile=tmp/integration-client.cov" "-tags='$(testintegtags)'" "-timeout=1h")
  29. @mkdir -p tmp
  30. @if which gotestsum > /dev/null 2>&1 ; then \
  31. echo "gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml --" $(testintegargs); \
  32. gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "."; \
  33. gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "./estransport" "./esapi" "./esutil"; \
  34. else \
  35. echo "go test -v" $(testintegargs) "."; \
  36. go test -v $(testintegargs) "./estransport" "./esapi" "./esutil"; \
  37. fi;
  38. test-api: ## Run generated API integration tests
  39. @mkdir -p tmp
  40. ifdef race
  41. $(eval testapiargs += "-race")
  42. endif
  43. $(eval testapiargs += "-cover" "-coverpkg=github.com/elastic/go-elasticsearch/v7/esapi" "-coverprofile=$(PWD)/tmp/integration-api.cov" "-tags='integration'" "-timeout=1h")
  44. ifdef flavor
  45. else
  46. $(eval flavor='free')
  47. endif
  48. @printf "\033[2m→ Running API integration tests for [$(flavor)]...\033[0m\n"
  49. ifeq ($(flavor), platinum)
  50. @{ \
  51. set -e ; \
  52. trap "test -d .git && git checkout --quiet $(PWD)/esapi/test/go.mod" INT TERM EXIT; \
  53. export ELASTICSEARCH_URL='https://elastic:elastic@localhost:9200' && \
  54. if which gotestsum > /dev/null 2>&1 ; then \
  55. cd esapi/test && \
  56. go mod download && \
  57. gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs) $(PWD)/esapi/test/xpack/*_test.go && \
  58. gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs) $(PWD)/esapi/test/xpack/ml/*_test.go && \
  59. gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs) $(PWD)/esapi/test/xpack/ml-crud/*_test.go; \
  60. else \
  61. echo "go test -v" $(testapiargs); \
  62. cd esapi/test && \
  63. go mod download && \
  64. go test -v $(testapiargs) $(PWD)/esapi/test/xpack/*_test.go && \
  65. go test -v $(testapiargs) $(PWD)/esapi/test/xpack/ml/*_test.go && \
  66. go test -v $(testapiargs) $(PWD)/esapi/test/xpack/ml-crud/*_test.go; \
  67. fi; \
  68. }
  69. else
  70. $(eval testapiargs += $(PWD)/esapi/test/*_test.go)
  71. @{ \
  72. set -e ; \
  73. trap "test -d .git && git checkout --quiet $(PWD)/esapi/test/go.mod" INT TERM EXIT; \
  74. if which gotestsum > /dev/null 2>&1 ; then \
  75. cd esapi/test && \
  76. go mod download && \
  77. gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs); \
  78. else \
  79. echo "go test -v" $(testapiargs); \
  80. cd esapi/test && \
  81. go mod download && \
  82. go test -v $(testapiargs); \
  83. fi; \
  84. }
  85. endif
  86. test-bench: ## Run benchmarks
  87. @printf "\033[2m→ Running benchmarks...\033[0m\n"
  88. go test -run=none -bench=. -benchmem ./...
  89. test-examples: ## Execute the _examples
  90. @printf "\033[2m→ Testing the examples...\033[0m\n"
  91. @{ \
  92. set -e ; \
  93. trap "test -d .git && git checkout --quiet _examples/**/go.mod" INT TERM EXIT; \
  94. for d in _examples/*/; do \
  95. printf "\033[2m────────────────────────────────────────────────────────────────────────────────\n"; \
  96. printf "\033[1mUpdating dependencies for $$d\033[0m\n"; \
  97. printf "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \
  98. (cd $$d && go mod download && make setup) || \
  99. ( \
  100. printf "\033[31m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \
  101. printf "\033[31;1m⨯ ERROR\033[0m\n"; \
  102. false; \
  103. ); \
  104. done; \
  105. \
  106. for f in _examples/*.go; do \
  107. printf "\033[2m────────────────────────────────────────────────────────────────────────────────\n"; \
  108. printf "\033[1m$$f\033[0m\n"; \
  109. printf "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \
  110. (go run $$f && true) || \
  111. ( \
  112. printf "\033[31m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \
  113. printf "\033[31;1m⨯ ERROR\033[0m\n"; \
  114. false; \
  115. ); \
  116. done; \
  117. \
  118. for f in _examples/*/; do \
  119. printf "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \
  120. printf "\033[1m$$f\033[0m\n"; \
  121. printf "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \
  122. (cd $$f && make test && true) || \
  123. ( \
  124. printf "\033[31m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \
  125. printf "\033[31;1m⨯ ERROR\033[0m\n"; \
  126. false; \
  127. ); \
  128. done; \
  129. printf "\033[32m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \
  130. \
  131. printf "\033[32;1mSUCCESS\033[0m\n"; \
  132. }
  133. test-coverage: ## Generate test coverage report
  134. @printf "\033[2m→ Generating test coverage report...\033[0m\n"
  135. @go tool cover -html=tmp/unit.cov -o tmp/coverage.html
  136. @go tool cover -func=tmp/unit.cov | 'grep' -v 'esapi/api\.' | sed 's/github.com\/elastic\/go-elasticsearch\///g'
  137. @printf "\033[0m--------------------------------------------------------------------------------\nopen tmp/coverage.html\n\n\033[0m"
  138. ##@ Development
  139. lint: ## Run lint on the package
  140. @printf "\033[2m→ Running lint...\033[0m\n"
  141. go vet github.com/elastic/go-elasticsearch/...
  142. go list github.com/elastic/go-elasticsearch/... | 'grep' -v internal | xargs golint -set_exit_status
  143. @{ \
  144. set -e ; \
  145. trap "test -d ../../../.git && git checkout --quiet go.mod" INT TERM EXIT; \
  146. echo "cd internal/build/ && go vet ./..."; \
  147. cd "internal/build/" && go mod tidy && go mod download && go vet ./...; \
  148. }
  149. apidiff: ## Display API incompabilities
  150. @if ! command -v apidiff > /dev/null; then \
  151. printf "\033[31;1mERROR: apidiff not installed\033[0m\n"; \
  152. printf "go get -u github.com/go-modules-by-example/apidiff\n"; \
  153. printf "\033[2m→ https://github.com/go-modules-by-example/index/blob/master/019_apidiff/README.md\033[0m\n\n"; \
  154. false; \
  155. fi;
  156. @rm -rf tmp/apidiff-OLD tmp/apidiff-NEW
  157. @git clone --quiet --local .git/ tmp/apidiff-OLD
  158. @mkdir -p tmp/apidiff-NEW
  159. @tar -c --exclude .git --exclude tmp --exclude cmd . | tar -x -C tmp/apidiff-NEW
  160. @printf "\033[2m→ Running apidiff...\033[0m\n"
  161. @pritnf "tmp/apidiff-OLD/esapi tmp/apidiff-NEW/esapi\n"
  162. @{ \
  163. set -e ; \
  164. output=$$(apidiff tmp/apidiff-OLD/esapi tmp/apidiff-NEW/esapi); \
  165. printf "\n$$output\n\n"; \
  166. if echo $$output | grep -i -e 'incompatible' - > /dev/null 2>&1; then \
  167. printf "\n\033[31;1mFAILURE\033[0m\n\n"; \
  168. false; \
  169. else \
  170. printf "\033[32;1mSUCCESS\033[0m\n"; \
  171. fi; \
  172. }
  173. backport: ## Backport one or more commits from master into version branches
  174. ifeq ($(origin commits), undefined)
  175. @echo "Missing commit(s), exiting..."
  176. @exit 2
  177. endif
  178. ifndef branches
  179. $(eval branches_list = '7.17' '6.x' '5.x')
  180. else
  181. $(eval branches_list = $(shell echo $(branches) | tr ',' ' ') )
  182. endif
  183. $(eval commits_list = $(shell echo $(commits) | tr ',' ' '))
  184. @printf "\033[2m→ Backporting commits [$(commits)]\033[0m\n"
  185. @{ \
  186. set -e -o pipefail; \
  187. for commit in $(commits_list); do \
  188. git show --pretty='%h | %s' --no-patch $$commit; \
  189. done; \
  190. echo ""; \
  191. for branch in $(branches_list); do \
  192. printf "\033[2m→ $$branch\033[0m\n"; \
  193. git checkout $$branch; \
  194. for commit in $(commits_list); do \
  195. git cherry-pick -x $$commit; \
  196. done; \
  197. git status --short --branch; \
  198. echo ""; \
  199. done; \
  200. printf "\033[2m→ Push updates to Github:\033[0m\n"; \
  201. for branch in $(branches_list); do \
  202. echo "git push --verbose origin $$branch"; \
  203. done; \
  204. }
  205. release: ## Release a new version to Github
  206. $(eval branch = $(shell git rev-parse --abbrev-ref HEAD))
  207. $(eval current_version = $(shell cat internal/version/version.go | sed -Ee 's/const Client = "(.*)"/\1/' | tail -1))
  208. @printf "\033[2m→ [$(branch)] Current version: $(current_version)...\033[0m\n"
  209. ifndef version
  210. @printf "\033[31m[!] Missing version argument, exiting...\033[0m\n"
  211. @exit 2
  212. endif
  213. ifeq ($(version), "")
  214. @printf "\033[31m[!] Empty version argument, exiting...\033[0m\n"
  215. @exit 2
  216. endif
  217. @printf "\033[2m→ [$(branch)] Creating version $(version)...\033[0m\n"
  218. @{ \
  219. set -e -o pipefail; \
  220. cp internal/version/version.go internal/version/version.go.OLD && \
  221. cat internal/version/version.go.OLD | sed -e 's/Client = ".*"/Client = "$(version)"/' > internal/version/version.go && \
  222. go vet internal/version/version.go && \
  223. go fmt internal/version/version.go && \
  224. git diff --color-words internal/version/version.go | tail -n 1; \
  225. }
  226. @{ \
  227. set -e -o pipefail; \
  228. printf "\033[2m→ Commit and create Git tag? (y/n): \033[0m\c"; \
  229. read continue; \
  230. if [[ $$continue == "y" ]]; then \
  231. git add internal/version/version.go && \
  232. git commit --no-status --quiet --message "Release $(version)" && \
  233. git tag --annotate v$(version) --message 'Release $(version)'; \
  234. printf "\033[2m→ Push `git show --pretty='%h (%s)' --no-patch HEAD` to Github:\033[0m\n\n"; \
  235. printf "\033[1m git push origin HEAD && git push origin v$(version)\033[0m\n\n"; \
  236. mv internal/version/version.go.OLD internal/version/version.go && \
  237. git add internal/version/version.go && \
  238. original_version=`cat internal/version/version.go | sed -ne 's;^const Client = "\(.*\)"$$;\1;p'` && \
  239. git commit --no-status --quiet --message "Update version to $$original_version"; \
  240. printf "\033[2m→ Version updated to [$$original_version].\033[0m\n\n"; \
  241. else \
  242. echo "Aborting..."; \
  243. rm internal/version/version.go.OLD; \
  244. exit 1; \
  245. fi; \
  246. }
  247. godoc: ## Display documentation for the package
  248. @printf "\033[2m→ Generating documentation...\033[0m\n"
  249. @echo "* http://localhost:6060/pkg/github.com/elastic/go-elasticsearch/v7"
  250. @echo "* http://localhost:6060/pkg/github.com/elastic/go-elasticsearch/v7/esapi"
  251. @echo "* http://localhost:6060/pkg/github.com/elastic/go-elasticsearch/v7/estransport"
  252. @echo "* http://localhost:6060/pkg/github.com/elastic/go-elasticsearch/v7/esutil"
  253. @printf "\n"
  254. godoc --http=localhost:6060 --play
  255. cluster: ## Launch an Elasticsearch cluster with Docker
  256. $(eval version ?= "elasticsearch:7.17-SNAPSHOT")
  257. $(eval flavor ?= "core")
  258. $(eval elasticsearch_url = "http://es1:9200")
  259. ifdef ELASTICSEARCH_BUILD_VERSION
  260. $(eval version ?= "elasticsearch:"${ELASTICSEARCH_BUILD_VERSION})
  261. else
  262. $(eval version ?= "elasticsearch:"${ELASTICSEARCH_DEFAULT_BUILD_VERSION})
  263. endif
  264. ifeq ($(origin nodes), undefined)
  265. $(eval nodes = 1)
  266. endif
  267. @printf "\033[2m→ Launching %d node(s) of %s...\033[0m\n" $(nodes) $(version)
  268. ifeq ($(shell test $(nodes) && test $(nodes) -gt 1; echo $$?),0)
  269. $(eval detach ?= "true")
  270. else
  271. $(eval detach ?= "false")
  272. endif
  273. ifeq ($(flavor), platinum)
  274. $(eval elasticsearch_url = "https://elastic:elastic@es1:9200")
  275. $(eval xpack_env += --env "ELASTIC_PASSWORD=elastic")
  276. $(eval xpack_env += --env "xpack.license.self_generated.type=trial")
  277. $(eval xpack_env += --env "xpack.security.enabled=true")
  278. $(eval xpack_env += --env "xpack.security.http.ssl.enabled=true")
  279. $(eval xpack_env += --env "xpack.security.http.ssl.key=certs/testnode.key")
  280. $(eval xpack_env += --env "xpack.security.http.ssl.certificate=certs/testnode.crt")
  281. $(eval xpack_env += --env "xpack.security.http.ssl.certificate_authorities=certs/ca.crt")
  282. $(eval xpack_env += --env "xpack.security.transport.ssl.enabled=true")
  283. $(eval xpack_env += --env "xpack.security.transport.ssl.verification_mode=certificate")
  284. $(eval xpack_env += --env "xpack.security.transport.ssl.key=certs/testnode.key")
  285. $(eval xpack_env += --env "xpack.security.transport.ssl.certificate=certs/testnode.crt")
  286. $(eval xpack_env += --env "xpack.security.transport.ssl.certificate_authorities=certs/ca.crt")
  287. $(eval xpack_volumes += --volume "$(PWD)/.ci/certs/testnode.crt:/usr/share/elasticsearch/config/certs/testnode.crt")
  288. $(eval xpack_volumes += --volume "$(PWD)/.ci/certs/testnode.key:/usr/share/elasticsearch/config/certs/testnode.key")
  289. $(eval xpack_volumes += --volume "$(PWD)/.ci/certs/ca.crt:/usr/share/elasticsearch/config/certs/ca.crt")
  290. endif
  291. @docker network inspect elasticsearch > /dev/null 2>&1 || docker network create elasticsearch;
  292. @{ \
  293. for n in `seq 1 $(nodes)`; do \
  294. if [[ -z "$$port" ]]; then \
  295. hostport=$$((9199+$$n)); \
  296. else \
  297. hostport=$$port; \
  298. fi; \
  299. docker run \
  300. --name "es$$n" \
  301. --network elasticsearch \
  302. --env "node.name=es$$n" \
  303. --env "cluster.name=go-elasticsearch" \
  304. --env "cluster.initial_master_nodes=es1" \
  305. --env "discovery.seed_hosts=es1" \
  306. --env "cluster.routing.allocation.disk.threshold_enabled=false" \
  307. --env "bootstrap.memory_lock=true" \
  308. --env "node.attr.testattr=test" \
  309. --env "path.repo=/tmp" \
  310. --env "repositories.url.allowed_urls=http://snapshot.test*" \
  311. --env ES_JAVA_OPTS="-Xms1g -Xmx1g" \
  312. $(xpack_env) \
  313. --volume `echo $(version) | tr -C "[:alnum:]" '-'`-node-$$n-data:/usr/share/elasticsearch/data \
  314. $(xpack_volumes) \
  315. --publish $$hostport:9200 \
  316. --ulimit nofile=65536:65536 \
  317. --ulimit memlock=-1:-1 \
  318. --detach=$(detach) \
  319. --rm \
  320. docker.elastic.co/elasticsearch/$(version); \
  321. done \
  322. }
  323. ifdef detach
  324. @{ \
  325. printf "\033[2m→ Waiting for the cluster on $(elasticsearch_url)...\033[0m\n"; \
  326. docker run --network elasticsearch --rm appropriate/curl --max-time 120 --retry 120 --retry-delay 1 --retry-connrefused --show-error --silent --insecure $(elasticsearch_url); \
  327. output="\033[2m→ Cluster ready; to remove containers:"; \
  328. output="$$output docker rm -f"; \
  329. for n in `seq 1 $(nodes)`; do \
  330. output="$$output es$$n"; \
  331. done; \
  332. printf "$$output\033[0m\n"; \
  333. }
  334. endif
  335. cluster-update: ## Update the Docker image
  336. ifdef ELASTICSEARCH_BUILD_VERSION
  337. $(eval version ?= "elasticsearch:"${ELASTICSEARCH_BUILD_VERSION})
  338. else
  339. $(eval version ?= "elasticsearch:"${ELASTICSEARCH_DEFAULT_BUILD_VERSION})
  340. endif
  341. @printf "\033[2m→ Updating the Docker image...\033[0m\n"
  342. @docker pull docker.elastic.co/elasticsearch/$(version);
  343. cluster-clean: ## Remove unused Docker volumes and networks
  344. @printf "\033[2m→ Cleaning up Docker assets...\033[0m\n"
  345. docker volume prune --force
  346. docker network prune --force
  347. docker: ## Build the Docker image and run it
  348. docker build --file .ci/Dockerfile --tag elastic/go-elasticsearch .
  349. docker run -it --network elasticsearch --volume $(PWD)/tmp:/tmp:rw,delegated --rm elastic/go-elasticsearch
  350. ##@ Generator
  351. gen-api: ## Generate the API package from the JSON specification
  352. $(eval input ?= tmp/rest-api-spec)
  353. $(eval output ?= esapi)
  354. ifdef debug
  355. $(eval args += --debug)
  356. endif
  357. ifdef ELASTICSEARCH_BUILD_VERSION
  358. $(eval version = $(ELASTICSEARCH_BUILD_VERSION))
  359. else
  360. $(eval version = $(ELASTICSEARCH_DEFAULT_BUILD_VERSION))
  361. endif
  362. ifdef ELASTICSEARCH_BUILD_HASH
  363. $(eval build_hash = $(ELASTICSEARCH_BUILD_HASH))
  364. else
  365. $(eval build_hash = $(shell cat tmp/elasticsearch.json | jq ".projects.elasticsearch.commit_hash"))
  366. endif
  367. @printf "\033[2m→ Generating API package from specification ($(version):$(build_hash))...\033[0m\n"
  368. @{ \
  369. set -e; \
  370. trap "test -d .git && git checkout --quiet $(PWD)/internal/build/go.mod" INT TERM EXIT; \
  371. export ELASTICSEARCH_BUILD_VERSION=$(version) && \
  372. export ELASTICSEARCH_BUILD_HASH=$(build_hash) && \
  373. cd internal/build && \
  374. go run main.go apisource --input '$(PWD)/$(input)/api/*.json' --output '$(PWD)/$(output)' $(args) && \
  375. go run main.go apistruct --output '$(PWD)/$(output)'; \
  376. }
  377. gen-tests: ## Generate the API tests from the YAML specification
  378. $(eval input ?= tmp/rest-api-spec)
  379. $(eval output ?= esapi/test)
  380. ifdef debug
  381. $(eval args += --debug)
  382. endif
  383. ifdef ELASTICSEARCH_BUILD_VERSION
  384. $(eval version = $(ELASTICSEARCH_BUILD_VERSION))
  385. else
  386. $(eval version = $(ELASTICSEARCH_DEFAULT_BUILD_VERSION))
  387. endif
  388. ifdef ELASTICSEARCH_BUILD_HASH
  389. $(eval build_hash = $(ELASTICSEARCH_BUILD_HASH))
  390. else
  391. $(eval build_hash = $(shell cat tmp/elasticsearch.json | jq ".projects.elasticsearch.commit_hash"))
  392. endif
  393. @printf "\033[2m→ Generating API tests from specification ($(version):$(build_hash))...\033[0m\n"
  394. @{ \
  395. set -e; \
  396. trap "test -d .git && git checkout --quiet $(PWD)/internal/cmd/generate/go.mod" INT TERM EXIT; \
  397. export ELASTICSEARCH_BUILD_VERSION=$(version) && \
  398. export ELASTICSEARCH_BUILD_HASH=$(build_hash) && \
  399. rm -rf $(output)/*_test.go && \
  400. rm -rf $(output)/xpack && \
  401. cd internal/build && \
  402. go get golang.org/x/tools/cmd/goimports && \
  403. go generate ./... && \
  404. go run main.go apitests --input '$(PWD)/$(input)/test/free/**/*.y*ml' --output '$(PWD)/$(output)' $(args) && \
  405. go run main.go apitests --input '$(PWD)/$(input)/test/platinum/**/*.yml' --output '$(PWD)/$(output)/xpack' $(args) && \
  406. mkdir -p '$(PWD)/esapi/test/xpack/ml' && \
  407. mkdir -p '$(PWD)/esapi/test/xpack/ml-crud' && \
  408. mv $(PWD)/esapi/test/xpack/xpack_ml* $(PWD)/esapi/test/xpack/ml/ && \
  409. mv $(PWD)/esapi/test/xpack/ml/xpack_ml__jobs_crud_test.go $(PWD)/esapi/test/xpack/ml-crud/; \
  410. }
  411. gen-docs: ## Generate the skeleton of documentation examples
  412. $(eval input ?= tmp/alternatives_report.json)
  413. $(eval update ?= no)
  414. @{ \
  415. set -e; \
  416. trap "test -d .git && git checkout --quiet $(PWD)/internal/cmd/generate/go.mod" INT TERM EXIT; \
  417. if [[ $(update) == 'yes' ]]; then \
  418. printf "\033[2m→ Updating the alternatives_report.json file\033[0m\n" && \
  419. curl -s https://raw.githubusercontent.com/elastic/built-docs/master/raw/en/elasticsearch/reference/master/alternatives_report.json > tmp/alternatives_report.json; \
  420. fi; \
  421. printf "\033[2m→ Generating Go source files from Console input in [$(input)]\033[0m\n" && \
  422. ( cd '$(PWD)/internal/cmd/generate' && \
  423. go run main.go examples src --debug --input='$(PWD)/$(input)' --output='$(PWD)/.doc/examples/' \
  424. ) && \
  425. ( cd '$(PWD)/.doc/examples/src' && \
  426. if which gotestsum > /dev/null 2>&1 ; then \
  427. gotestsum --format=short-verbose; \
  428. else \
  429. go test -v $(testunitargs); \
  430. fi; \
  431. ) && \
  432. printf "\n\033[2m→ Generating ASCIIDoc files from Go source\033[0m\n" && \
  433. ( cd '$(PWD)/internal/build' && \
  434. go run main.go examples doc --debug --input='$(PWD)/.doc/examples/src/' --output='$(PWD)/.doc/examples/' \
  435. ) \
  436. }
  437. download-specs: ## Download the latest specs for the specified Elasticsearch version
  438. $(eval output ?= tmp)
  439. @mkdir -p tmp
  440. @{ \
  441. set -e; \
  442. printf "\n\033[2m→ Downloading latest Elasticsearch specs for version [$(ELASTICSEARCH_DEFAULT_BUILD_VERSION)]\033[0m\n" && \
  443. rm -rf $(output)/rest-api-spec && \
  444. rm -rf $(output)/elasticsearch.json && \
  445. cd internal/build && \
  446. go run main.go download-spec --output '$(PWD)/$(output)'; \
  447. }
  448. ##@ Other
  449. #------------------------------------------------------------------------------
  450. help: ## Display help
  451. @awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
  452. #------------- <https://suva.sh/posts/well-documented-makefiles> --------------
  453. .DEFAULT_GOAL := help
  454. .PHONY: help apidiff backport cluster cluster-clean cluster-update coverage docker examples gen-api gen-tests godoc lint release test test-api test-bench test-integ test-unit