Makefile 8.3 KB

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