Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. ##@ Documentation
  66. DOCS_HOST ?= 127.0.0.1
  67. DOCS_PORT ?= 4000
  68. define prepare_docs
  69. cd docs && \
  70. export BUNDLE_FROZEN=true && $(if , Always respect Gemfile.lock ) \
  71. export BUNDLE_PATH=.bundle && $(if , Specify repo-local path to run without root ) \
  72. (bundle check || bundle install)
  73. endef
  74. .PHONY: build-docs
  75. build-docs: ## Test building Jekyll documentation
  76. $(prepare_docs) && bundle exec jekyll build
  77. # Example usage: `make serve-docs DOCS_HOST=0.0.0.0 DOCS_PORT=8080`
  78. .PHONY: serve-docs
  79. serve-docs: ## Run local server for serving docs
  80. $(prepare_docs) && bundle exec jekyll serve -H $(DOCS_HOST) -P $(DOCS_PORT) --watch --incremental
  81. .PHONY: clean-docs
  82. clean-docs: ## Clean up generated Jekyll files
  83. rm -rf docs/_site docs/.jekyll-cache # Without removing installed bundles
  84. ##@ Tests and linter
  85. .PHONY: lint
  86. lint: bin/phpcs ## Run the linter on PHP files
  87. $(PHP) bin/phpcs . -p -s
  88. .PHONY: lint-fix
  89. lint-fix: bin/phpcbf ## Fix the errors detected by the linter
  90. $(PHP) bin/phpcbf . -p -s
  91. .PHONY: test
  92. test: bin/phpunit ## Run the PHP test suite
  93. $(PHP) bin/phpunit --bootstrap ./tests/bootstrap.php ./tests
  94. bin/composer:
  95. mkdir -p bin/
  96. cd bin ; \
  97. wget 'https://raw.githubusercontent.com/composer/getcomposer.org/acf8a43b6a379f3a5ef72ebf21979f4936a608fd/web/installer' && \
  98. echo 'aad0c40a36d9938664f5a34eb2ed39dbc1021792f9706dbcb9cd6d8001227c99 installer' | sha256sum -c - && \
  99. php installer -- --quiet --install-dir='./' --filename='composer' && \
  100. rm installer && \
  101. cd ..
  102. # building any of these builds them all
  103. vendor/bin/phpunit vendor/bin/phpcs vendor/bin/phpcbf vendor/bin/phpstan &: bin/composer
  104. bin/composer install --prefer-dist --no-progress
  105. # Any of these depend on the vendor/ target, and then symlink the vendor/bin/ to the bin/.
  106. # 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
  107. bin/phpunit bin/phpcs bin/phpcbf bin/phpstan : % : vendor/%
  108. ln -sf $< $@
  109. bin/typos:
  110. mkdir -p bin/
  111. cd bin ; \
  112. wget 'https://github.com/crate-ci/typos/releases/download/v1.49.0/typos-v1.49.0-x86_64-unknown-linux-musl.tar.gz' && \
  113. echo '48bd2d58e02ce713b8c0f1aa239e68ee4f7d8c551013135806e6aed3938d9e10 typos-v1.49.0-x86_64-unknown-linux-musl.tar.gz' | sha256sum -c - && \
  114. tar -xvf *.tar.gz './typos' && \
  115. chmod +x typos && \
  116. rm *.tar.gz ; \
  117. cd ..
  118. node_modules/.bin/eslint:
  119. npm install
  120. node_modules/.bin/rtlcss:
  121. npm install
  122. node_modules/.bin/svgo:
  123. npm install
  124. # TODO: Add composer install
  125. .PHONY: composer-test
  126. composer-test: bin/phpstan bin/composer
  127. bin/composer run-script test
  128. .PHONY: composer-fix
  129. composer-fix: bin/composer
  130. bin/composer run-script fix
  131. .PHONY: npm-test
  132. npm-test: node_modules/.bin/eslint
  133. npm test
  134. .PHONY: npm-fix
  135. npm-fix: node_modules/.bin/eslint
  136. npm run fix
  137. .PHONY: typos-test
  138. typos-test: bin/typos
  139. bin/typos
  140. # TODO: Add shellcheck, shfmt, hadolint
  141. .PHONY: test-all
  142. test-all: composer-test npm-test typos-test ## Run all tests
  143. .PHONY: test-all-php-versions
  144. test-all-php-versions: ## Run the test suite with every supported PHP version (Docker)
  145. @set -eu; \
  146. i=0; \
  147. $(DOCKER) rm --force freshrss-tests-db >/dev/null 2>&1 || true; \
  148. $(DOCKER) network create freshrss-tests-db-network >/dev/null 2>&1 || true; \
  149. cleanup() { $(DOCKER) rm --force freshrss-tests-db >/dev/null 2>&1 || true; $(DOCKER) network rm freshrss-tests-db-network >/dev/null 2>&1 || true; }; \
  150. trap cleanup EXIT INT TERM; \
  151. $(DOCKER) run --detach --rm \
  152. --name freshrss-tests-db \
  153. --network freshrss-tests-db-network \
  154. --env POSTGRES_HOST_AUTH_METHOD=trust \
  155. $(TESTS_PGSQL_IMAGE) >/dev/null; \
  156. until $(DOCKER) exec freshrss-tests-db pg_isready >/dev/null 2>&1; do \
  157. i=$$((i + 1)); [ $$i -lt 30 ] || { echo 'PostgreSQL database did not become ready in time.' >&2; exit 1; }; \
  158. sleep 1; \
  159. done; \
  160. for v in $(PHP_VERSIONS); do \
  161. echo "===== PHP $$v ====="; \
  162. $(DOCKER) build --quiet \
  163. --build-arg PHP_VERSION=$$v \
  164. --tag docker.io/freshrss/tests:php$$v \
  165. --file Docker/Dockerfile-tests . ; \
  166. $(DOCKER) run --rm \
  167. --network freshrss-tests-db-network \
  168. --env FRESHRSS_TEST_PGSQL_DSN='pgsql:host=freshrss-tests-db;dbname=postgres;user=postgres' \
  169. --volume $(shell pwd):/var/www/FreshRSS:z \
  170. --workdir /var/www/FreshRSS \
  171. docker.io/freshrss/tests:php$$v \
  172. sh -c "php --version | head -1 ; bin/composer test" ; \
  173. done
  174. .PHONY: fix-all
  175. fix-all: composer-fix npm-fix ## Run all fixes
  176. ##@ I18n
  177. .PHONY: i18n-add-file
  178. i18n-add-file: ## Add a new translation file to all supported languages
  179. ifndef key
  180. $(error To add a new file, you need to provide one in the "key" variable)
  181. endif
  182. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key)
  183. @echo File added.
  184. .PHONY: i18n-add-key
  185. i18n-add-key: ## Add a translation key to all supported languages
  186. ifndef key
  187. $(error To add a key, you need to provide one in the "key" variable)
  188. endif
  189. ifndef value
  190. $(error To add a key, you need to provide its value in the "value" variable)
  191. endif
  192. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)"
  193. @echo Key added.
  194. .PHONY: i18n-move-key
  195. i18n-move-key: ## Move an existing key into a new location
  196. ifndef key
  197. $(error To move a key, you need to provide one in the "key" variable)
  198. endif
  199. ifndef new-key
  200. $(error To specify a location to move the key to, you need to provide it in the "new-key" variable)
  201. endif
  202. @$(PHP) ./cli/manipulate.translation.php --action move --key $(key) --new-key "$(new-key)"
  203. @echo Key moved.
  204. .PHONY: i18n-add-language
  205. i18n-add-language: ## Add a new supported language
  206. ifndef lang
  207. $(error To add a new language, you need to provide one in the "lang" variable)
  208. endif
  209. $(PHP) ./cli/manipulate.translation.php --action add --language $(lang) --origin-language $(ref)
  210. @echo Language added.
  211. .PHONY: i18n-compile-plurals
  212. i18n-compile-plurals: ## Compile plural formulas from app/i18n/*/plurals.php
  213. @$(PHP) ./cli/compile.plurals.php --all
  214. @echo Plural files compiled.
  215. .PHONY: i18n-format
  216. i18n-format: ## Format I18N files
  217. @$(PHP) ./cli/manipulate.translation.php --action format
  218. @$(PHP) ./cli/compile.plurals.php --all
  219. @echo Files formatted.
  220. .PHONY: i18n-ignore-key
  221. i18n-ignore-key: ## Ignore a translation key for the selected language
  222. ifndef lang
  223. $(error To ignore a key, you need to provide a language in the "lang" variable)
  224. endif
  225. ifndef key
  226. $(error To ignore a key, you need to provide one in the "key" variable)
  227. endif
  228. @$(PHP) ./cli/manipulate.translation.php --action ignore --key $(key) --language $(lang)
  229. @echo Key ignored.
  230. .PHONY: i18n-ignore-unmodified-keys
  231. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  232. ifndef lang
  233. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  234. endif
  235. @$(PHP) ./cli/manipulate.translation.php --action ignore_unmodified --language $(lang)
  236. @echo Unmodified keys ignored.
  237. .PHONY: i18n-key-exists
  238. i18n-key-exists: ## Check if a translation key exists
  239. ifndef key
  240. $(error To check if a key exists, you need to provide one in the "key" variable)
  241. endif
  242. @$(PHP) ./cli/manipulate.translation.php --action exist --key $(key)
  243. .PHONY: i18n-remove-key
  244. i18n-remove-key: ## Remove a translation key from all supported languages
  245. ifndef key
  246. $(error To remove a key, you need to provide one in the "key" variable)
  247. endif
  248. @$(PHP) ./cli/manipulate.translation.php --action delete --key $(key)
  249. @echo Key removed.
  250. .PHONY: i18n-update-key
  251. i18n-update-key: ## Update a translation key in all supported languages
  252. ifndef key
  253. $(error To update a key, you need to provide one in the "key" variable)
  254. endif
  255. ifndef value
  256. $(error To update a key, you need to provide its value in the "value" variable)
  257. endif
  258. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)" --language en
  259. @echo Key updated.
  260. ##@ Tools
  261. .PHONY: pot
  262. pot: ## Generate POT templates for docs
  263. cd docs && ../cli/translation-update.sh
  264. .PHONY: readme
  265. readme: ## Generate translation progress in README file
  266. @$(PHP) ./cli/check.translation.php --generate-readme
  267. .PHONY: refresh
  268. refresh: ## Refresh feeds by fetching new messages
  269. @$(PHP) ./app/actualize_script.php
  270. .PHONY: rtl
  271. rtl: node_modules/.bin/rtlcss ## Generate RTL CSS files
  272. npm run-script rtlcss
  273. .PHONY: svgo
  274. svgo: node_modules/.bin/svgo ## Optimize SVG image files
  275. npm run-script svgo
  276. ##@ Help
  277. .PHONY: help
  278. help: ## Display this help
  279. @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)