Просмотр исходного кода

[misc] update build scripts (#23316)

* [misc] update build scripts

* [misc] make shellcheck happy

GitOrigin-RevId: 343655fda54aa7e835dd666dcd4218d61c58fd09
Jakob Ackermann 1 год назад
Родитель
Сommit
5404dcb93d

+ 19 - 1
services/chat/Makefile

@@ -39,6 +39,23 @@ RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.e
 # Same but from the top of the monorepo
 RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
 
+SHELLCHECK_OPTS = \
+	--shell=bash \
+	--external-sources
+SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
+
+shellcheck:
+	find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
+		koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
+
+shellcheck_fix:
+	@for file in $$(find . -type f -name "*.sh"); do \
+		diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
+		if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
+		elif [ -n "$$diff" ]; then echo "$$file"; \
+		else echo "\033[2m$$file\033[0m"; fi \
+	done
+
 format:
 	$(RUN_LINTING) format
 
@@ -63,7 +80,7 @@ typecheck:
 typecheck_ci:
 	$(RUN_LINTING_CI) types:check
 
-test: format lint typecheck test_unit test_acceptance
+test: format lint typecheck shellcheck test_unit test_acceptance
 
 test_unit:
 ifneq (,$(wildcard test/unit))
@@ -137,6 +154,7 @@ publish:
 	lint lint_fix \
 	build_types typecheck \
 	lint_ci format_ci typecheck_ci \
+	shellcheck shellcheck_fix \
 	test test_clean test_unit test_unit_clean \
 	test_acceptance test_acceptance_debug test_acceptance_pre_run \
 	test_acceptance_run test_acceptance_run_debug test_acceptance_clean \

+ 19 - 1
services/clsi/Makefile

@@ -40,6 +40,23 @@ RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.e
 # Same but from the top of the monorepo
 RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
 
+SHELLCHECK_OPTS = \
+	--shell=bash \
+	--external-sources
+SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
+
+shellcheck:
+	find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
+		koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
+
+shellcheck_fix:
+	@for file in $$(find . -type f -name "*.sh"); do \
+		diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
+		if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
+		elif [ -n "$$diff" ]; then echo "$$file"; \
+		else echo "\033[2m$$file\033[0m"; fi \
+	done
+
 format:
 	$(RUN_LINTING) format
 
@@ -64,7 +81,7 @@ typecheck:
 typecheck_ci:
 	$(RUN_LINTING_CI) types:check
 
-test: format lint typecheck test_unit test_acceptance
+test: format lint typecheck shellcheck test_unit test_acceptance
 
 test_unit:
 ifneq (,$(wildcard test/unit))
@@ -132,6 +149,7 @@ publish:
 	lint lint_fix \
 	build_types typecheck \
 	lint_ci format_ci typecheck_ci \
+	shellcheck shellcheck_fix \
 	test test_clean test_unit test_unit_clean \
 	test_acceptance test_acceptance_debug test_acceptance_pre_run \
 	test_acceptance_run test_acceptance_run_debug test_acceptance_clean \

+ 1 - 1
services/clsi/entrypoint.sh

@@ -2,7 +2,7 @@
 
 # add the node user to the docker group on the host
 DOCKER_GROUP=$(stat -c '%g' /var/run/docker.sock)
-groupadd --non-unique --gid ${DOCKER_GROUP} dockeronhost
+groupadd --non-unique --gid "${DOCKER_GROUP}" dockeronhost
 usermod -aG dockeronhost node
 
 # compatibility: initial volume setup

+ 19 - 1
services/contacts/Makefile

@@ -39,6 +39,23 @@ RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.e
 # Same but from the top of the monorepo
 RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
 
+SHELLCHECK_OPTS = \
+	--shell=bash \
+	--external-sources
+SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
+
+shellcheck:
+	find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
+		koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
+
+shellcheck_fix:
+	@for file in $$(find . -type f -name "*.sh"); do \
+		diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
+		if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
+		elif [ -n "$$diff" ]; then echo "$$file"; \
+		else echo "\033[2m$$file\033[0m"; fi \
+	done
+
 format:
 	$(RUN_LINTING) format
 
@@ -63,7 +80,7 @@ typecheck:
 typecheck_ci:
 	$(RUN_LINTING_CI) types:check
 
-test: format lint typecheck test_unit test_acceptance
+test: format lint typecheck shellcheck test_unit test_acceptance
 
 test_unit:
 ifneq (,$(wildcard test/unit))
@@ -137,6 +154,7 @@ publish:
 	lint lint_fix \
 	build_types typecheck \
 	lint_ci format_ci typecheck_ci \
+	shellcheck shellcheck_fix \
 	test test_clean test_unit test_unit_clean \
 	test_acceptance test_acceptance_debug test_acceptance_pre_run \
 	test_acceptance_run test_acceptance_run_debug test_acceptance_clean \

+ 19 - 1
services/docstore/Makefile

@@ -39,6 +39,23 @@ RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.e
 # Same but from the top of the monorepo
 RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
 
+SHELLCHECK_OPTS = \
+	--shell=bash \
+	--external-sources
+SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
+
+shellcheck:
+	find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
+		koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
+
+shellcheck_fix:
+	@for file in $$(find . -type f -name "*.sh"); do \
+		diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
+		if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
+		elif [ -n "$$diff" ]; then echo "$$file"; \
+		else echo "\033[2m$$file\033[0m"; fi \
+	done
+
 format:
 	$(RUN_LINTING) format
 
@@ -63,7 +80,7 @@ typecheck:
 typecheck_ci:
 	$(RUN_LINTING_CI) types:check
 
-test: format lint typecheck test_unit test_acceptance
+test: format lint typecheck shellcheck test_unit test_acceptance
 
 test_unit:
 ifneq (,$(wildcard test/unit))
@@ -137,6 +154,7 @@ publish:
 	lint lint_fix \
 	build_types typecheck \
 	lint_ci format_ci typecheck_ci \
+	shellcheck shellcheck_fix \
 	test test_clean test_unit test_unit_clean \
 	test_acceptance test_acceptance_debug test_acceptance_pre_run \
 	test_acceptance_run test_acceptance_run_debug test_acceptance_clean \

+ 2 - 2
services/docstore/test/acceptance/deps/healthcheck.sh

@@ -1,9 +1,9 @@
 #!/bin/sh
 
 # health check to allow 404 status code as valid
-STATUSCODE=$(curl --silent --output /dev/null --write-out "%{http_code}" $1)
+STATUSCODE=$(curl --silent --output /dev/null --write-out "%{http_code}" "$1")
 # will be 000 on non-http error (e.g. connection failure)
-if test $STATUSCODE -ge 500 || test $STATUSCODE -lt 200; then
+if test "$STATUSCODE" -ge 500 || test "$STATUSCODE" -lt 200; then
   exit 1
 fi
 exit 0

+ 19 - 1
services/document-updater/Makefile

@@ -39,6 +39,23 @@ RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.e
 # Same but from the top of the monorepo
 RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
 
+SHELLCHECK_OPTS = \
+	--shell=bash \
+	--external-sources
+SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
+
+shellcheck:
+	find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
+		koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
+
+shellcheck_fix:
+	@for file in $$(find . -type f -name "*.sh"); do \
+		diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
+		if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
+		elif [ -n "$$diff" ]; then echo "$$file"; \
+		else echo "\033[2m$$file\033[0m"; fi \
+	done
+
 format:
 	$(RUN_LINTING) format
 
@@ -63,7 +80,7 @@ typecheck:
 typecheck_ci:
 	$(RUN_LINTING_CI) types:check
 
-test: format lint typecheck test_unit test_acceptance
+test: format lint typecheck shellcheck test_unit test_acceptance
 
 test_unit:
 ifneq (,$(wildcard test/unit))
@@ -137,6 +154,7 @@ publish:
 	lint lint_fix \
 	build_types typecheck \
 	lint_ci format_ci typecheck_ci \
+	shellcheck shellcheck_fix \
 	test test_clean test_unit test_unit_clean \
 	test_acceptance test_acceptance_debug test_acceptance_pre_run \
 	test_acceptance_run test_acceptance_run_debug test_acceptance_clean \

+ 19 - 1
services/filestore/Makefile

@@ -39,6 +39,23 @@ RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.e
 # Same but from the top of the monorepo
 RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
 
+SHELLCHECK_OPTS = \
+	--shell=bash \
+	--external-sources
+SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
+
+shellcheck:
+	find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
+		koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
+
+shellcheck_fix:
+	@for file in $$(find . -type f -name "*.sh"); do \
+		diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
+		if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
+		elif [ -n "$$diff" ]; then echo "$$file"; \
+		else echo "\033[2m$$file\033[0m"; fi \
+	done
+
 format:
 	$(RUN_LINTING) format
 
@@ -63,7 +80,7 @@ typecheck:
 typecheck_ci:
 	$(RUN_LINTING_CI) types:check
 
-test: format lint typecheck test_unit test_acceptance
+test: format lint typecheck shellcheck test_unit test_acceptance
 
 test_unit:
 ifneq (,$(wildcard test/unit))
@@ -130,6 +147,7 @@ publish:
 	lint lint_fix \
 	build_types typecheck \
 	lint_ci format_ci typecheck_ci \
+	shellcheck shellcheck_fix \
 	test test_clean test_unit test_unit_clean \
 	test_acceptance test_acceptance_debug test_acceptance_pre_run \
 	test_acceptance_run test_acceptance_run_debug test_acceptance_clean \

+ 2 - 2
services/filestore/test/acceptance/deps/healthcheck.sh

@@ -1,9 +1,9 @@
 #!/bin/sh
 
 # health check to allow 404 status code as valid
-STATUSCODE=$(curl --silent --output /dev/null --write-out "%{http_code}" $1)
+STATUSCODE=$(curl --silent --output /dev/null --write-out "%{http_code}" "$1")
 # will be 000 on non-http error (e.g. connection failure)
-if test $STATUSCODE -ge 500 || test $STATUSCODE -lt 200; then
+if test "$STATUSCODE" -ge 500 || test "$STATUSCODE" -lt 200; then
   exit 1
 fi
 exit 0

+ 19 - 1
services/history-v1/Makefile

@@ -39,6 +39,23 @@ RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.e
 # Same but from the top of the monorepo
 RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
 
+SHELLCHECK_OPTS = \
+	--shell=bash \
+	--external-sources
+SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
+
+shellcheck:
+	find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
+		koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
+
+shellcheck_fix:
+	@for file in $$(find . -type f -name "*.sh"); do \
+		diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
+		if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
+		elif [ -n "$$diff" ]; then echo "$$file"; \
+		else echo "\033[2m$$file\033[0m"; fi \
+	done
+
 format:
 	$(RUN_LINTING) format
 
@@ -63,7 +80,7 @@ typecheck:
 typecheck_ci:
 	$(RUN_LINTING_CI) types:check
 
-test: format lint typecheck test_unit test_acceptance
+test: format lint typecheck shellcheck test_unit test_acceptance
 
 test_unit:
 ifneq (,$(wildcard test/unit))
@@ -137,6 +154,7 @@ publish:
 	lint lint_fix \
 	build_types typecheck \
 	lint_ci format_ci typecheck_ci \
+	shellcheck shellcheck_fix \
 	test test_clean test_unit test_unit_clean \
 	test_acceptance test_acceptance_debug test_acceptance_pre_run \
 	test_acceptance_run test_acceptance_run_debug test_acceptance_clean \

+ 19 - 1
services/notifications/Makefile

@@ -39,6 +39,23 @@ RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.e
 # Same but from the top of the monorepo
 RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
 
+SHELLCHECK_OPTS = \
+	--shell=bash \
+	--external-sources
+SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
+
+shellcheck:
+	find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
+		koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
+
+shellcheck_fix:
+	@for file in $$(find . -type f -name "*.sh"); do \
+		diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
+		if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
+		elif [ -n "$$diff" ]; then echo "$$file"; \
+		else echo "\033[2m$$file\033[0m"; fi \
+	done
+
 format:
 	$(RUN_LINTING) format
 
@@ -63,7 +80,7 @@ typecheck:
 typecheck_ci:
 	$(RUN_LINTING_CI) types:check
 
-test: format lint typecheck test_unit test_acceptance
+test: format lint typecheck shellcheck test_unit test_acceptance
 
 test_unit:
 ifneq (,$(wildcard test/unit))
@@ -137,6 +154,7 @@ publish:
 	lint lint_fix \
 	build_types typecheck \
 	lint_ci format_ci typecheck_ci \
+	shellcheck shellcheck_fix \
 	test test_clean test_unit test_unit_clean \
 	test_acceptance test_acceptance_debug test_acceptance_pre_run \
 	test_acceptance_run test_acceptance_run_debug test_acceptance_clean \

+ 19 - 1
services/project-history/Makefile

@@ -39,6 +39,23 @@ RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.e
 # Same but from the top of the monorepo
 RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
 
+SHELLCHECK_OPTS = \
+	--shell=bash \
+	--external-sources
+SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
+
+shellcheck:
+	find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
+		koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
+
+shellcheck_fix:
+	@for file in $$(find . -type f -name "*.sh"); do \
+		diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
+		if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
+		elif [ -n "$$diff" ]; then echo "$$file"; \
+		else echo "\033[2m$$file\033[0m"; fi \
+	done
+
 format:
 	$(RUN_LINTING) format
 
@@ -63,7 +80,7 @@ typecheck:
 typecheck_ci:
 	$(RUN_LINTING_CI) types:check
 
-test: format lint typecheck test_unit test_acceptance
+test: format lint typecheck shellcheck test_unit test_acceptance
 
 test_unit:
 ifneq (,$(wildcard test/unit))
@@ -137,6 +154,7 @@ publish:
 	lint lint_fix \
 	build_types typecheck \
 	lint_ci format_ci typecheck_ci \
+	shellcheck shellcheck_fix \
 	test test_clean test_unit test_unit_clean \
 	test_acceptance test_acceptance_debug test_acceptance_pre_run \
 	test_acceptance_run test_acceptance_run_debug test_acceptance_clean \

+ 19 - 1
services/real-time/Makefile

@@ -39,6 +39,23 @@ RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.e
 # Same but from the top of the monorepo
 RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:20.18.2 npm run --silent
 
+SHELLCHECK_OPTS = \
+	--shell=bash \
+	--external-sources
+SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
+
+shellcheck:
+	find . -type f -name "*.sh" -print0 | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
+		koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
+
+shellcheck_fix:
+	@for file in $$(find . -type f -name "*.sh"); do \
+		diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
+		if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
+		elif [ -n "$$diff" ]; then echo "$$file"; \
+		else echo "\033[2m$$file\033[0m"; fi \
+	done
+
 format:
 	$(RUN_LINTING) format
 
@@ -63,7 +80,7 @@ typecheck:
 typecheck_ci:
 	$(RUN_LINTING_CI) types:check
 
-test: format lint typecheck test_unit test_acceptance
+test: format lint typecheck shellcheck test_unit test_acceptance
 
 test_unit:
 ifneq (,$(wildcard test/unit))
@@ -130,6 +147,7 @@ publish:
 	lint lint_fix \
 	build_types typecheck \
 	lint_ci format_ci typecheck_ci \
+	shellcheck shellcheck_fix \
 	test test_clean test_unit test_unit_clean \
 	test_acceptance test_acceptance_debug test_acceptance_pre_run \
 	test_acceptance_run test_acceptance_run_debug test_acceptance_clean \