Makefile 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. .DEFAULT_GOAL := help
  2. ifndef TAG
  3. TAG=alpine
  4. endif
  5. PORT ?= 8080
  6. NETWORK ?= freshrss-network
  7. ifdef NO_DOCKER
  8. PHP = $(shell which php)
  9. else
  10. PHP = docker run \
  11. --rm \
  12. --volume $(shell pwd):/var/www/FreshRSS:z \
  13. --env FRESHRSS_ENV=development \
  14. --name freshrss-php-cli \
  15. freshrss/freshrss:$(TAG) \
  16. php
  17. endif
  18. ifeq ($(findstring alpine,$(TAG)),alpine)
  19. DOCKERFILE=Dockerfile-Alpine
  20. else ifeq ($(findstring arm,$(TAG)),arm)
  21. DOCKERFILE=Dockerfile-QEMU-ARM
  22. else
  23. DOCKERFILE=Dockerfile
  24. endif
  25. ############
  26. ## Docker ##
  27. ############
  28. .PHONY: build
  29. build: ## Build a Docker image
  30. docker build \
  31. --pull \
  32. --tag freshrss/freshrss:$(TAG) \
  33. --file Docker/$(DOCKERFILE) .
  34. .PHONY: start
  35. start: ## Start the development environment (use Docker)
  36. docker network create --driver bridge $(NETWORK) || true
  37. $(foreach extension,$(extensions),$(eval volumes=$(volumes) --volume $(extension):/var/www/FreshRSS/extensions/$(notdir $(extension)):z))
  38. docker run \
  39. --rm \
  40. --volume $(shell pwd):/var/www/FreshRSS:z \
  41. $(volumes) \
  42. --publish $(PORT):80 \
  43. --env FRESHRSS_ENV=development \
  44. --name freshrss-dev \
  45. --network $(NETWORK) \
  46. freshrss/freshrss:$(TAG)
  47. .PHONY: stop
  48. stop: ## Stop FreshRSS container if any
  49. docker stop freshrss-dev || true
  50. docker network rm $(NETWORK) || true
  51. ######################
  52. ## Tests and linter ##
  53. ######################
  54. .PHONY: test
  55. test: bin/phpunit ## Run the test suite
  56. $(PHP) ./bin/phpunit --bootstrap ./tests/bootstrap.php ./tests
  57. .PHONY: lint
  58. lint: bin/phpcs ## Run the linter on the PHP files
  59. $(PHP) ./bin/phpcs . -p -s
  60. .PHONY: lint-fix
  61. lint-fix: bin/phpcbf ## Fix the errors detected by the linter
  62. $(PHP) ./bin/phpcbf . -p -s
  63. bin/composer:
  64. mkdir -p bin/
  65. wget 'https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer' -O - -q | php -- --quiet --install-dir='./bin/' --filename='composer'
  66. bin/phpunit:
  67. mkdir -p bin/
  68. wget -O bin/phpunit 'https://phar.phpunit.de/phpunit-9.5.20.phar'
  69. echo '6becad2da5c37f5ad101cc665ef05a2f1a6a45d2427c8edcc74f72c92fb1e05a bin/phpunit' | sha256sum -c - || rm bin/phpunit
  70. bin/phpcs:
  71. mkdir -p bin/
  72. wget -O bin/phpcs 'https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcs.phar'
  73. echo '7a14323a14af9f58302d15442492ee1076a8cd72c018a816cb44965bf3a9b015 bin/phpcs' | sha256sum -c - || rm bin/phpcs
  74. bin/phpcbf:
  75. mkdir -p bin/
  76. wget -O bin/phpcbf 'https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcbf.phar'
  77. echo 'c93c0e83cbda21c21f849ccf0f4b42979d20004a5a6172ed0ea270eca7ae6fa8 bin/phpcbf' | sha256sum -c - || rm bin/phpcbf
  78. bin/typos:
  79. mkdir -p bin/
  80. cd bin ; \
  81. wget -q 'https://github.com/crate-ci/typos/releases/download/v1.10.1/typos-v1.10.1-x86_64-unknown-linux-musl.tar.gz' && \
  82. tar -xvf *.tar.gz './typos' && \
  83. chmod +x typos && \
  84. rm *.tar.gz ; \
  85. cd ..
  86. node_modules/.bin/eslint:
  87. npm install
  88. vendor/bin/phpstan: bin/composer
  89. bin/composer install --prefer-dist --no-progress
  90. ##########
  91. ## I18N ##
  92. ##########
  93. .PHONY: i18n-format
  94. i18n-format: ## Format I18N files
  95. @$(PHP) ./cli/manipulate.translation.php -a format
  96. @echo Files formatted.
  97. .PHONY: i18n-add-language
  98. i18n-add-language: ## Add a new supported language
  99. ifndef lang
  100. $(error To add a new language, you need to provide one in the "lang" variable)
  101. endif
  102. $(PHP) ./cli/manipulate.translation.php -a add -l $(lang) -o $(ref)
  103. @echo Language added.
  104. .PHONY: i18n-add-key
  105. i18n-add-key: ## Add a translation key to all supported languages
  106. ifndef key
  107. $(error To add a key, you need to provide one in the "key" variable)
  108. endif
  109. ifndef value
  110. $(error To add a key, you need to provide its value in the "value" variable)
  111. endif
  112. @$(PHP) ./cli/manipulate.translation.php -a add -k $(key) -v "$(value)"
  113. @echo Key added.
  114. .PHONY: i18n-remove-key
  115. i18n-remove-key: ## Remove a translation key from all supported languages
  116. ifndef key
  117. $(error To remove a key, you need to provide one in the "key" variable)
  118. endif
  119. @$(PHP) ./cli/manipulate.translation.php -a delete -k $(key)
  120. @echo Key removed.
  121. .PHONY: i18n-update-key
  122. i18n-update-key: ## Update a translation key in all supported languages
  123. ifndef key
  124. $(error To update a key, you need to provide one in the "key" variable)
  125. endif
  126. ifndef value
  127. $(error To update a key, you need to provide its value in the "value" variable)
  128. endif
  129. @$(PHP) ./cli/manipulate.translation.php -a add -k $(key) -v "$(value)" -l en
  130. @echo Key updated.
  131. .PHONY: i18n-ignore-key
  132. i18n-ignore-key: ## Ignore a translation key for the selected language
  133. ifndef lang
  134. $(error To ignore a key, you need to provide a language in the "lang" variable)
  135. endif
  136. ifndef key
  137. $(error To ignore a key, you need to provide one in the "key" variable)
  138. endif
  139. @$(PHP) ./cli/manipulate.translation.php -a ignore -k $(key) -l $(lang)
  140. @echo Key ignored.
  141. .PHONY: i18n-ignore-unmodified-keys
  142. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  143. ifndef lang
  144. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  145. endif
  146. @$(PHP) ./cli/manipulate.translation.php -a ignore_unmodified -l $(lang)
  147. @echo Unmodified keys ignored.
  148. .PHONY: i18n-key-exists
  149. i18n-key-exists: ## Check if a translation key exists
  150. ifndef key
  151. $(error To check if a key exists, you need to provide one in the "key" variable)
  152. endif
  153. @$(PHP) ./cli/manipulate.translation.php -a exist -k $(key)
  154. ###########
  155. ## TOOLS ##
  156. ###########
  157. .PHONY: rtl
  158. rtl: ## Generate RTL CSS files
  159. rtlcss -d p/themes/ && find p/themes/ -type f -name '*.rtl.rtl.css' -delete
  160. .PHONY: pot
  161. pot: ## Generate POT templates for docs
  162. cd docs && ../cli/translation-update.sh
  163. .PHONY: refresh
  164. refresh: ## Refresh feeds by fetching new messages
  165. @$(PHP) ./app/actualize_script.php
  166. ###############################
  167. ## New commands aligned on CI #
  168. ## Work in progress #
  169. ###############################
  170. # TODO: Add composer install
  171. .PHONY: composer-test
  172. composer-test: vendor/bin/phpstan
  173. bin/composer run-script test
  174. .PHONY: composer-fix
  175. composer-fix:
  176. bin/composer run-script fix
  177. .PHONY: npm-test
  178. npm-test: node_modules/.bin/eslint
  179. npm test
  180. .PHONY: npm-fix
  181. npm-fix: node_modules/.bin/eslint
  182. npm run fix
  183. .PHONY: typos-test
  184. typos-test: bin/typos
  185. bin/typos
  186. # TODO: Add shellcheck, shfmt, hadolint
  187. .PHONY: test-all
  188. test-all: composer-test npm-test typos-test
  189. .PHONY: fix-all
  190. fix-all: composer-fix npm-fix
  191. ##########
  192. ## HELP ##
  193. ##########
  194. .PHONY: help
  195. help:
  196. @grep --extended-regexp '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'