Makefile 21 KB

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