Makefile 23 KB

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