Makefile 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml
  2. BUILD_NUMBER ?= local
  3. BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)
  4. PROJECT_NAME = web
  5. BUILD_DIR_NAME = $(shell pwd | xargs basename | tr -cd '[a-zA-Z0-9_.\-]')
  6. export SHARELATEX_CONFIG ?= /overleaf/services/web/test/acceptance/config/settings.test.saas.js
  7. export BASE_CONFIG ?= ${SHARELATEX_CONFIG}
  8. CFG_SAAS=/overleaf/services/web/test/acceptance/config/settings.test.saas.js
  9. CFG_SERVER_CE=/overleaf/services/web/test/acceptance/config/settings.test.server-ce.js
  10. CFG_SERVER_PRO=/overleaf/services/web/test/acceptance/config/settings.test.server-pro.js
  11. DOCKER_COMPOSE := BUILD_NUMBER=$(BUILD_NUMBER) \
  12. BRANCH_NAME=$(BRANCH_NAME) \
  13. PROJECT_NAME=$(PROJECT_NAME) \
  14. MOCHA_GREP=${MOCHA_GREP} \
  15. docker-compose ${DOCKER_COMPOSE_FLAGS}
  16. MODULE_DIRS := $(shell find modules -mindepth 1 -maxdepth 1 -type d -not -name '.git' )
  17. MODULE_MAKEFILES := $(MODULE_DIRS:=/Makefile)
  18. MODULE_NAME=$(shell basename $(MODULE))
  19. $(MODULE_MAKEFILES): Makefile.module
  20. cp Makefile.module $@ || diff Makefile.module $@
  21. #
  22. # Clean
  23. #
  24. clean:
  25. -$(DOCKER_COMPOSE) down --rmi local
  26. -COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  27. -COMPOSE_PROJECT_NAME=unit_test_all_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  28. -COMPOSE_PROJECT_NAME=unit_test_parallel_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  29. -COMPOSE_PROJECT_NAME=unit_test_parallel_make_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  30. -COMPOSE_PROJECT_NAME=acceptance_test_saas_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  31. -COMPOSE_PROJECT_NAME=acceptance_test_server_ce_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  32. -COMPOSE_PROJECT_NAME=acceptance_test_server_pro_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  33. -COMPOSE_PROJECT_NAME=acceptance_modules_merged_saas_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  34. -COMPOSE_PROJECT_NAME=acceptance_modules_merged_saas_1_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  35. -COMPOSE_PROJECT_NAME=acceptance_modules_merged_saas_2_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  36. -COMPOSE_PROJECT_NAME=acceptance_modules_merged_saas_3_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  37. -COMPOSE_PROJECT_NAME=acceptance_modules_merged_saas_4_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  38. -COMPOSE_PROJECT_NAME=acceptance_modules_merged_server_ce_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  39. -COMPOSE_PROJECT_NAME=acceptance_modules_merged_server_pro_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  40. -COMPOSE_PROJECT_NAME=karma_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  41. -COMPOSE_PROJECT_NAME=karma_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  42. -COMPOSE_PROJECT_NAME=frontend_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  43. -COMPOSE_PROJECT_NAME=tar_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down --rmi local
  44. clean_ci:
  45. $(DOCKER_COMPOSE) down -v -t 0
  46. docker container list | grep 'days ago' | cut -d ' ' -f 1 - | xargs -r docker container stop
  47. docker image prune -af --filter "until=48h"
  48. docker network prune -f
  49. #
  50. # Tests
  51. #
  52. test: test_unit test_karma test_acceptance test_frontend test_frontend_ct
  53. test_module: test_unit_module test_acceptance_module
  54. #
  55. # Unit tests
  56. #
  57. test_unit: test_unit_all
  58. test_unit_all:
  59. COMPOSE_PROJECT_NAME=unit_test_all_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_unit npm run test:unit:all
  60. COMPOSE_PROJECT_NAME=unit_test_all_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  61. test_unit_all_silent:
  62. COMPOSE_PROJECT_NAME=unit_test_all_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_unit npm run test:unit:all:silent
  63. COMPOSE_PROJECT_NAME=unit_test_all_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  64. test_unit_app:
  65. COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  66. COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --name unit_test_$(BUILD_DIR_NAME) --rm test_unit
  67. COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  68. TEST_SUITES = $(sort $(filter-out \
  69. $(wildcard test/unit/src/helpers/*), \
  70. $(wildcard test/unit/src/*/*)))
  71. MOCHA_CMD_LINE = \
  72. mocha \
  73. --exit \
  74. --file test/unit/bootstrap.js \
  75. --grep=${MOCHA_GREP} \
  76. --reporter spec \
  77. --timeout 25000 \
  78. .PHONY: $(TEST_SUITES)
  79. $(TEST_SUITES):
  80. $(MOCHA_CMD_LINE) $@
  81. J ?= 1
  82. test_unit_app_parallel_gnu_make: $(TEST_SUITES)
  83. test_unit_app_parallel_gnu_make_docker: export COMPOSE_PROJECT_NAME = \
  84. unit_test_parallel_make_$(BUILD_DIR_NAME)
  85. test_unit_app_parallel_gnu_make_docker:
  86. $(DOCKER_COMPOSE) down -v -t 0
  87. $(DOCKER_COMPOSE) run --rm test_unit \
  88. make test_unit_app_parallel_gnu_make --output-sync -j $(J)
  89. $(DOCKER_COMPOSE) down -v -t 0
  90. TEST_UNIT_MODULES = $(MODULE_DIRS:=/test_unit)
  91. $(TEST_UNIT_MODULES): %/test_unit: %/Makefile
  92. test_unit_modules: $(TEST_UNIT_MODULES)
  93. test_unit_module:
  94. $(MAKE) modules/$(MODULE_NAME)/test_unit
  95. #
  96. # Karma frontend tests
  97. #
  98. test_karma: build_test_karma test_karma_run
  99. test_karma_run:
  100. COMPOSE_PROJECT_NAME=karma_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  101. COMPOSE_PROJECT_NAME=karma_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_karma
  102. COMPOSE_PROJECT_NAME=karma_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  103. test_karma_build_run: build_test_karma test_karma_run
  104. #
  105. # Frontend tests
  106. #
  107. test_frontend:
  108. COMPOSE_PROJECT_NAME=frontend_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  109. COMPOSE_PROJECT_NAME=frontend_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_frontend
  110. COMPOSE_PROJECT_NAME=frontend_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  111. #
  112. # Frontend component tests in Cypress
  113. #
  114. test_frontend_ct:
  115. COMPOSE_PROJECT_NAME=frontend_test_ct_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  116. COMPOSE_PROJECT_NAME=frontend_test_ct_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_frontend_ct
  117. COMPOSE_PROJECT_NAME=frontend_test_ct_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  118. # Note: The below cypress targets are for CI only
  119. build_test_frontend_ct:
  120. COMPOSE_PROJECT_NAME=frontend_test_ct_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) build test_frontend_ct
  121. # Note: The 2nd build should use the cache from the 1st build.
  122. COMPOSE_PROJECT_NAME=frontend_test_ct_editor_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) build test_frontend_ct
  123. test_frontend_ct_core: export CYPRESS_RESULTS=./cypress/results/core
  124. test_frontend_ct_core: export CYPRESS_SPEC_PATTERN=./{test,modules/**/test}/frontend/**/*.spec.{js,ts,tsx}
  125. test_frontend_ct_core: export CYPRESS_EXCLUDE_SPEC_PATTERN=./test/frontend/features/source-editor/**/*.spec.{js,ts,tsx}
  126. test_frontend_ct_core:
  127. COMPOSE_PROJECT_NAME=frontend_test_ct_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  128. COMPOSE_PROJECT_NAME=frontend_test_ct_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_frontend_ct
  129. COMPOSE_PROJECT_NAME=frontend_test_ct_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  130. test_frontend_ct_editor: export CYPRESS_RESULTS=./cypress/results/editor
  131. test_frontend_ct_editor: export CYPRESS_SPEC_PATTERN=./test/frontend/features/source-editor/**/*.spec.{js,ts,tsx}
  132. test_frontend_ct_editor:
  133. COMPOSE_PROJECT_NAME=frontend_test_ct_editor_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  134. COMPOSE_PROJECT_NAME=frontend_test_ct_editor_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_frontend_ct
  135. COMPOSE_PROJECT_NAME=frontend_test_ct_editor_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  136. #
  137. # Acceptance tests
  138. #
  139. # Keep in sync with TEST_ACCEPTANCE_MONGO_INIT in Makefile.module
  140. TEST_ACCEPTANCE_MONGO_INIT := \
  141. $(DOCKER_COMPOSE) up -d mongo; \
  142. $(DOCKER_COMPOSE) exec -T mongo sh -c ' \
  143. while ! mongo --eval "db.version()" > /dev/null; do \
  144. echo "Waiting for Mongo..."; \
  145. sleep 1; \
  146. done; \
  147. mongo --eval "rs.initiate({ _id: \"overleaf\", members: [ { _id: 0, host: \"mongo:27017\" } ] })"'
  148. test_acceptance: test_acceptance_app test_acceptance_modules
  149. test_acceptance_saas: test_acceptance_app_saas test_acceptance_modules_merged_saas
  150. test_acceptance_server_ce: test_acceptance_app_server_ce test_acceptance_modules_merged_server_ce
  151. test_acceptance_server_pro: test_acceptance_app_server_pro test_acceptance_modules_merged_server_pro
  152. TEST_ACCEPTANCE_APP := \
  153. test_acceptance_app_saas \
  154. test_acceptance_app_server_ce \
  155. test_acceptance_app_server_pro \
  156. test_acceptance_app: $(TEST_ACCEPTANCE_APP)
  157. test_acceptance_app_saas: export COMPOSE_PROJECT_NAME=acceptance_test_saas_$(BUILD_DIR_NAME)
  158. test_acceptance_app_saas: export SHARELATEX_CONFIG=$(CFG_SAAS)
  159. test_acceptance_app_server_ce: export COMPOSE_PROJECT_NAME=acceptance_test_server_ce_$(BUILD_DIR_NAME)
  160. test_acceptance_app_server_ce: export SHARELATEX_CONFIG=$(CFG_SERVER_CE)
  161. test_acceptance_app_server_pro: export COMPOSE_PROJECT_NAME=acceptance_test_server_pro_$(BUILD_DIR_NAME)
  162. test_acceptance_app_server_pro: export SHARELATEX_CONFIG=$(CFG_SERVER_PRO)
  163. $(TEST_ACCEPTANCE_APP):
  164. $(DOCKER_COMPOSE) down -v -t 0
  165. $(TEST_ACCEPTANCE_MONGO_INIT)
  166. $(DOCKER_COMPOSE) run --rm test_acceptance
  167. $(DOCKER_COMPOSE) down -v -t 0
  168. # We are using _make magic_ for turning these file-targets into calls to
  169. # sub-Makefiles in the individual modules.
  170. # These sub-Makefiles need to be kept in sync with the template, hence we
  171. # add a dependency on each modules Makefile and cross-link that to the
  172. # template at the very top of this file.
  173. # Example: `web$ make modules/server-ce-scripts/test_acceptance_server_ce`
  174. # Description: Run the acceptance tests of the server-ce-scripts module in a
  175. # Server CE Environment.
  176. # Break down:
  177. # Target: modules/server-ce-scripts/test_acceptance_server_ce
  178. # -> depends on modules/server-ce-scripts/Makefile
  179. # -> add environment variable BASE_CONFIG=$(CFG_SERVER_CE)
  180. # -> BASE_CONFIG=/overleaf/services/web/test/acceptance/config/settings.test.server-ce.js
  181. # -> automatic target: `make -C server-ce-scripts test_acceptance_server_ce`
  182. # -> automatic target: run `make test_acceptance_server_ce` in module
  183. # Target: modules/server-ce-scripts/Makefile
  184. # -> depends on Makefile.module
  185. # -> automatic target: copies the file when changed
  186. TEST_ACCEPTANCE_MODULES = $(MODULE_DIRS:=/test_acceptance)
  187. $(TEST_ACCEPTANCE_MODULES): %/test_acceptance: %/Makefile
  188. $(TEST_ACCEPTANCE_MODULES): modules/%/test_acceptance:
  189. $(MAKE) test_acceptance_module MODULE_NAME=$*
  190. TEST_ACCEPTANCE_MODULES_SAAS = $(MODULE_DIRS:=/test_acceptance_saas)
  191. $(TEST_ACCEPTANCE_MODULES_SAAS): %/test_acceptance_saas: %/Makefile
  192. $(TEST_ACCEPTANCE_MODULES_SAAS): export BASE_CONFIG = $(CFG_SAAS)
  193. # This line adds `/test_acceptance_saas` suffix to all items in $(MODULE_DIRS).
  194. TEST_ACCEPTANCE_MODULES_SERVER_CE = $(MODULE_DIRS:=/test_acceptance_server_ce)
  195. # This line adds a dependency on the modules Makefile.
  196. $(TEST_ACCEPTANCE_MODULES_SERVER_CE): %/test_acceptance_server_ce: %/Makefile
  197. # This line adds the environment variable BASE_CONFIG=$(CFG_SERVER_CE) to all
  198. # invocations of `web$ make modules/foo/test_acceptance_server_ce`.
  199. $(TEST_ACCEPTANCE_MODULES_SERVER_CE): export BASE_CONFIG = $(CFG_SERVER_CE)
  200. TEST_ACCEPTANCE_MODULES_SERVER_PRO = $(MODULE_DIRS:=/test_acceptance_server_pro)
  201. $(TEST_ACCEPTANCE_MODULES_SERVER_PRO): %/test_acceptance_server_pro: %/Makefile
  202. $(TEST_ACCEPTANCE_MODULES_SERVER_PRO): export BASE_CONFIG = $(CFG_SERVER_PRO)
  203. CLEAN_TEST_ACCEPTANCE_MODULES = $(MODULE_DIRS:=/clean_test_acceptance)
  204. $(CLEAN_TEST_ACCEPTANCE_MODULES): %/clean_test_acceptance: %/Makefile
  205. clean_test_acceptance_modules: $(CLEAN_TEST_ACCEPTANCE_MODULES)
  206. clean_ci: clean_test_acceptance_modules
  207. test_acceptance_module_noop:
  208. @echo
  209. @echo Module '$(MODULE_NAME)' does not run in ${LABEL}.
  210. @echo
  211. TEST_ACCEPTANCE_MODULE_MAYBE_IN := \
  212. test_acceptance_module_maybe_in_saas \
  213. test_acceptance_module_maybe_in_server_ce \
  214. test_acceptance_module_maybe_in_server_pro \
  215. test_acceptance_module: $(TEST_ACCEPTANCE_MODULE_MAYBE_IN)
  216. test_acceptance_module_maybe_in_saas: export BASE_CONFIG=$(CFG_SAAS)
  217. test_acceptance_module_maybe_in_server_ce: export BASE_CONFIG=$(CFG_SERVER_CE)
  218. test_acceptance_module_maybe_in_server_pro: export BASE_CONFIG=$(CFG_SERVER_PRO)
  219. # We need to figure out whether the module is loaded in a given environment.
  220. # This information is stored in the (base-)settings.
  221. # We get the full list of modules and check for a matching module entry.
  222. # Either the grep will find and emit the module, or exits with code 1, which
  223. # we handle with a fallback to a noop make target.
  224. # Run the node command in a docker-compose container which provides the needed
  225. # npm dependencies (from disk in dev-env or from the CI image in CI).
  226. # Pick the test_unit service which is very light-weight -- the test_acceptance
  227. # service would start mongo/redis.
  228. $(TEST_ACCEPTANCE_MODULE_MAYBE_IN): test_acceptance_module_maybe_in_%:
  229. $(MAKE) $(shell \
  230. SHARELATEX_CONFIG=$(BASE_CONFIG) \
  231. $(DOCKER_COMPOSE) run --rm test_unit \
  232. node test/acceptance/getModuleTargets test_acceptance_$* \
  233. | grep -e /$(MODULE_NAME)/ || echo test_acceptance_module_noop LABEL=$* \
  234. )
  235. # See docs for test_acceptance_server_ce how this works.
  236. test_acceptance_module_saas: export BASE_CONFIG = $(CFG_SAAS)
  237. test_acceptance_module_saas:
  238. $(MAKE) modules/$(MODULE_NAME)/test_acceptance_saas
  239. test_acceptance_module_server_ce: export BASE_CONFIG = $(CFG_SERVER_CE)
  240. test_acceptance_module_server_ce:
  241. $(MAKE) modules/$(MODULE_NAME)/test_acceptance_server_ce
  242. test_acceptance_module_server_pro: export BASE_CONFIG = $(CFG_SERVER_PRO)
  243. test_acceptance_module_server_pro:
  244. $(MAKE) modules/$(MODULE_NAME)/test_acceptance_server_pro
  245. # See docs for test_acceptance_server_ce how this works.
  246. TEST_ACCEPTANCE_MODULES_MERGED_INNER = $(MODULE_DIRS:=/test_acceptance_merged_inner)
  247. $(TEST_ACCEPTANCE_MODULES_MERGED_INNER): %/test_acceptance_merged_inner: %/Makefile
  248. test_acceptance_modules_merged_inner:
  249. $(MAKE) $(shell \
  250. SHARELATEX_CONFIG=$(BASE_CONFIG) \
  251. node test/acceptance/getModuleTargets test_acceptance_merged_inner \
  252. )
  253. # inner loop for running saas tests in parallel
  254. no_more_targets:
  255. # If we ever have more than 40 modules, we need to add _5 targets to all the places and have it START at 41.
  256. test_acceptance_modules_merged_inner_1: export START=1
  257. test_acceptance_modules_merged_inner_2: export START=11
  258. test_acceptance_modules_merged_inner_3: export START=21
  259. test_acceptance_modules_merged_inner_4: export START=31
  260. TEST_ACCEPTANCE_MODULES_MERGED_INNER_SPLIT = \
  261. test_acceptance_modules_merged_inner_1 \
  262. test_acceptance_modules_merged_inner_2 \
  263. test_acceptance_modules_merged_inner_3 \
  264. test_acceptance_modules_merged_inner_4 \
  265. # The node script prints one module per line.
  266. # Using tail and head we skip over the first n=START entries and print the last 10.
  267. # Finally we check with grep for any targets in a batch and print a fallback if none were found.
  268. $(TEST_ACCEPTANCE_MODULES_MERGED_INNER_SPLIT):
  269. $(MAKE) $(shell \
  270. SHARELATEX_CONFIG=$(BASE_CONFIG) \
  271. node test/acceptance/getModuleTargets test_acceptance_merged_inner \
  272. | tail -n+$(START) | head -n 10 \
  273. | grep -e . || echo no_more_targets \
  274. )
  275. # See docs for test_acceptance_server_ce how this works.
  276. test_acceptance_modules_merged_saas: export COMPOSE_PROJECT_NAME = \
  277. acceptance_test_modules_merged_saas_$(BUILD_DIR_NAME)
  278. test_acceptance_modules_merged_saas: export BASE_CONFIG = $(CFG_SAAS)
  279. test_acceptance_modules_merged_server_ce: export COMPOSE_PROJECT_NAME = \
  280. acceptance_test_modules_merged_server_ce_$(BUILD_DIR_NAME)
  281. test_acceptance_modules_merged_server_ce: export BASE_CONFIG = $(CFG_SERVER_CE)
  282. test_acceptance_modules_merged_server_pro: export COMPOSE_PROJECT_NAME = \
  283. acceptance_test_modules_merged_server_pro_$(BUILD_DIR_NAME)
  284. test_acceptance_modules_merged_server_pro: export BASE_CONFIG = $(CFG_SERVER_PRO)
  285. # All these variants run the same command.
  286. # Each target has a different set of environment defined above.
  287. TEST_ACCEPTANCE_MODULES_MERGED_VARIANTS = \
  288. test_acceptance_modules_merged_saas \
  289. test_acceptance_modules_merged_server_ce \
  290. test_acceptance_modules_merged_server_pro \
  291. $(TEST_ACCEPTANCE_MODULES_MERGED_VARIANTS):
  292. $(DOCKER_COMPOSE) down -v -t 0
  293. $(TEST_ACCEPTANCE_MONGO_INIT)
  294. $(DOCKER_COMPOSE) run --rm test_acceptance make test_acceptance_modules_merged_inner
  295. $(DOCKER_COMPOSE) down -v -t 0
  296. # outer loop for running saas tests in parallel
  297. TEST_ACCEPTANCE_MODULES_MERGED_SPLIT_SAAS = \
  298. test_acceptance_modules_merged_saas_1 \
  299. test_acceptance_modules_merged_saas_2 \
  300. test_acceptance_modules_merged_saas_3 \
  301. test_acceptance_modules_merged_saas_4 \
  302. test_acceptance_modules_merged_saas_1: export COMPOSE_PROJECT_NAME = \
  303. acceptance_test_modules_merged_saas_1_$(BUILD_DIR_NAME)
  304. test_acceptance_modules_merged_saas_2: export COMPOSE_PROJECT_NAME = \
  305. acceptance_test_modules_merged_saas_2_$(BUILD_DIR_NAME)
  306. test_acceptance_modules_merged_saas_3: export COMPOSE_PROJECT_NAME = \
  307. acceptance_test_modules_merged_saas_3_$(BUILD_DIR_NAME)
  308. test_acceptance_modules_merged_saas_4: export COMPOSE_PROJECT_NAME = \
  309. acceptance_test_modules_merged_saas_4_$(BUILD_DIR_NAME)
  310. $(TEST_ACCEPTANCE_MODULES_MERGED_SPLIT_SAAS): export BASE_CONFIG = $(CFG_SAAS)
  311. $(TEST_ACCEPTANCE_MODULES_MERGED_SPLIT_SAAS): test_acceptance_modules_merged_saas_%:
  312. $(DOCKER_COMPOSE) down -v -t 0
  313. $(TEST_ACCEPTANCE_MONGO_INIT)
  314. $(DOCKER_COMPOSE) run --rm test_acceptance make test_acceptance_modules_merged_inner_$*
  315. $(DOCKER_COMPOSE) down -v -t 0
  316. test_acceptance_modules: $(TEST_ACCEPTANCE_MODULES_MERGED_VARIANTS)
  317. #
  318. # CI tests
  319. #
  320. ci:
  321. MOCHA_ARGS="--reporter tap" \
  322. $(MAKE) test
  323. #
  324. # Lint & format
  325. #
  326. ORG_PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  327. RUN_LINT_FORMAT ?= \
  328. docker run --rm ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
  329. NODE_MODULES_PATH := ${PATH}:${PWD}/node_modules/.bin:/overleaf/services/web/node_modules/.bin
  330. WITH_NODE_MODULES_PATH = \
  331. format_backend \
  332. format_frontend \
  333. format_misc \
  334. format_styles \
  335. format_test_app_unit \
  336. format_test_app_rest \
  337. format_test_modules \
  338. $(TEST_SUITES) \
  339. $(WITH_NODE_MODULES_PATH): export PATH=$(NODE_MODULES_PATH)
  340. lint: lint_backend
  341. lint_backend:
  342. npx eslint \
  343. 'app.{js,mjs,ts,tsx}' \
  344. 'app/**/*.{js,mjs,ts,tsx}' \
  345. 'modules/*/index.{js,mjs,ts,tsx}' \
  346. 'modules/*/app/**/*.{js,mjs,ts,tsx}' \
  347. --max-warnings=0
  348. lint: lint_frontend
  349. lint_frontend:
  350. npx eslint \
  351. 'frontend/**/*.{js,mjs,ts,tsx}' \
  352. 'modules/**/frontend/**/*.{js,mjs,ts,tsx}' \
  353. --max-warnings=0
  354. lint: lint_test
  355. lint_test: lint_test_app
  356. lint_test_app: lint_test_app_unit
  357. lint_test_app_unit:
  358. npx eslint \
  359. 'test/unit/**/*.{js,mjs,ts,tsx}' \
  360. --max-warnings=0
  361. lint_test_app: lint_test_app_rest
  362. lint_test_app_rest:
  363. npx eslint \
  364. 'test/**/*.{js,mjs,ts,tsx}' \
  365. --ignore-pattern 'test/unit/**/*.{js,mjs,ts,tsx}' \
  366. --max-warnings=0
  367. lint_test: lint_test_modules
  368. lint_test_modules:
  369. npx eslint \
  370. 'modules/*/test/**/*.{js,mjs,ts,tsx}' \
  371. --max-warnings=0
  372. lint: lint_misc
  373. # migrations, scripts, webpack config, karma config
  374. lint_misc:
  375. npx eslint . \
  376. --ignore-pattern 'app.{js,mjs,ts,tsx}' \
  377. --ignore-pattern 'app/**/*.{js,mjs,ts,tsx}' \
  378. --ignore-pattern 'modules/*/app/**/*.{js,mjs,ts,tsx}' \
  379. --ignore-pattern 'modules/*/index.{js,mjs,ts,tsx}' \
  380. --ignore-pattern 'frontend/**/*.{js,mjs,ts,tsx}' \
  381. --ignore-pattern 'modules/**/frontend/**/*.{js,mjs,ts,tsx}' \
  382. --ignore-pattern 'test/**/*.{js,mjs,ts,tsx}' \
  383. --ignore-pattern 'modules/*/test/**/*.{js,mjs,ts,tsx}' \
  384. --max-warnings=0
  385. lint: lint_pug
  386. lint_pug:
  387. bin/lint_pug_templates
  388. lint: lint_locales
  389. lint_locales:
  390. bin/lint_locales
  391. lint: check_extracted_translations
  392. check_extracted_translations:
  393. bin/check_extracted_translations
  394. sort_locales:
  395. node scripts/translations/sort.js
  396. cleanup_unused_locales:
  397. node scripts/translations/cleanupUnusedLocales.js
  398. lint: lint_flag_res_send_usage
  399. lint_flag_res_send_usage:
  400. bin/lint_flag_res_send_usage
  401. lint: typecheck_frontend
  402. typecheck_frontend:
  403. npx -p typescript tsc --noEmit
  404. lint_in_docker:
  405. $(RUN_LINT_FORMAT) make lint -j --output-sync
  406. format: format_js
  407. format_js:
  408. npm run --silent format
  409. format: format_styles
  410. format_styles:
  411. npm run --silent format:styles
  412. format_fix:
  413. npm run --silent format:fix
  414. format_styles_fix:
  415. npm run --silent format:styles:fix
  416. format_in_docker:
  417. $(RUN_LINT_FORMAT) make format -j --output-sync
  418. #
  419. # Build & publish
  420. #
  421. IMAGE_CI ?= ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
  422. IMAGE_REPO ?= gcr.io/overleaf-ops/$(PROJECT_NAME)
  423. IMAGE_REPO_BRANCH ?= $(IMAGE_REPO):$(BRANCH_NAME)
  424. IMAGE_REPO_MAIN ?= $(IMAGE_REPO):main
  425. IMAGE_REPO_FINAL ?= $(IMAGE_REPO_BRANCH)-$(BUILD_NUMBER)
  426. export SENTRY_RELEASE ?= ${COMMIT_SHA}
  427. build_deps:
  428. docker build --pull \
  429. --build-arg BUILDKIT_INLINE_CACHE=1 \
  430. --cache-from $(IMAGE_REPO_BRANCH)-deps \
  431. --cache-from $(IMAGE_REPO_MAIN)-deps \
  432. --tag $(IMAGE_REPO_BRANCH)-deps \
  433. --target deps \
  434. --file Dockerfile \
  435. ../..
  436. build_dev:
  437. docker build \
  438. --build-arg SENTRY_RELEASE \
  439. --tag $(IMAGE_CI) \
  440. --tag $(IMAGE_CI)-dev \
  441. --target dev \
  442. --file Dockerfile \
  443. ../..
  444. build_webpack:
  445. $(MAKE) build_webpack_once \
  446. || $(MAKE) build_webpack_once
  447. build_webpack_once:
  448. docker build \
  449. --build-arg SENTRY_RELEASE \
  450. --cache-from $(IMAGE_CI)-dev \
  451. --cache-from $(IMAGE_CI)-webpack \
  452. --tag $(IMAGE_CI)-webpack \
  453. --target webpack \
  454. --file Dockerfile \
  455. ../..
  456. build:
  457. docker build \
  458. --build-arg SENTRY_RELEASE \
  459. --cache-from $(IMAGE_CI)-webpack \
  460. --cache-from $(IMAGE_REPO_FINAL) \
  461. --tag $(IMAGE_REPO_FINAL) \
  462. --file Dockerfile \
  463. ../..
  464. build_test_karma:
  465. COMPOSE_PROJECT_NAME=karma_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) build test_karma
  466. publish:
  467. docker push $(DOCKER_REPO)/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
  468. tar:
  469. COMPOSE_PROJECT_NAME=tar_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm tar
  470. COMPOSE_PROJECT_NAME=tar_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  471. MODULE_TARGETS = \
  472. $(TEST_ACCEPTANCE_MODULES_SAAS) \
  473. $(TEST_ACCEPTANCE_MODULES_SERVER_CE) \
  474. $(TEST_ACCEPTANCE_MODULES_SERVER_PRO) \
  475. $(TEST_ACCEPTANCE_MODULES_MERGED_INNER) \
  476. $(CLEAN_TEST_ACCEPTANCE_MODULES) \
  477. $(TEST_UNIT_MODULES) \
  478. $(MODULE_TARGETS):
  479. $(MAKE) -C $(dir $@) $(notdir $@) BUILD_DIR_NAME=$(BUILD_DIR_NAME)
  480. .PHONY:
  481. $(MODULE_TARGETS) \
  482. compile_modules compile_modules_full clean_ci \
  483. test test_module test_unit test_unit_app \
  484. test_unit_modules test_unit_module test_karma test_karma_run \
  485. test_karma_build_run test_frontend test_acceptance test_acceptance_app \
  486. test_acceptance_modules test_acceptance_module ci format format_fix lint \
  487. build build_test_karma publish tar