Makefile 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # This file was auto-generated, do not edit it directly.
  2. # Instead run bin/update_build_scripts from
  3. # https://github.com/overleaf/internal/
  4. BUILD_NUMBER ?= local
  5. BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)
  6. PROJECT_NAME = chat
  7. BUILD_DIR_NAME = $(shell pwd | xargs basename | tr -cd '[a-zA-Z0-9_.\-]')
  8. DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml
  9. DOCKER_COMPOSE := BUILD_NUMBER=$(BUILD_NUMBER) \
  10. BRANCH_NAME=$(BRANCH_NAME) \
  11. PROJECT_NAME=$(PROJECT_NAME) \
  12. MOCHA_GREP=${MOCHA_GREP} \
  13. docker compose ${DOCKER_COMPOSE_FLAGS}
  14. COMPOSE_PROJECT_NAME_TEST_ACCEPTANCE ?= test_acceptance_$(BUILD_DIR_NAME)
  15. DOCKER_COMPOSE_TEST_ACCEPTANCE = \
  16. COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME_TEST_ACCEPTANCE) $(DOCKER_COMPOSE)
  17. COMPOSE_PROJECT_NAME_TEST_UNIT ?= test_unit_$(BUILD_DIR_NAME)
  18. DOCKER_COMPOSE_TEST_UNIT = \
  19. COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME_TEST_UNIT) $(DOCKER_COMPOSE)
  20. clean:
  21. -docker rmi ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
  22. -docker rmi us-east1-docker.pkg.dev/overleaf-ops/ol-docker/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
  23. -$(DOCKER_COMPOSE_TEST_UNIT) down --rmi local
  24. -$(DOCKER_COMPOSE_TEST_ACCEPTANCE) down --rmi local
  25. HERE=$(shell pwd)
  26. MONOREPO=$(shell cd ../../ && pwd)
  27. # Run the linting commands in the scope of the monorepo.
  28. # Eslint and prettier (plus some configs) are on the root.
  29. RUN_LINTING = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(HERE) node:20.18.2 npm run --silent
  30. RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.editorconfig --volume $(MONOREPO)/.eslintignore:/overleaf/.eslintignore --volume $(MONOREPO)/.eslintrc:/overleaf/.eslintrc --volume $(MONOREPO)/.prettierignore:/overleaf/.prettierignore --volume $(MONOREPO)/.prettierrc:/overleaf/.prettierrc --volume $(MONOREPO)/tsconfig.backend.json:/overleaf/tsconfig.backend.json ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER) npm run --silent
  31. # Same but from the top of the monorepo
  32. RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
  33. SHELLCHECK_OPTS = \
  34. --shell=bash \
  35. --external-sources
  36. SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
  37. shellcheck:
  38. find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
  39. koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
  40. shellcheck_fix:
  41. @for file in $$(find . -type f -name "*.sh"); do \
  42. diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
  43. if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
  44. elif [ -n "$$diff" ]; then echo "$$file"; \
  45. else echo "\033[2m$$file\033[0m"; fi \
  46. done
  47. format:
  48. $(RUN_LINTING) format
  49. format_ci:
  50. $(RUN_LINTING_CI) format
  51. format_fix:
  52. $(RUN_LINTING) format:fix
  53. lint:
  54. $(RUN_LINTING) lint
  55. lint_ci:
  56. $(RUN_LINTING_CI) lint
  57. lint_fix:
  58. $(RUN_LINTING) lint:fix
  59. typecheck:
  60. $(RUN_LINTING) types:check
  61. typecheck_ci:
  62. $(RUN_LINTING_CI) types:check
  63. test: format lint typecheck shellcheck test_unit test_acceptance
  64. test_unit:
  65. ifneq (,$(wildcard test/unit))
  66. $(DOCKER_COMPOSE_TEST_UNIT) run --rm test_unit
  67. $(MAKE) test_unit_clean
  68. endif
  69. test_clean: test_unit_clean
  70. test_unit_clean:
  71. ifneq (,$(wildcard test/unit))
  72. $(DOCKER_COMPOSE_TEST_UNIT) down -v -t 0
  73. endif
  74. test_acceptance: test_acceptance_clean test_acceptance_pre_run test_acceptance_run
  75. $(MAKE) test_acceptance_clean
  76. test_acceptance_debug: test_acceptance_clean test_acceptance_pre_run test_acceptance_run_debug
  77. $(MAKE) test_acceptance_clean
  78. test_acceptance_run:
  79. ifneq (,$(wildcard test/acceptance))
  80. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) run --rm test_acceptance
  81. endif
  82. test_acceptance_run_debug:
  83. ifneq (,$(wildcard test/acceptance))
  84. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) run -p 127.0.0.9:19999:19999 --rm test_acceptance npm run test:acceptance -- --inspect=0.0.0.0:19999 --inspect-brk
  85. endif
  86. test_clean: test_acceptance_clean
  87. test_acceptance_clean:
  88. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) down -v -t 0
  89. test_acceptance_pre_run:
  90. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) up -d mongo
  91. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) exec -T mongo sh -c ' \
  92. while ! mongosh --eval "db.version()" > /dev/null; do \
  93. echo "Waiting for Mongo..."; \
  94. sleep 1; \
  95. done; \
  96. mongosh --eval "rs.initiate({ _id: \"overleaf\", members: [ { _id: 0, host: \"mongo:27017\" } ] })"'
  97. ifneq (,$(wildcard test/acceptance/js/scripts/pre-run))
  98. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) run --rm test_acceptance test/acceptance/js/scripts/pre-run
  99. endif
  100. benchmarks:
  101. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) run --rm test_acceptance npm run benchmarks
  102. build:
  103. docker build \
  104. --pull \
  105. --build-arg BUILDKIT_INLINE_CACHE=1 \
  106. --tag ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER) \
  107. --tag us-east1-docker.pkg.dev/overleaf-ops/ol-docker/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER) \
  108. --tag us-east1-docker.pkg.dev/overleaf-ops/ol-docker/$(PROJECT_NAME):$(BRANCH_NAME) \
  109. --cache-from us-east1-docker.pkg.dev/overleaf-ops/ol-docker/$(PROJECT_NAME):$(BRANCH_NAME) \
  110. --cache-from us-east1-docker.pkg.dev/overleaf-ops/ol-docker/$(PROJECT_NAME):main \
  111. --file Dockerfile \
  112. ../..
  113. tar:
  114. $(DOCKER_COMPOSE) up tar
  115. publish:
  116. docker push $(DOCKER_REPO)/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
  117. .PHONY: clean \
  118. format format_fix \
  119. lint lint_fix \
  120. build_types typecheck \
  121. lint_ci format_ci typecheck_ci \
  122. shellcheck shellcheck_fix \
  123. test test_clean test_unit test_unit_clean \
  124. test_acceptance test_acceptance_debug test_acceptance_pre_run \
  125. test_acceptance_run test_acceptance_run_debug test_acceptance_clean \
  126. benchmarks \
  127. build tar publish \