Makefile 29 KB

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