Makefile 22 KB

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