Makefile 19 KB

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