Makefile 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml
  2. BUILD_NUMBER ?= local
  3. ifeq ($(BRANCH_NAME),)
  4. export BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)
  5. endif
  6. BRANCH_NAME_TAG_SAFE := $(subst /,--,$(BRANCH_NAME))
  7. ifeq ($(COMMIT_SHA),)
  8. export COMMIT_SHA := $(shell git rev-parse HEAD)
  9. endif
  10. PROJECT_NAME = web
  11. BUILD_DIR_NAME := web
  12. PWD := $(shell pwd)
  13. ifeq ($(MONOREPO),)
  14. export MONOREPO := $(shell cd ../../ && pwd)
  15. endif
  16. export OVERLEAF_CONFIG ?= /overleaf/services/web/test/acceptance/config/settings.test.saas.js
  17. export BASE_CONFIG ?= ${OVERLEAF_CONFIG}
  18. CFG_SAAS=/overleaf/services/web/test/acceptance/config/settings.test.saas.js
  19. CFG_SERVER_CE=/overleaf/services/web/test/acceptance/config/settings.test.server-ce.js
  20. CFG_SERVER_PRO=/overleaf/services/web/test/acceptance/config/settings.test.server-pro.js
  21. DOCKER_COMPOSE := BUILD_NUMBER=$(BUILD_NUMBER) \
  22. BRANCH_NAME=$(BRANCH_NAME_TAG_SAFE) \
  23. PROJECT_NAME=$(PROJECT_NAME) \
  24. MOCHA_GREP=${MOCHA_GREP} \
  25. docker compose ${DOCKER_COMPOSE_FLAGS}
  26. MODULE_DIRS := $(shell find modules -mindepth 1 -maxdepth 1 -type d -not -name '.git' )
  27. MODULE_MAKEFILES := $(MODULE_DIRS:=/Makefile)
  28. MODULE_NAME=$(shell basename $(MODULE))
  29. create_module_Makefiles: $(MODULE_MAKEFILES)
  30. $(MODULE_MAKEFILES): Makefile.module
  31. cp Makefile.module $@ || diff Makefile.module $@
  32. #
  33. # Clean
  34. #
  35. SHARD_PROJECT_NAMES = \
  36. unit_test_$(BUILD_DIR_NAME) \
  37. unit_test_all_$(BUILD_DIR_NAME) \
  38. unit_test_esm_$(BUILD_DIR_NAME) \
  39. unit_test_esm_watch_$(BUILD_DIR_NAME) \
  40. unit_test_mocha_$(BUILD_DIR_NAME) \
  41. unit_test_parallel_$(BUILD_DIR_NAME) \
  42. unit_test_parallel_make_$(BUILD_DIR_NAME) \
  43. acceptance_test_saas_$(BUILD_DIR_NAME) \
  44. acceptance_test_server_ce_$(BUILD_DIR_NAME) \
  45. acceptance_test_server_pro_$(BUILD_DIR_NAME) \
  46. acceptance_test_modules_merged_saas_$(BUILD_DIR_NAME) \
  47. acceptance_test_modules_merged_saas_1_$(BUILD_DIR_NAME) \
  48. acceptance_test_modules_merged_saas_2_$(BUILD_DIR_NAME) \
  49. acceptance_test_modules_merged_saas_3_$(BUILD_DIR_NAME) \
  50. acceptance_test_modules_merged_saas_4_$(BUILD_DIR_NAME) \
  51. acceptance_test_modules_merged_server_ce_$(BUILD_DIR_NAME) \
  52. acceptance_test_modules_merged_server_pro_$(BUILD_DIR_NAME) \
  53. frontend_test_$(BUILD_DIR_NAME) \
  54. test_frontend_ct_$(BUILD_DIR_NAME) \
  55. test_frontend_ct_core_other_$(BUILD_DIR_NAME) \
  56. test_frontend_ct_core_features_$(BUILD_DIR_NAME) \
  57. test_frontend_ct_modules_$(BUILD_DIR_NAME) \
  58. test_frontend_ct_editor_other_$(BUILD_DIR_NAME) \
  59. test_frontend_ct_editor_visual_$(BUILD_DIR_NAME) \
  60. tar_$(BUILD_DIR_NAME) \
  61. CLEAN_SHARDS=$(addprefix clean/,$(SHARD_PROJECT_NAMES))
  62. clean: $(CLEAN_SHARDS)
  63. -docker run --rm --volume /dev/shm:/dev/shm --user root $(IMAGE_CI) rm -rf /dev/shm/overleaf
  64. -docker rmi --force $(IMAGE_CI) $(IMAGE_CI)-dev $(IMAGE_CI)-pug $(IMAGE_CI)-webpack $(IMAGE_REPO_FINAL)
  65. -docker compose down --remove-orphans --rmi local --timeout 0 --volumes
  66. -git clean -dfX data/
  67. $(CLEAN_SHARDS): clean/%:
  68. -COMPOSE_PROJECT_NAME=$* docker compose down --remove-orphans --rmi local --timeout 0 --volumes
  69. clean_ci:
  70. $(DOCKER_COMPOSE) down -v -t 0
  71. docker container list | grep 'days ago' | cut -d ' ' -f 1 - | xargs -r docker container stop
  72. docker image prune -af --filter "until=48h"
  73. docker network prune -f
  74. #
  75. # Tests
  76. #
  77. test: test_unit test_acceptance test_frontend test_frontend_ct test_writefull
  78. test_module: test_unit_module test_acceptance_module
  79. #
  80. # Unit tests
  81. #
  82. test_unit: test_unit_all
  83. test_unit_all: export COMPOSE_PROJECT_NAME=unit_test_all_$(BUILD_DIR_NAME)
  84. test_unit_all: mongo_migrations_for_tests
  85. $(DOCKER_COMPOSE) run --rm test_unit npm run test:unit:all
  86. test_unit_all_silent: export COMPOSE_PROJECT_NAME=unit_test_all_$(BUILD_DIR_NAME)
  87. test_unit_all_silent: mongo_migrations_for_tests
  88. $(DOCKER_COMPOSE) run --rm test_unit npm run test:unit:all:silent
  89. test_unit_app: export COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME)
  90. test_unit_app: mongo_migrations_for_tests
  91. $(DOCKER_COMPOSE) run --name unit_test_$(BUILD_DIR_NAME) --rm test_unit
  92. test_unit_parallel: export JUNIT_ROOT_SUITE_NAME = ESM unit tests - parallel
  93. test_unit_parallel: export COMPOSE_PROJECT_NAME=unit_test_parallel_$(BUILD_DIR_NAME)
  94. test_unit_parallel: mongo_migrations_for_tests
  95. $(DOCKER_COMPOSE) run --rm test_unit npm run test:unit:parallel
  96. test_unit_sequential: export JUNIT_ROOT_SUITE_NAME = ESM unit tests - sequential
  97. test_unit_sequential: export COMPOSE_PROJECT_NAME=unit_test_sequential_$(BUILD_DIR_NAME)
  98. test_unit_sequential: mongo_migrations_for_tests
  99. $(DOCKER_COMPOSE) run --rm test_unit npm run test:unit:sequential
  100. test_unit_watch: export COMPOSE_PROJECT_NAME=unit_test_watch_$(BUILD_DIR_NAME)
  101. test_unit_watch: mongo_migrations_for_tests
  102. $(DOCKER_COMPOSE) run --rm test_unit npm run test:unit:watch
  103. TEST_SUITES = $(sort $(filter-out \
  104. $(wildcard test/unit/src/helpers/*), \
  105. $(wildcard test/unit/src/*/*)))
  106. MOCHA_CMD_LINE = \
  107. mocha \
  108. --exit \
  109. --file test/unit/bootstrap.js \
  110. --grep=${MOCHA_GREP} \
  111. --reporter spec \
  112. --timeout 25000 \
  113. .PHONY: $(TEST_SUITES)
  114. $(TEST_SUITES):
  115. $(MOCHA_CMD_LINE) $@
  116. J ?= 1
  117. test_unit_app_parallel_gnu_make: $(TEST_SUITES)
  118. test_unit_app_parallel_gnu_make_docker: export COMPOSE_PROJECT_NAME = \
  119. unit_test_parallel_make_$(BUILD_DIR_NAME)
  120. test_unit_app_parallel_gnu_make_docker: mongo_migrations_for_tests
  121. $(DOCKER_COMPOSE) run --rm test_unit \
  122. make test_unit_app_parallel_gnu_make --output-sync -j $(J)
  123. TEST_UNIT_MODULES = $(MODULE_DIRS:=/test_unit)
  124. $(TEST_UNIT_MODULES): %/test_unit: %/Makefile
  125. test_unit_modules: mongo_migrations_for_tests $(TEST_UNIT_MODULES)
  126. test_unit_module: mongo_migrations_for_tests
  127. $(MAKE) modules/$(MODULE_NAME)/test_unit
  128. mongo_migrations_for_tests:
  129. $(DOCKER_COMPOSE) run --rm --workdir /overleaf/tools/migrations test_unit npm run migrations -- migrate -t saas
  130. #
  131. # Frontend tests
  132. #
  133. test_frontend: export JUNIT_ROOT_SUITE_NAME = JSDOM frontend tests
  134. test_frontend:
  135. COMPOSE_PROJECT_NAME=frontend_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_frontend
  136. COMPOSE_PROJECT_NAME=frontend_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  137. #
  138. # Frontend component tests in Cypress
  139. #
  140. # Local development: use $ make test_frontend_ct
  141. #
  142. TEST_FRONTEND_CT_VARIANTS = \
  143. test_frontend_ct \
  144. test_frontend_ct_core_other \
  145. test_frontend_ct_core_features \
  146. test_frontend_ct_modules \
  147. test_frontend_ct_editor_other \
  148. test_frontend_ct_editor_visual \
  149. #
  150. # Writefull tests
  151. #
  152. test_writefull: export JUNIT_ROOT_SUITE_NAME = Writefull tests
  153. test_writefull:
  154. COMPOSE_PROJECT_NAME=writefull_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_writefull
  155. COMPOSE_PROJECT_NAME=writefull_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  156. # Note: The below cypress targets are for CI only
  157. build_test_frontend_ct:
  158. docker run --rm --volume /dev/shm:/dev/shm --user root $(IMAGE_CI) bash -ec 'for path in /overleaf/services/web/cypress/results /overleaf/services/web/node_modules/.cache; do mkdir -p $$path; chown -R node:node $$path; done && tar -cC / overleaf | tar -xC /dev/shm'
  159. test_frontend_ct_core_other: export CYPRESS_DOWNLOADS=./cypress/downloads/core
  160. test_frontend_ct_core_other: export CYPRESS_RESULTS=./cypress/results/core
  161. test_frontend_ct_core_other: export CYPRESS_SPEC_PATTERN=./test/frontend/**/*.spec.{js,jsx,ts,tsx}
  162. test_frontend_ct_core_other: export CYPRESS_EXCLUDE_SPEC_PATTERN=./test/frontend/features/**/*.spec.{js,jsx,ts,tsx}
  163. test_frontend_ct_core_features: export CYPRESS_DOWNLOADS=./cypress/downloads/core
  164. test_frontend_ct_core_features: export CYPRESS_RESULTS=./cypress/results/core
  165. test_frontend_ct_core_features: export CYPRESS_SPEC_PATTERN=./test/frontend/features/**/*.spec.{js,jsx,ts,tsx}
  166. test_frontend_ct_core_features: export CYPRESS_EXCLUDE_SPEC_PATTERN=./test/frontend/features/source-editor/**/*.spec.{js,jsx,ts,tsx}
  167. test_frontend_ct_modules: export CYPRESS_DOWNLOADS=./cypress/downloads/modules
  168. test_frontend_ct_modules: export CYPRESS_RESULTS=./cypress/results/modules
  169. test_frontend_ct_modules: export CYPRESS_SPEC_PATTERN=./modules/**/test/frontend/**/*.spec.{js,jsx,ts,tsx}
  170. test_frontend_ct_editor_other: export CYPRESS_DOWNLOADS=./cypress/downloads/editor_other
  171. test_frontend_ct_editor_other: export CYPRESS_RESULTS=./cypress/results/editor_other
  172. test_frontend_ct_editor_other: export CYPRESS_SPEC_PATTERN=./test/frontend/features/source-editor/**/*.spec.{js,jsx,ts,tsx}
  173. test_frontend_ct_editor_other: export CYPRESS_EXCLUDE_SPEC_PATTERN=./test/frontend/features/source-editor/components/codemirror-editor-visual*.spec.{js,jsx,ts,tsx}
  174. test_frontend_ct_editor_visual: export CYPRESS_DOWNLOADS=./cypress/downloads/editor_visual
  175. test_frontend_ct_editor_visual: export CYPRESS_RESULTS=./cypress/results/editor_visual
  176. test_frontend_ct_editor_visual: export CYPRESS_SPEC_PATTERN=./test/frontend/features/source-editor/components/codemirror-editor-visual*.spec.{js,jsx,ts,tsx}
  177. $(TEST_FRONTEND_CT_VARIANTS):
  178. COMPOSE_PROJECT_NAME=$@_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_frontend_ct
  179. COMPOSE_PROJECT_NAME=$@_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  180. #
  181. # Acceptance tests
  182. #
  183. test_acceptance: test_acceptance_app test_acceptance_modules
  184. test_acceptance_saas: test_acceptance_app_saas test_acceptance_modules_merged_saas
  185. test_acceptance_server_ce: test_acceptance_app_server_ce test_acceptance_modules_merged_server_ce
  186. test_acceptance_server_pro: test_acceptance_app_server_pro test_acceptance_modules_merged_server_pro
  187. TEST_ACCEPTANCE_APP := \
  188. test_acceptance_app_saas \
  189. test_acceptance_app_server_ce \
  190. test_acceptance_app_server_pro \
  191. test_acceptance_app: $(TEST_ACCEPTANCE_APP)
  192. test_acceptance_app_saas: export JUNIT_ROOT_SUITE_NAME = SaaS app acceptance tests
  193. test_acceptance_app_saas: export COMPOSE_PROJECT_NAME=acceptance_test_saas_$(BUILD_DIR_NAME)
  194. test_acceptance_app_saas: export OVERLEAF_CONFIG=$(CFG_SAAS)
  195. test_acceptance_app_server_ce: export JUNIT_ROOT_SUITE_NAME = Server CE app acceptance tests
  196. test_acceptance_app_server_ce: export COMPOSE_PROJECT_NAME=acceptance_test_server_ce_$(BUILD_DIR_NAME)
  197. test_acceptance_app_server_ce: export OVERLEAF_CONFIG=$(CFG_SERVER_CE)
  198. test_acceptance_app_server_pro: export JUNIT_ROOT_SUITE_NAME = Server Pro app acceptance tests
  199. test_acceptance_app_server_pro: export COMPOSE_PROJECT_NAME=acceptance_test_server_pro_$(BUILD_DIR_NAME)
  200. test_acceptance_app_server_pro: export OVERLEAF_CONFIG=$(CFG_SERVER_PRO)
  201. $(TEST_ACCEPTANCE_APP):
  202. $(DOCKER_COMPOSE) run --rm test_acceptance
  203. $(DOCKER_COMPOSE) down -v -t 0
  204. # We are using _make magic_ for turning these file-targets into calls to
  205. # sub-Makefiles in the individual modules.
  206. # These sub-Makefiles need to be kept in sync with the template, hence we
  207. # add a dependency on each modules Makefile and cross-link that to the
  208. # template at the very top of this file.
  209. # Example: `web$ make modules/server-ce-scripts/test_acceptance_server_ce`
  210. # Description: Run the acceptance tests of the server-ce-scripts module in an
  211. # Overleaf Community Edition Environment.
  212. # Break down:
  213. # Target: modules/server-ce-scripts/test_acceptance_server_ce
  214. # -> depends on modules/server-ce-scripts/Makefile
  215. # -> add environment variable BASE_CONFIG=$(CFG_SERVER_CE)
  216. # -> BASE_CONFIG=/overleaf/services/web/test/acceptance/config/settings.test.server-ce.js
  217. # -> automatic target: `make -C server-ce-scripts test_acceptance_server_ce`
  218. # -> automatic target: run `make test_acceptance_server_ce` in module
  219. # Target: modules/server-ce-scripts/Makefile
  220. # -> depends on Makefile.module
  221. # -> automatic target: copies the file when changed
  222. TEST_ACCEPTANCE_MODULES = $(MODULE_DIRS:=/test_acceptance)
  223. $(TEST_ACCEPTANCE_MODULES): %/test_acceptance: %/Makefile
  224. $(TEST_ACCEPTANCE_MODULES): modules/%/test_acceptance:
  225. $(MAKE) test_acceptance_module MODULE_NAME=$*
  226. TEST_ACCEPTANCE_MODULES_SAAS = $(MODULE_DIRS:=/test_acceptance_saas)
  227. $(TEST_ACCEPTANCE_MODULES_SAAS): %/test_acceptance_saas: %/Makefile
  228. $(TEST_ACCEPTANCE_MODULES_SAAS): export BASE_CONFIG = $(CFG_SAAS)
  229. # This line adds `/test_acceptance_saas` suffix to all items in $(MODULE_DIRS).
  230. TEST_ACCEPTANCE_MODULES_SERVER_CE = $(MODULE_DIRS:=/test_acceptance_server_ce)
  231. # This line adds a dependency on the modules Makefile.
  232. $(TEST_ACCEPTANCE_MODULES_SERVER_CE): %/test_acceptance_server_ce: %/Makefile
  233. # This line adds the environment variable BASE_CONFIG=$(CFG_SERVER_CE) to all
  234. # invocations of `web$ make modules/foo/test_acceptance_server_ce`.
  235. $(TEST_ACCEPTANCE_MODULES_SERVER_CE): export BASE_CONFIG = $(CFG_SERVER_CE)
  236. TEST_ACCEPTANCE_MODULES_SERVER_PRO = $(MODULE_DIRS:=/test_acceptance_server_pro)
  237. $(TEST_ACCEPTANCE_MODULES_SERVER_PRO): %/test_acceptance_server_pro: %/Makefile
  238. $(TEST_ACCEPTANCE_MODULES_SERVER_PRO): export BASE_CONFIG = $(CFG_SERVER_PRO)
  239. CLEAN_TEST_ACCEPTANCE_MODULES = $(MODULE_DIRS:=/clean_test_acceptance)
  240. $(CLEAN_TEST_ACCEPTANCE_MODULES): %/clean_test_acceptance: %/Makefile
  241. clean_test_acceptance_modules: $(CLEAN_TEST_ACCEPTANCE_MODULES)
  242. clean_ci: clean_test_acceptance_modules
  243. test_acceptance_module_noop:
  244. @echo
  245. @echo Module '$(MODULE_NAME)' does not run in ${LABEL}.
  246. @echo
  247. TEST_ACCEPTANCE_MODULE_MAYBE_IN := \
  248. test_acceptance_module_maybe_in_saas \
  249. test_acceptance_module_maybe_in_server_ce \
  250. test_acceptance_module_maybe_in_server_pro \
  251. test_acceptance_module: $(TEST_ACCEPTANCE_MODULE_MAYBE_IN)
  252. test_acceptance_module_maybe_in_saas: export BASE_CONFIG=$(CFG_SAAS)
  253. test_acceptance_module_maybe_in_server_ce: export BASE_CONFIG=$(CFG_SERVER_CE)
  254. test_acceptance_module_maybe_in_server_pro: export BASE_CONFIG=$(CFG_SERVER_PRO)
  255. # We need to figure out whether the module is loaded in a given environment.
  256. # This information is stored in the (base-)settings.
  257. # We get the full list of modules and check for a matching module entry.
  258. # Either the grep will find and emit the module, or exits with code 1, which
  259. # we handle with a fallback to a noop make target.
  260. # Run the node command in a docker compose container which provides the needed
  261. # npm dependencies (from disk in dev-env or from the CI image in CI).
  262. # Pick the test_unit service which is very light-weight -- the test_acceptance
  263. # service would start mongo/redis.
  264. $(TEST_ACCEPTANCE_MODULE_MAYBE_IN): test_acceptance_module_maybe_in_%:
  265. $(MAKE) $(shell \
  266. OVERLEAF_CONFIG=$(BASE_CONFIG) \
  267. $(DOCKER_COMPOSE) run --rm test_unit \
  268. node test/acceptance/getModuleTargets test_acceptance_$* \
  269. | grep -e /$(MODULE_NAME)/ || echo test_acceptance_module_noop LABEL=$* \
  270. )
  271. # See docs for test_acceptance_server_ce how this works.
  272. test_acceptance_module_saas: export BASE_CONFIG = $(CFG_SAAS)
  273. test_acceptance_module_saas:
  274. $(MAKE) modules/$(MODULE_NAME)/test_acceptance_saas
  275. test_acceptance_module_server_ce: export BASE_CONFIG = $(CFG_SERVER_CE)
  276. test_acceptance_module_server_ce:
  277. $(MAKE) modules/$(MODULE_NAME)/test_acceptance_server_ce
  278. test_acceptance_module_server_pro: export BASE_CONFIG = $(CFG_SERVER_PRO)
  279. test_acceptance_module_server_pro:
  280. $(MAKE) modules/$(MODULE_NAME)/test_acceptance_server_pro
  281. # See docs for test_acceptance_server_ce how this works.
  282. TEST_ACCEPTANCE_MODULES_MERGED_INNER = $(MODULE_DIRS:=/test_acceptance_merged_inner)
  283. $(TEST_ACCEPTANCE_MODULES_MERGED_INNER): %/test_acceptance_merged_inner: %/Makefile
  284. test_acceptance_modules_merged_inner:
  285. $(MAKE) $(shell \
  286. OVERLEAF_CONFIG=$(BASE_CONFIG) \
  287. node test/acceptance/getModuleTargets test_acceptance_merged_inner \
  288. )
  289. # inner loop for running saas tests in parallel
  290. no_more_targets:
  291. # If we ever have more than 40 modules, we need to add _5 targets to all the places and have it START at 41.
  292. test_acceptance_modules_merged_inner_1: export START=1
  293. test_acceptance_modules_merged_inner_2: export START=11
  294. test_acceptance_modules_merged_inner_3: export START=21
  295. test_acceptance_modules_merged_inner_4: export START=31
  296. TEST_ACCEPTANCE_MODULES_MERGED_INNER_SPLIT = \
  297. test_acceptance_modules_merged_inner_1 \
  298. test_acceptance_modules_merged_inner_2 \
  299. test_acceptance_modules_merged_inner_3 \
  300. test_acceptance_modules_merged_inner_4 \
  301. # The node script prints one module per line.
  302. # Using tail and head we skip over the first n=START entries and print the last 10.
  303. # Finally we check with grep for any targets in a batch and print a fallback if none were found.
  304. $(TEST_ACCEPTANCE_MODULES_MERGED_INNER_SPLIT):
  305. $(MAKE) $(shell \
  306. OVERLEAF_CONFIG=$(BASE_CONFIG) \
  307. node test/acceptance/getModuleTargets test_acceptance_merged_inner \
  308. | tail -n+$(START) | head -n 10 \
  309. | grep -e . || echo no_more_targets \
  310. )
  311. # See docs for test_acceptance_server_ce how this works.
  312. test_acceptance_modules_merged_saas: export JUNIT_ROOT_SUITE_NAME = SaaS modules acceptance tests
  313. test_acceptance_modules_merged_saas: export COMPOSE_PROJECT_NAME = \
  314. acceptance_test_modules_merged_saas_$(BUILD_DIR_NAME)
  315. test_acceptance_modules_merged_saas: export BASE_CONFIG = $(CFG_SAAS)
  316. test_acceptance_modules_merged_server_ce: export JUNIT_ROOT_SUITE_NAME = Server CE modules acceptance tests
  317. test_acceptance_modules_merged_server_ce: export COMPOSE_PROJECT_NAME = \
  318. acceptance_test_modules_merged_server_ce_$(BUILD_DIR_NAME)
  319. test_acceptance_modules_merged_server_ce: export BASE_CONFIG = $(CFG_SERVER_CE)
  320. test_acceptance_modules_merged_server_pro: export JUNIT_ROOT_SUITE_NAME = Server Pro modules acceptance tests
  321. test_acceptance_modules_merged_server_pro: export COMPOSE_PROJECT_NAME = \
  322. acceptance_test_modules_merged_server_pro_$(BUILD_DIR_NAME)
  323. test_acceptance_modules_merged_server_pro: export BASE_CONFIG = $(CFG_SERVER_PRO)
  324. # All these variants run the same command.
  325. # Each target has a different set of environment defined above.
  326. TEST_ACCEPTANCE_MODULES_MERGED_VARIANTS = \
  327. test_acceptance_modules_merged_saas \
  328. test_acceptance_modules_merged_server_ce \
  329. test_acceptance_modules_merged_server_pro \
  330. $(TEST_ACCEPTANCE_MODULES_MERGED_VARIANTS):
  331. $(DOCKER_COMPOSE) run --rm test_acceptance make test_acceptance_modules_merged_inner
  332. $(DOCKER_COMPOSE) down -v -t 0
  333. # outer loop for running saas tests in parallel
  334. TEST_ACCEPTANCE_MODULES_MERGED_SPLIT_SAAS = \
  335. test_acceptance_modules_merged_saas_1 \
  336. test_acceptance_modules_merged_saas_2 \
  337. test_acceptance_modules_merged_saas_3 \
  338. test_acceptance_modules_merged_saas_4 \
  339. test_acceptance_modules_merged_saas_1: export COMPOSE_PROJECT_NAME = \
  340. acceptance_test_modules_merged_saas_1_$(BUILD_DIR_NAME)
  341. test_acceptance_modules_merged_saas_2: export COMPOSE_PROJECT_NAME = \
  342. acceptance_test_modules_merged_saas_2_$(BUILD_DIR_NAME)
  343. test_acceptance_modules_merged_saas_3: export COMPOSE_PROJECT_NAME = \
  344. acceptance_test_modules_merged_saas_3_$(BUILD_DIR_NAME)
  345. test_acceptance_modules_merged_saas_4: export COMPOSE_PROJECT_NAME = \
  346. acceptance_test_modules_merged_saas_4_$(BUILD_DIR_NAME)
  347. $(TEST_ACCEPTANCE_MODULES_MERGED_SPLIT_SAAS): export BASE_CONFIG = $(CFG_SAAS)
  348. $(TEST_ACCEPTANCE_MODULES_MERGED_SPLIT_SAAS): export JUNIT_ROOT_SUITE_NAME = SaaS modules acceptance tests
  349. $(TEST_ACCEPTANCE_MODULES_MERGED_SPLIT_SAAS): test_acceptance_modules_merged_saas_%:
  350. $(DOCKER_COMPOSE) run --rm test_acceptance make test_acceptance_modules_merged_inner_$*
  351. $(DOCKER_COMPOSE) down -v -t 0
  352. test_acceptance_modules: $(TEST_ACCEPTANCE_MODULES_MERGED_VARIANTS)
  353. #
  354. # CI tests
  355. #
  356. rebase_coverage_reports:
  357. sed -i 's_path="/overleaf/_path="_' data/coverage/*/clover.xml
  358. # Create the bundle with full paths inside the monorepo to make it easier to organize them later.
  359. bundle_coverage_reports:
  360. cd ../../ && tar -czf services/web/data/coverage.tar.gz services/web/data/coverage/*/clover.xml
  361. ci:
  362. MOCHA_ARGS="--reporter tap" \
  363. $(MAKE) test
  364. #
  365. # Lint & format
  366. #
  367. # Run the linting commands in the scope of the monorepo.
  368. # Eslint and prettier (plus some configs) are on the root.
  369. RUN_LINTING_CI_MONOREPO = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.editorconfig --volume $(MONOREPO)/.eslintignore:/overleaf/.eslintignore --volume $(MONOREPO)/.eslintrc:/overleaf/.eslintrc --volume $(MONOREPO)/.prettierignore:/overleaf/.prettierignore --volume $(MONOREPO)/.prettierrc:/overleaf/.prettierrc --volume $(MONOREPO)/tsconfig.backend.json:/overleaf/tsconfig.backend.json --volume $(MONOREPO)/services/web/data/reports:/overleaf/services/web/data/reports --volume $(MONOREPO)/node_modules/.cache/:/overleaf/node_modules/.cache/ -w /overleaf $(IMAGE_CI) npm run --silent
  370. RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) --user node node:24.13.0 npm run --silent
  371. ORG_PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  372. RUN_LINT_FORMAT ?= \
  373. docker run --rm --env BRANCH_NAME --env CI --env COMMIT_SHA --env MONOREPO --volume $(MONOREPO)/.prettierignore:/overleaf/.prettierignore --volume $(MONOREPO)/.prettierrc:/overleaf/.prettierrc --volume ${PWD}/data/reports:/overleaf/services/web/data/reports --volume $(MONOREPO)/node_modules/.cache/:/overleaf/node_modules/.cache/ ${IMAGE_CI}
  374. NODE_MODULES_PATH := ${PATH}:${PWD}/node_modules/.bin:/overleaf/services/web/node_modules/.bin
  375. WITH_NODE_MODULES_PATH = \
  376. format_backend \
  377. format_frontend \
  378. format_misc \
  379. format_styles \
  380. format_test_app_unit \
  381. format_test_app_rest \
  382. format_test_modules \
  383. $(TEST_SUITES) \
  384. $(WITH_NODE_MODULES_PATH): export PATH=$(NODE_MODULES_PATH)
  385. WITH_CACHE_FOLDER = \
  386. lint_eslint \
  387. lint_stylelint \
  388. lint_in_docker \
  389. format_js \
  390. format_ci \
  391. format_fix \
  392. format_styles \
  393. format_styles_fix \
  394. format_pug \
  395. format_pug_fix \
  396. format_jenkins \
  397. format_jenkins_fix \
  398. format_in_docker \
  399. $(WITH_CACHE_FOLDER): ../../node_modules/.cache/prettier/
  400. ../../node_modules/.cache/prettier/:
  401. mkdir -p $@
  402. $(WITH_CACHE_FOLDER): ../../node_modules/.cache/eslint/
  403. ../../node_modules/.cache/eslint/:
  404. mkdir -p $@
  405. $(WITH_CACHE_FOLDER): ../../node_modules/.cache/stylelint/
  406. ../../node_modules/.cache/stylelint/:
  407. mkdir -p $@
  408. lint: lint_eslint
  409. lint_eslint:
  410. ifeq ($(CI),true)
  411. -npm run lint -- --format json --output-file data/reports/eslint.json
  412. sed -i 's_"filePath":"/overleaf_"filePath":"$(MONOREPO)_g' data/reports/eslint.json
  413. else
  414. npm run lint
  415. endif
  416. lint: lint_stylelint
  417. lint_stylelint:
  418. ifeq ($(CI),true)
  419. -npm run lint:styles -- --formatter json --output-file data/reports/stylelint.json
  420. sed -i 's_"source":"/overleaf_"source":"$(MONOREPO)_g' data/reports/stylelint.json
  421. else
  422. npm run lint:styles
  423. endif
  424. lint: lint_pug
  425. lint_pug:
  426. bin/lint_pug_templates
  427. lint: lint_locales
  428. lint_locales:
  429. bin/lint_locales
  430. lint: check_extracted_translations
  431. check_extracted_translations:
  432. bin/check_extracted_translations
  433. sort_locales:
  434. node scripts/translations/sort.js
  435. cleanup_unused_locales:
  436. node scripts/translations/cleanupUnusedLocales.js
  437. lint: lint_flag_res_send_usage
  438. lint_flag_res_send_usage:
  439. bin/lint_flag_res_send_usage
  440. lint: lint_overleafModuleImports
  441. lint_overleafModuleImports:
  442. node scripts/check_overleafModuleImports.mjs
  443. lint: typecheck_frontend
  444. typecheck_frontend:
  445. npm run --silent type-check
  446. lint: typecheck_backend
  447. typecheck_backend:
  448. npm run --silent type-check:backend
  449. lint_in_docker:
  450. $(RUN_LINT_FORMAT) make lint -j2 --output-sync
  451. format: format_js
  452. format_js:
  453. $(RUN_LINTING_MONOREPO) format -- services/web
  454. format_ci:
  455. $(RUN_LINTING_CI_MONOREPO) format -- services/web
  456. format_fix:
  457. $(RUN_LINTING_MONOREPO) format:fix -- services/web
  458. format_styles:
  459. $(RUN_LINTING_MONOREPO) format:styles
  460. format_styles_fix:
  461. $(RUN_LINTING_MONOREPO) format:styles:fix
  462. format_pug:
  463. $(RUN_LINTING_MONOREPO) format:pug
  464. format_pug_fix:
  465. $(RUN_LINTING_MONOREPO) format:pug:fix
  466. format_jenkins:
  467. $(RUN_LINTING_MONOREPO) format:jenkins
  468. format_jenkins_fix:
  469. $(RUN_LINTING_MONOREPO) format:jenkins:fix
  470. format_in_docker:
  471. $(RUN_LINT_FORMAT) npm run --prefix /overleaf format -- services/web
  472. SHELLCHECK_OPTS = \
  473. --shell=bash \
  474. --external-sources
  475. SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
  476. SHELLCHECK_FILES := { git ls-files "*.sh" -z; git grep -Plz "\A\#\!.*bash"; } | sort -zu
  477. shellcheck:
  478. @$(SHELLCHECK_FILES) | xargs -0 -r docker run --rm -v $(PWD):/mnt -w /mnt \
  479. koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
  480. shellcheck_fix:
  481. @$(SHELLCHECK_FILES) | while IFS= read -r -d '' file; do \
  482. diff=$$(docker run --rm -v $(PWD):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
  483. if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
  484. elif [ -n "$$diff" ]; then echo "$$file"; \
  485. else echo "\033[2m$$file\033[0m"; fi \
  486. done
  487. #
  488. # Build & publish
  489. #
  490. IMAGE_CI ?= ci/$(PROJECT_NAME):$(BRANCH_NAME_TAG_SAFE)-$(BUILD_NUMBER)
  491. IMAGE_REPO ?= us-east1-docker.pkg.dev/overleaf-ops/ol-docker/$(PROJECT_NAME)
  492. IMAGE_REPO_FINAL ?= $(IMAGE_REPO):$(BRANCH_NAME_TAG_SAFE)-$(BUILD_NUMBER)
  493. # A shared scratch tag that is used by all the pipelines for pushing the layers of the production image ASAP from a parallel step.
  494. # We do not want to make the image available before all the tests have passed.
  495. # Using a single tag avoids generating cruft in our docker repository / AR.
  496. IMAGE_SCRATCH ?= $(IMAGE_REPO):do-not-use-this-tag-for-deploys--it-is-used-for-early-pushes-in-ci
  497. IMAGE_CACHE ?= $(IMAGE_REPO):cache-$(shell cat \
  498. $(MONOREPO)/package.json \
  499. $(MONOREPO)/package-lock.json \
  500. $(MONOREPO)/libraries/access-token-encryptor/package.json \
  501. $(MONOREPO)/libraries/eslint-plugin/package.json \
  502. $(MONOREPO)/libraries/fetch-utils/package.json \
  503. $(MONOREPO)/libraries/logger/package.json \
  504. $(MONOREPO)/libraries/metrics/package.json \
  505. $(MONOREPO)/libraries/mongo-utils/package.json \
  506. $(MONOREPO)/libraries/o-error/package.json \
  507. $(MONOREPO)/libraries/object-persistor/package.json \
  508. $(MONOREPO)/libraries/overleaf-editor-core/package.json \
  509. $(MONOREPO)/libraries/promise-utils/package.json \
  510. $(MONOREPO)/libraries/ranges-tracker/package.json \
  511. $(MONOREPO)/libraries/redis-wrapper/package.json \
  512. $(MONOREPO)/libraries/settings/package.json \
  513. $(MONOREPO)/libraries/stream-utils/package.json \
  514. $(MONOREPO)/libraries/validation-tools/package.json \
  515. $(MONOREPO)/services/web/package.json \
  516. $(MONOREPO)/patches/* \
  517. | sha256sum | cut -d '-' -f1)
  518. export SENTRY_RELEASE ?= ${COMMIT_SHA}
  519. build_deps:
  520. docker build --pull \
  521. --build-arg BUILDKIT_INLINE_CACHE=1 \
  522. --cache-from $(IMAGE_CACHE) \
  523. --tag $(IMAGE_CACHE) \
  524. --target deps \
  525. --file Dockerfile \
  526. ../..
  527. build_dev:
  528. docker build \
  529. --build-arg SENTRY_RELEASE \
  530. --tag $(IMAGE_CI) \
  531. --tag $(IMAGE_CI)-dev \
  532. --target dev \
  533. --file Dockerfile \
  534. ../..
  535. build_webpack:
  536. $(MAKE) build_webpack_once \
  537. || $(MAKE) build_webpack_once
  538. build_webpack_once:
  539. docker build \
  540. --build-arg SENTRY_RELEASE \
  541. --tag $(IMAGE_CI)-webpack \
  542. --target webpack \
  543. --file Dockerfile \
  544. ../..
  545. build_pug:
  546. docker build \
  547. --build-arg SENTRY_RELEASE \
  548. --tag $(IMAGE_CI)-pug \
  549. --target pug \
  550. --file Dockerfile \
  551. ../..
  552. build:
  553. docker build \
  554. --build-arg SENTRY_RELEASE \
  555. --tag $(IMAGE_REPO_FINAL) \
  556. --tag $(IMAGE_SCRATCH) \
  557. --target app \
  558. --file Dockerfile \
  559. ../..
  560. publish:
  561. docker push $(IMAGE_REPO_FINAL)
  562. push_branch:
  563. docker push $(IMAGE_CACHE)
  564. push_scratch:
  565. docker push $(IMAGE_SCRATCH)
  566. SENTRY_IMAGE=getsentry/sentry-cli:2.16.1
  567. sentry_prefetch:
  568. docker pull $(SENTRY_IMAGE)
  569. sentry_upload:
  570. docker run --rm \
  571. --volume $(MONOREPO):$(MONOREPO) --workdir $(PWD) \
  572. --user "$(shell id -u):$(shell id -g)" \
  573. --env BRANCH_NAME --env SENTRY_RELEASE \
  574. --entrypoint bin/sentry_upload \
  575. $(SENTRY_IMAGE)
  576. tar:
  577. COMPOSE_PROJECT_NAME=tar_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm tar
  578. COMPOSE_PROJECT_NAME=tar_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  579. build_storybook:
  580. npm run lezer-latex:generate
  581. mkdir -p data/storybook/
  582. npm run build-storybook -- --output-dir data/storybook/$(BRANCH_NAME)
  583. storybook_index:
  584. mkdir -p data/storybook/
  585. m4 \
  586. -DLIST="$(shell gsutil ls "${BUCKET}/" \
  587. | sed -E "s@^${BUCKET}/([^/]+)/@\1@" \
  588. | grep -v -e index.html \
  589. | sort \
  590. | tr '\n' ,)" \
  591. -DBRANCH_NAME="${BRANCH_NAME}" .storybook/index.html.m4 \
  592. > data/storybook/index.html
  593. MODULE_TARGETS = \
  594. $(TEST_ACCEPTANCE_MODULES_SAAS) \
  595. $(TEST_ACCEPTANCE_MODULES_SERVER_CE) \
  596. $(TEST_ACCEPTANCE_MODULES_SERVER_PRO) \
  597. $(TEST_ACCEPTANCE_MODULES_MERGED_INNER) \
  598. $(CLEAN_TEST_ACCEPTANCE_MODULES) \
  599. $(TEST_UNIT_MODULES) \
  600. $(MODULE_TARGETS):
  601. $(MAKE) -C $(dir $@) $(notdir $@) BUILD_DIR_NAME=$(BUILD_DIR_NAME)
  602. .PHONY:
  603. $(MODULE_TARGETS) \
  604. compile_modules compile_modules_full clean_ci \
  605. test test_module mongo_migrations_for_tests test_unit test_unit_app \
  606. test_unit_modules test_unit_module test_frontend \
  607. test_acceptance test_acceptance_app test_acceptance_modules \
  608. test_acceptance_module ci format format_fix lint \
  609. shellcheck shellcheck_fix \
  610. build publish tar