Makefile 24 KB

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