Makefile 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. .DEFAULT_GOAL := help
  2. ifndef TAG
  3. TAG=alpine
  4. endif
  5. PORT ?= 8080
  6. NETWORK ?= freshrss-network
  7. # PHP versions tested by test-all-php-versions
  8. PHP_VERSIONS ?= 8.2 8.3 8.4 8.5 8.6
  9. # PostgreSQL database used by test-all-php-versions
  10. TESTS_PGSQL_IMAGE ?= postgres:19-alpine
  11. # detect docker or podman
  12. DOCKER ?= $(shell which docker 2>/dev/null || which podman 2>/dev/null)
  13. ifeq ($(DOCKER),)
  14. NO_DOCKER := 1
  15. endif
  16. ifdef NO_DOCKER
  17. PHP = $(shell which php)
  18. else
  19. PHP = $(DOCKER) run \
  20. --rm \
  21. --volume $(shell pwd):/var/www/FreshRSS:z \
  22. --env FRESHRSS_ENV=development \
  23. --name freshrss-php-cli \
  24. docker.io/freshrss/freshrss:$(TAG) \
  25. php
  26. endif
  27. ifeq ($(findstring alpine,$(TAG)),alpine)
  28. DOCKERFILE=Dockerfile-Alpine
  29. else
  30. DOCKERFILE=Dockerfile
  31. endif
  32. ##@ Docker
  33. .PHONY: build
  34. build: ## Build a Docker image
  35. $(DOCKER) build \
  36. --pull \
  37. --tag freshrss/freshrss:$(TAG) \
  38. --file Docker/$(DOCKERFILE) .
  39. .PHONY: start
  40. start: ## Start the development environment (use Docker)
  41. $(DOCKER) network create --driver bridge $(NETWORK) || true
  42. $(foreach extension,$(extensions),$(eval volumes=$(volumes) --volume $(extension):/var/www/FreshRSS/extensions/$(notdir $(extension)):z))
  43. @# No TTY and no --sig-proxy: a terminal resize (SIGWINCH) must not reach Apache, which treats it as a graceful stop.
  44. @# Ctrl+C is relayed by stopping the container instead.
  45. trap '$(DOCKER) stop freshrss-dev >/dev/null' INT TERM; \
  46. $(DOCKER) run \
  47. --rm \
  48. --sig-proxy=false \
  49. --volume $(shell pwd):/var/www/FreshRSS:z \
  50. $(volumes) \
  51. --publish $(PORT):80 \
  52. --env FRESHRSS_ENV=development \
  53. --name freshrss-dev \
  54. --network $(NETWORK) \
  55. docker.io/freshrss/freshrss:$(TAG) & \
  56. pid=$$!; \
  57. wait $$pid; \
  58. status=$$?; \
  59. if [ "$$status" -gt 128 ]; then wait $$pid; status=$$?; fi; \
  60. exit $$status
  61. .PHONY: stop
  62. stop: ## Stop FreshRSS container if any
  63. $(DOCKER) stop freshrss-dev || true
  64. $(DOCKER) network rm $(NETWORK) || true
  65. ##@ Tests and linter
  66. .PHONY: lint
  67. lint: bin/phpcs ## Run the linter on PHP files
  68. $(PHP) bin/phpcs . -p -s
  69. .PHONY: lint-fix
  70. lint-fix: bin/phpcbf ## Fix the errors detected by the linter
  71. $(PHP) bin/phpcbf . -p -s
  72. .PHONY: test
  73. test: bin/phpunit ## Run the PHP test suite
  74. $(PHP) bin/phpunit --bootstrap ./tests/bootstrap.php ./tests
  75. bin/composer:
  76. mkdir -p bin/
  77. cd bin ; \
  78. wget 'https://raw.githubusercontent.com/composer/getcomposer.org/acf8a43b6a379f3a5ef72ebf21979f4936a608fd/web/installer' && \
  79. echo 'aad0c40a36d9938664f5a34eb2ed39dbc1021792f9706dbcb9cd6d8001227c99 installer' | sha256sum -c - && \
  80. php installer -- --quiet --install-dir='./' --filename='composer' && \
  81. rm installer && \
  82. cd ..
  83. # building any of these builds them all
  84. vendor/bin/phpunit vendor/bin/phpcs vendor/bin/phpcbf vendor/bin/phpstan &: bin/composer
  85. bin/composer install --prefer-dist --no-progress
  86. # Any of these depend on the vendor/ target, and then symlink the vendor/bin/ to the bin/.
  87. # use -sf so if the symlink already exists it won't error out. Running this from a container often won't properly detect it already exists
  88. bin/phpunit bin/phpcs bin/phpcbf bin/phpstan : % : vendor/%
  89. ln -sf $< $@
  90. bin/typos:
  91. mkdir -p bin/
  92. cd bin ; \
  93. wget 'https://github.com/crate-ci/typos/releases/download/v1.49.0/typos-v1.49.0-x86_64-unknown-linux-musl.tar.gz' && \
  94. echo '48bd2d58e02ce713b8c0f1aa239e68ee4f7d8c551013135806e6aed3938d9e10 typos-v1.49.0-x86_64-unknown-linux-musl.tar.gz' | sha256sum -c - && \
  95. tar -xvf *.tar.gz './typos' && \
  96. chmod +x typos && \
  97. rm *.tar.gz ; \
  98. cd ..
  99. node_modules/.bin/eslint:
  100. npm install
  101. node_modules/.bin/rtlcss:
  102. npm install
  103. node_modules/.bin/svgo:
  104. npm install
  105. # TODO: Add composer install
  106. .PHONY: composer-test
  107. composer-test: bin/phpstan bin/composer
  108. bin/composer run-script test
  109. .PHONY: composer-fix
  110. composer-fix: bin/composer
  111. bin/composer run-script fix
  112. .PHONY: npm-test
  113. npm-test: node_modules/.bin/eslint
  114. npm test
  115. .PHONY: npm-fix
  116. npm-fix: node_modules/.bin/eslint
  117. npm run fix
  118. .PHONY: typos-test
  119. typos-test: bin/typos
  120. bin/typos
  121. # TODO: Add shellcheck, shfmt, hadolint
  122. .PHONY: test-all
  123. test-all: composer-test npm-test typos-test ## Run all tests
  124. .PHONY: test-all-php-versions
  125. test-all-php-versions: ## Run the test suite with every supported PHP version (Docker)
  126. @set -eu; \
  127. i=0; \
  128. $(DOCKER) rm --force freshrss-tests-db >/dev/null 2>&1 || true; \
  129. $(DOCKER) network create freshrss-tests-db-network >/dev/null 2>&1 || true; \
  130. cleanup() { $(DOCKER) rm --force freshrss-tests-db >/dev/null 2>&1 || true; $(DOCKER) network rm freshrss-tests-db-network >/dev/null 2>&1 || true; }; \
  131. trap cleanup EXIT INT TERM; \
  132. $(DOCKER) run --detach --rm \
  133. --name freshrss-tests-db \
  134. --network freshrss-tests-db-network \
  135. --env POSTGRES_HOST_AUTH_METHOD=trust \
  136. $(TESTS_PGSQL_IMAGE) >/dev/null; \
  137. until $(DOCKER) exec freshrss-tests-db pg_isready >/dev/null 2>&1; do \
  138. i=$$((i + 1)); [ $$i -lt 30 ] || { echo 'PostgreSQL database did not become ready in time.' >&2; exit 1; }; \
  139. sleep 1; \
  140. done; \
  141. for v in $(PHP_VERSIONS); do \
  142. echo "===== PHP $$v ====="; \
  143. $(DOCKER) build --quiet \
  144. --build-arg PHP_VERSION=$$v \
  145. --tag docker.io/freshrss/tests:php$$v \
  146. --file Docker/Dockerfile-tests . ; \
  147. $(DOCKER) run --rm \
  148. --network freshrss-tests-db-network \
  149. --env FRESHRSS_TEST_PGSQL_DSN='pgsql:host=freshrss-tests-db;dbname=postgres;user=postgres' \
  150. --volume $(shell pwd):/var/www/FreshRSS:z \
  151. --workdir /var/www/FreshRSS \
  152. docker.io/freshrss/tests:php$$v \
  153. sh -c "php --version | head -1 ; bin/composer test" ; \
  154. done
  155. .PHONY: fix-all
  156. fix-all: composer-fix npm-fix ## Run all fixes
  157. ##@ I18n
  158. .PHONY: i18n-add-file
  159. i18n-add-file: ## Add a new translation file to all supported languages
  160. ifndef key
  161. $(error To add a new file, you need to provide one in the "key" variable)
  162. endif
  163. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key)
  164. @echo File added.
  165. .PHONY: i18n-add-key
  166. i18n-add-key: ## Add a translation key to all supported languages
  167. ifndef key
  168. $(error To add a key, you need to provide one in the "key" variable)
  169. endif
  170. ifndef value
  171. $(error To add a key, you need to provide its value in the "value" variable)
  172. endif
  173. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)"
  174. @echo Key added.
  175. .PHONY: i18n-move-key
  176. i18n-move-key: ## Move an existing key into a new location
  177. ifndef key
  178. $(error To move a key, you need to provide one in the "key" variable)
  179. endif
  180. ifndef new-key
  181. $(error To specify a location to move the key to, you need to provide it in the "new-key" variable)
  182. endif
  183. @$(PHP) ./cli/manipulate.translation.php --action move --key $(key) --new-key "$(new-key)"
  184. @echo Key moved.
  185. .PHONY: i18n-add-language
  186. i18n-add-language: ## Add a new supported language
  187. ifndef lang
  188. $(error To add a new language, you need to provide one in the "lang" variable)
  189. endif
  190. $(PHP) ./cli/manipulate.translation.php --action add --language $(lang) --origin-language $(ref)
  191. @echo Language added.
  192. .PHONY: i18n-compile-plurals
  193. i18n-compile-plurals: ## Compile plural formulas from app/i18n/*/plurals.php
  194. @$(PHP) ./cli/compile.plurals.php --all
  195. @echo Plural files compiled.
  196. .PHONY: i18n-format
  197. i18n-format: ## Format I18N files
  198. @$(PHP) ./cli/manipulate.translation.php --action format
  199. @$(PHP) ./cli/compile.plurals.php --all
  200. @echo Files formatted.
  201. .PHONY: i18n-ignore-key
  202. i18n-ignore-key: ## Ignore a translation key for the selected language
  203. ifndef lang
  204. $(error To ignore a key, you need to provide a language in the "lang" variable)
  205. endif
  206. ifndef key
  207. $(error To ignore a key, you need to provide one in the "key" variable)
  208. endif
  209. @$(PHP) ./cli/manipulate.translation.php --action ignore --key $(key) --language $(lang)
  210. @echo Key ignored.
  211. .PHONY: i18n-ignore-unmodified-keys
  212. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  213. ifndef lang
  214. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  215. endif
  216. @$(PHP) ./cli/manipulate.translation.php --action ignore_unmodified --language $(lang)
  217. @echo Unmodified keys ignored.
  218. .PHONY: i18n-key-exists
  219. i18n-key-exists: ## Check if a translation key exists
  220. ifndef key
  221. $(error To check if a key exists, you need to provide one in the "key" variable)
  222. endif
  223. @$(PHP) ./cli/manipulate.translation.php --action exist --key $(key)
  224. .PHONY: i18n-remove-key
  225. i18n-remove-key: ## Remove a translation key from all supported languages
  226. ifndef key
  227. $(error To remove a key, you need to provide one in the "key" variable)
  228. endif
  229. @$(PHP) ./cli/manipulate.translation.php --action delete --key $(key)
  230. @echo Key removed.
  231. .PHONY: i18n-update-key
  232. i18n-update-key: ## Update a translation key in all supported languages
  233. ifndef key
  234. $(error To update a key, you need to provide one in the "key" variable)
  235. endif
  236. ifndef value
  237. $(error To update a key, you need to provide its value in the "value" variable)
  238. endif
  239. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)" --language en
  240. @echo Key updated.
  241. ##@ Tools
  242. .PHONY: pot
  243. pot: ## Generate POT templates for docs
  244. cd docs && ../cli/translation-update.sh
  245. .PHONY: readme
  246. readme: ## Generate translation progress in README file
  247. @$(PHP) ./cli/check.translation.php --generate-readme
  248. .PHONY: refresh
  249. refresh: ## Refresh feeds by fetching new messages
  250. @$(PHP) ./app/actualize_script.php
  251. .PHONY: rtl
  252. rtl: node_modules/.bin/rtlcss ## Generate RTL CSS files
  253. npm run-script rtlcss
  254. .PHONY: svgo
  255. svgo: node_modules/.bin/svgo ## Optimize SVG image files
  256. npm run-script svgo
  257. ##@ Help
  258. .PHONY: help
  259. help: ## Display this help
  260. @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-30s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)