Files
FreshRSS/Makefile
T

307 lines
9.6 KiB
Makefile

.DEFAULT_GOAL := help
ifndef TAG
TAG=alpine
endif
PORT ?= 8080
NETWORK ?= freshrss-network
# PHP versions tested by test-all-php-versions
PHP_VERSIONS ?= 8.2 8.3 8.4 8.5 8.6
# PostgreSQL database used by test-all-php-versions
TESTS_PGSQL_IMAGE ?= postgres:19-alpine
# detect docker or podman
DOCKER ?= $(shell which docker 2>/dev/null || which podman 2>/dev/null)
ifeq ($(DOCKER),)
NO_DOCKER := 1
endif
ifdef NO_DOCKER
PHP = $(shell which php)
else
PHP = $(DOCKER) run \
--rm \
--volume $(shell pwd):/var/www/FreshRSS:z \
--env FRESHRSS_ENV=development \
--name freshrss-php-cli \
docker.io/freshrss/freshrss:$(TAG) \
php
endif
ifeq ($(findstring alpine,$(TAG)),alpine)
DOCKERFILE=Dockerfile-Alpine
else
DOCKERFILE=Dockerfile
endif
##@ Docker
.PHONY: build
build: ## Build a Docker image
$(DOCKER) build \
--pull \
--tag freshrss/freshrss:$(TAG) \
--file Docker/$(DOCKERFILE) .
.PHONY: start
start: ## Start the development environment (use Docker)
$(DOCKER) network create --driver bridge $(NETWORK) || true
$(foreach extension,$(extensions),$(eval volumes=$(volumes) --volume $(extension):/var/www/FreshRSS/extensions/$(notdir $(extension)):z))
@# No TTY and no --sig-proxy: a terminal resize (SIGWINCH) must not reach Apache, which treats it as a graceful stop.
@# Ctrl+C is relayed by stopping the container instead.
trap '$(DOCKER) stop freshrss-dev >/dev/null' INT TERM; \
$(DOCKER) run \
--rm \
--sig-proxy=false \
--volume $(shell pwd):/var/www/FreshRSS:z \
$(volumes) \
--publish $(PORT):80 \
--env FRESHRSS_ENV=development \
--name freshrss-dev \
--network $(NETWORK) \
docker.io/freshrss/freshrss:$(TAG) & \
pid=$$!; \
wait $$pid; \
status=$$?; \
if [ "$$status" -gt 128 ]; then wait $$pid; status=$$?; fi; \
exit $$status
.PHONY: stop
stop: ## Stop FreshRSS container if any
$(DOCKER) stop freshrss-dev || true
$(DOCKER) network rm $(NETWORK) || true
##@ Tests and linter
.PHONY: lint
lint: bin/phpcs ## Run the linter on PHP files
$(PHP) bin/phpcs . -p -s
.PHONY: lint-fix
lint-fix: bin/phpcbf ## Fix the errors detected by the linter
$(PHP) bin/phpcbf . -p -s
.PHONY: test
test: bin/phpunit ## Run the PHP test suite
$(PHP) bin/phpunit --bootstrap ./tests/bootstrap.php ./tests
bin/composer:
mkdir -p bin/
cd bin ; \
wget 'https://raw.githubusercontent.com/composer/getcomposer.org/acf8a43b6a379f3a5ef72ebf21979f4936a608fd/web/installer' && \
echo 'aad0c40a36d9938664f5a34eb2ed39dbc1021792f9706dbcb9cd6d8001227c99 installer' | sha256sum -c - && \
php installer -- --quiet --install-dir='./' --filename='composer' && \
rm installer && \
cd ..
# building any of these builds them all
vendor/bin/phpunit vendor/bin/phpcs vendor/bin/phpcbf vendor/bin/phpstan &: bin/composer
bin/composer install --prefer-dist --no-progress
# Any of these depend on the vendor/ target, and then symlink the vendor/bin/ to the bin/.
# 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
bin/phpunit bin/phpcs bin/phpcbf bin/phpstan : % : vendor/%
ln -sf $< $@
bin/typos:
mkdir -p bin/
cd bin ; \
wget 'https://github.com/crate-ci/typos/releases/download/v1.49.0/typos-v1.49.0-x86_64-unknown-linux-musl.tar.gz' && \
echo '48bd2d58e02ce713b8c0f1aa239e68ee4f7d8c551013135806e6aed3938d9e10 typos-v1.49.0-x86_64-unknown-linux-musl.tar.gz' | sha256sum -c - && \
tar -xvf *.tar.gz './typos' && \
chmod +x typos && \
rm *.tar.gz ; \
cd ..
node_modules/.bin/eslint:
npm install
node_modules/.bin/rtlcss:
npm install
node_modules/.bin/svgo:
npm install
# TODO: Add composer install
.PHONY: composer-test
composer-test: bin/phpstan bin/composer
bin/composer run-script test
.PHONY: composer-fix
composer-fix: bin/composer
bin/composer run-script fix
.PHONY: npm-test
npm-test: node_modules/.bin/eslint
npm test
.PHONY: npm-fix
npm-fix: node_modules/.bin/eslint
npm run fix
.PHONY: typos-test
typos-test: bin/typos
bin/typos
# TODO: Add shellcheck, shfmt, hadolint
.PHONY: test-all
test-all: composer-test npm-test typos-test ## Run all tests
.PHONY: test-all-php-versions
test-all-php-versions: ## Run the test suite with every supported PHP version (Docker)
@set -eu; \
i=0; \
$(DOCKER) rm --force freshrss-tests-db >/dev/null 2>&1 || true; \
$(DOCKER) network create freshrss-tests-db-network >/dev/null 2>&1 || true; \
cleanup() { $(DOCKER) rm --force freshrss-tests-db >/dev/null 2>&1 || true; $(DOCKER) network rm freshrss-tests-db-network >/dev/null 2>&1 || true; }; \
trap cleanup EXIT INT TERM; \
$(DOCKER) run --detach --rm \
--name freshrss-tests-db \
--network freshrss-tests-db-network \
--env POSTGRES_HOST_AUTH_METHOD=trust \
$(TESTS_PGSQL_IMAGE) >/dev/null; \
until $(DOCKER) exec freshrss-tests-db pg_isready >/dev/null 2>&1; do \
i=$$((i + 1)); [ $$i -lt 30 ] || { echo 'PostgreSQL database did not become ready in time.' >&2; exit 1; }; \
sleep 1; \
done; \
for v in $(PHP_VERSIONS); do \
echo "===== PHP $$v ====="; \
$(DOCKER) build --quiet \
--build-arg PHP_VERSION=$$v \
--tag docker.io/freshrss/tests:php$$v \
--file Docker/Dockerfile-tests . ; \
$(DOCKER) run --rm \
--network freshrss-tests-db-network \
--env FRESHRSS_TEST_PGSQL_DSN='pgsql:host=freshrss-tests-db;dbname=postgres;user=postgres' \
--volume $(shell pwd):/var/www/FreshRSS:z \
--workdir /var/www/FreshRSS \
docker.io/freshrss/tests:php$$v \
sh -c "php --version | head -1 ; bin/composer test" ; \
done
.PHONY: fix-all
fix-all: composer-fix npm-fix ## Run all fixes
##@ I18n
.PHONY: i18n-add-file
i18n-add-file: ## Add a new translation file to all supported languages
ifndef key
$(error To add a new file, you need to provide one in the "key" variable)
endif
@$(PHP) ./cli/manipulate.translation.php --action add --key $(key)
@echo File added.
.PHONY: i18n-add-key
i18n-add-key: ## Add a translation key to all supported languages
ifndef key
$(error To add a key, you need to provide one in the "key" variable)
endif
ifndef value
$(error To add a key, you need to provide its value in the "value" variable)
endif
@$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)"
@echo Key added.
.PHONY: i18n-move-key
i18n-move-key: ## Move an existing key into a new location
ifndef key
$(error To move a key, you need to provide one in the "key" variable)
endif
ifndef new-key
$(error To specify a location to move the key to, you need to provide it in the "new-key" variable)
endif
@$(PHP) ./cli/manipulate.translation.php --action move --key $(key) --new-key "$(new-key)"
@echo Key moved.
.PHONY: i18n-add-language
i18n-add-language: ## Add a new supported language
ifndef lang
$(error To add a new language, you need to provide one in the "lang" variable)
endif
$(PHP) ./cli/manipulate.translation.php --action add --language $(lang) --origin-language $(ref)
@echo Language added.
.PHONY: i18n-compile-plurals
i18n-compile-plurals: ## Compile plural formulas from app/i18n/*/plurals.php
@$(PHP) ./cli/compile.plurals.php --all
@echo Plural files compiled.
.PHONY: i18n-format
i18n-format: ## Format I18N files
@$(PHP) ./cli/manipulate.translation.php --action format
@$(PHP) ./cli/compile.plurals.php --all
@echo Files formatted.
.PHONY: i18n-ignore-key
i18n-ignore-key: ## Ignore a translation key for the selected language
ifndef lang
$(error To ignore a key, you need to provide a language in the "lang" variable)
endif
ifndef key
$(error To ignore a key, you need to provide one in the "key" variable)
endif
@$(PHP) ./cli/manipulate.translation.php --action ignore --key $(key) --language $(lang)
@echo Key ignored.
.PHONY: i18n-ignore-unmodified-keys
i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
ifndef lang
$(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
endif
@$(PHP) ./cli/manipulate.translation.php --action ignore_unmodified --language $(lang)
@echo Unmodified keys ignored.
.PHONY: i18n-key-exists
i18n-key-exists: ## Check if a translation key exists
ifndef key
$(error To check if a key exists, you need to provide one in the "key" variable)
endif
@$(PHP) ./cli/manipulate.translation.php --action exist --key $(key)
.PHONY: i18n-remove-key
i18n-remove-key: ## Remove a translation key from all supported languages
ifndef key
$(error To remove a key, you need to provide one in the "key" variable)
endif
@$(PHP) ./cli/manipulate.translation.php --action delete --key $(key)
@echo Key removed.
.PHONY: i18n-update-key
i18n-update-key: ## Update a translation key in all supported languages
ifndef key
$(error To update a key, you need to provide one in the "key" variable)
endif
ifndef value
$(error To update a key, you need to provide its value in the "value" variable)
endif
@$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)" --language en
@echo Key updated.
##@ Tools
.PHONY: pot
pot: ## Generate POT templates for docs
cd docs && ../cli/translation-update.sh
.PHONY: readme
readme: ## Generate translation progress in README file
@$(PHP) ./cli/check.translation.php --generate-readme
.PHONY: refresh
refresh: ## Refresh feeds by fetching new messages
@$(PHP) ./app/actualize_script.php
.PHONY: rtl
rtl: node_modules/.bin/rtlcss ## Generate RTL CSS files
npm run-script rtlcss
.PHONY: svgo
svgo: node_modules/.bin/svgo ## Optimize SVG image files
npm run-script svgo
##@ Help
.PHONY: help
help: ## Display this help
@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)