Makefile 30 KB

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