Makefile 8.6 KB

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