Makefile 22 KB

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