Makefile 21 KB

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