Makefile 26 KB

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