Makefile 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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
  21. DOCKERFILE=Dockerfile
  22. endif
  23. ##@ Docker
  24. .PHONY: build
  25. build: ## Build a Docker image
  26. docker build \
  27. --pull \
  28. --tag freshrss/freshrss:$(TAG) \
  29. --file Docker/$(DOCKERFILE) .
  30. .PHONY: start
  31. start: ## Start the development environment (use Docker)
  32. docker network create --driver bridge $(NETWORK) || true
  33. $(foreach extension,$(extensions),$(eval volumes=$(volumes) --volume $(extension):/var/www/FreshRSS/extensions/$(notdir $(extension)):z))
  34. docker run \
  35. -it \
  36. --rm \
  37. --volume $(shell pwd):/var/www/FreshRSS:z \
  38. $(volumes) \
  39. --publish $(PORT):80 \
  40. --env FRESHRSS_ENV=development \
  41. --name freshrss-dev \
  42. --network $(NETWORK) \
  43. freshrss/freshrss:$(TAG)
  44. .PHONY: stop
  45. stop: ## Stop FreshRSS container if any
  46. docker stop freshrss-dev || true
  47. docker network rm $(NETWORK) || true
  48. ##@ Tests and linter
  49. .PHONY: test
  50. test: bin/phpunit ## Run the test suite
  51. $(PHP) bin/phpunit --bootstrap ./tests/bootstrap.php ./tests
  52. .PHONY: lint
  53. lint: bin/phpcs ## Run the linter on the PHP files
  54. $(PHP) bin/phpcs . -p -s
  55. .PHONY: lint-fix
  56. lint-fix: bin/phpcbf ## Fix the errors detected by the linter
  57. $(PHP) bin/phpcbf . -p -s
  58. bin/composer:
  59. mkdir -p bin/
  60. wget 'https://raw.githubusercontent.com/composer/getcomposer.org/9e43d8a9b16fffa4dc9b090b9104dab7d815424a/web/installer' -O - -q | php -- --quiet --install-dir='./bin/' --filename='composer'
  61. # building any of these builds them all
  62. vendor/bin/phpunit vendor/bin/phpcs vendor/bin/phpcbf vendor/bin/phpstan &: bin/composer
  63. bin/composer install --prefer-dist --no-progress
  64. # Any of these depend on the vendor/ target, and then symlink the vendor/bin/ to the bin/.
  65. # 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
  66. bin/phpunit bin/phpcs bin/phpcbf bin/phpstan : % : vendor/%
  67. ln -sf $< $@
  68. bin/typos:
  69. mkdir -p bin/
  70. cd bin ; \
  71. wget -q 'https://github.com/crate-ci/typos/releases/download/v1.29.9/typos-v1.29.9-x86_64-unknown-linux-musl.tar.gz' && \
  72. tar -xvf *.tar.gz './typos' && \
  73. chmod +x typos && \
  74. rm *.tar.gz ; \
  75. cd ..
  76. node_modules/.bin/eslint:
  77. npm install
  78. node_modules/.bin/rtlcss:
  79. npm install
  80. ##@ I18n
  81. .PHONY: i18n-format
  82. i18n-format: ## Format I18N files
  83. @$(PHP) ./cli/manipulate.translation.php -a format
  84. @echo Files formatted.
  85. .PHONY: i18n-add-language
  86. i18n-add-language: ## Add a new supported language
  87. ifndef lang
  88. $(error To add a new language, you need to provide one in the "lang" variable)
  89. endif
  90. $(PHP) ./cli/manipulate.translation.php -a add -l $(lang) -o $(ref)
  91. @echo Language added.
  92. .PHONY: i18n-add-key
  93. i18n-add-key: ## Add a translation key to all supported languages
  94. ifndef key
  95. $(error To add a key, you need to provide one in the "key" variable)
  96. endif
  97. ifndef value
  98. $(error To add a key, you need to provide its value in the "value" variable)
  99. endif
  100. @$(PHP) ./cli/manipulate.translation.php -a add -k $(key) -v "$(value)"
  101. @echo Key added.
  102. .PHONY: i18n-remove-key
  103. i18n-remove-key: ## Remove a translation key from all supported languages
  104. ifndef key
  105. $(error To remove a key, you need to provide one in the "key" variable)
  106. endif
  107. @$(PHP) ./cli/manipulate.translation.php -a delete -k $(key)
  108. @echo Key removed.
  109. .PHONY: i18n-update-key
  110. i18n-update-key: ## Update a translation key in all supported languages
  111. ifndef key
  112. $(error To update a key, you need to provide one in the "key" variable)
  113. endif
  114. ifndef value
  115. $(error To update a key, you need to provide its value in the "value" variable)
  116. endif
  117. @$(PHP) ./cli/manipulate.translation.php -a add -k $(key) -v "$(value)" -l en
  118. @echo Key updated.
  119. .PHONY: i18n-ignore-key
  120. i18n-ignore-key: ## Ignore a translation key for the selected language
  121. ifndef lang
  122. $(error To ignore a key, you need to provide a language in the "lang" variable)
  123. endif
  124. ifndef key
  125. $(error To ignore a key, you need to provide one in the "key" variable)
  126. endif
  127. @$(PHP) ./cli/manipulate.translation.php -a ignore -k $(key) -l $(lang)
  128. @echo Key ignored.
  129. .PHONY: i18n-ignore-unmodified-keys
  130. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  131. ifndef lang
  132. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  133. endif
  134. @$(PHP) ./cli/manipulate.translation.php -a ignore_unmodified -l $(lang)
  135. @echo Unmodified keys ignored.
  136. .PHONY: i18n-key-exists
  137. i18n-key-exists: ## Check if a translation key exists
  138. ifndef key
  139. $(error To check if a key exists, you need to provide one in the "key" variable)
  140. endif
  141. @$(PHP) ./cli/manipulate.translation.php -a exist -k $(key)
  142. ##@ Tools
  143. .PHONY: rtl
  144. rtl: node_modules/.bin/rtlcss ## Generate RTL CSS files
  145. npm run-script rtlcss
  146. .PHONY: pot
  147. pot: ## Generate POT templates for docs
  148. cd docs && ../cli/translation-update.sh
  149. .PHONY: refresh
  150. refresh: ## Refresh feeds by fetching new messages
  151. @$(PHP) ./app/actualize_script.php
  152. ###############################
  153. ## New commands aligned on CI #
  154. ## Work in progress #
  155. ###############################
  156. # TODO: Add composer install
  157. .PHONY: composer-test
  158. composer-test: bin/phpstan bin/composer
  159. bin/composer run-script test
  160. .PHONY: composer-fix
  161. composer-fix: bin/composer
  162. bin/composer run-script fix
  163. .PHONY: npm-test
  164. npm-test: node_modules/.bin/eslint
  165. npm test
  166. .PHONY: npm-fix
  167. npm-fix: node_modules/.bin/eslint
  168. npm run fix
  169. .PHONY: typos-test
  170. typos-test: bin/typos
  171. bin/typos
  172. # TODO: Add shellcheck, shfmt, hadolint
  173. .PHONY: test-all
  174. test-all: composer-test npm-test typos-test
  175. .PHONY: fix-all
  176. fix-all: composer-fix npm-fix
  177. ##@ Help
  178. .PHONY: help
  179. help: ## Display this help
  180. @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)