-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathMakefile
More file actions
102 lines (84 loc) · 3.14 KB
/
Makefile
File metadata and controls
102 lines (84 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
.PHONY: update-version increment-major increment-minor increment-patch test build clean install lint format check publish
# Version file location
VERSION_FILE := VERSION
VERSION_PHP_FILE := src/Version.php
COMPOSER_FILE := composer.json
# PHP commands
PHP := php
COMPOSER := composer
PHPUNIT := vendor/bin/phpunit
PHPSTAN := vendor/bin/phpstan
PHP_CS_FIXER := vendor/bin/php-cs-fixer
update-version:
@echo "$(VERSION)" > $(VERSION_FILE)
@perl -pi -e 's|const VERSION = '\''[.\-\d\w]+'\'';|const VERSION = '\''$(VERSION)'\'';|' $(VERSION_PHP_FILE)
@if [ -f "$(COMPOSER_FILE)" ]; then \
perl -pi -e 's|"version"\s*:\s*"[.\-\d\w]+"|"version": "$(VERSION)"|' $(COMPOSER_FILE); \
fi
@echo "Updated version to $(VERSION)"
increment-major:
$(eval CURRENT := $(shell cat $(VERSION_FILE)))
$(eval MAJOR := $(shell echo $(CURRENT) | cut -d. -f1))
$(eval NEW_VERSION := $(shell echo $$(($(MAJOR) + 1)).0.0))
@$(MAKE) update-version VERSION=$(NEW_VERSION)
@echo "Version bumped from $(CURRENT) to $(NEW_VERSION)"
increment-minor:
$(eval CURRENT := $(shell cat $(VERSION_FILE)))
$(eval MAJOR := $(shell echo $(CURRENT) | cut -d. -f1))
$(eval MINOR := $(shell echo $(CURRENT) | cut -d. -f2))
$(eval NEW_VERSION := $(MAJOR).$(shell echo $$(($(MINOR) + 1))).0)
@$(MAKE) update-version VERSION=$(NEW_VERSION)
@echo "Version bumped from $(CURRENT) to $(NEW_VERSION)"
increment-patch:
$(eval CURRENT := $(shell cat $(VERSION_FILE)))
$(eval MAJOR := $(shell echo $(CURRENT) | cut -d. -f1))
$(eval MINOR := $(shell echo $(CURRENT) | cut -d. -f2))
$(eval PATCH := $(shell echo $(CURRENT) | cut -d. -f3))
$(eval NEW_VERSION := $(MAJOR).$(MINOR).$(shell echo $$(($(PATCH) + 1))))
@$(MAKE) update-version VERSION=$(NEW_VERSION)
@echo "Version bumped from $(CURRENT) to $(NEW_VERSION)"
install:
@echo "Installing dependencies..."
@$(COMPOSER) install --no-dev --optimize-autoloader
install-dev:
@echo "Installing development dependencies..."
@$(COMPOSER) install
test: install-dev
@echo "Running tests..."
@$(PHPUNIT) --testdox
test-coverage:
@echo "Running tests with coverage..."
@XDEBUG_MODE=coverage $(PHPUNIT) --coverage-html coverage --coverage-text
@echo "Coverage report generated in coverage/index.html"
format:
@echo "Formatter is not added currently."
format-check:
@echo "Checking code formatting..."
@if [ -f "$(PHP_CS_FIXER)" ]; then \
$(PHP_CS_FIXER) fix --dry-run --diff --allow-risky=yes; \
else \
echo "PHP CS Fixer not found. Install it with: composer require --dev friendsofphp/php-cs-fixer"; \
fi
lint:
@echo "Running PHPStan static analysis..."
@if [ -f "$(PHPSTAN)" ]; then \
$(PHPSTAN) analyse --memory-limit=512M; \
else \
echo "PHPStan not found. Install it with: composer require --dev phpstan/phpstan"; \
fi
typecheck: lint
check: format-check lint test
@echo "All checks passed!"
build: clean
@echo "Building package..."
@$(COMPOSER) validate
@$(COMPOSER) install --no-dev --optimize-autoloader --prefer-dist
clean:
@echo "Cleaning build artifacts..."
@rm -rf vendor/
@rm -rf coverage/
@rm -rf .phpunit.cache/
@rm -rf .phpunit.result.cache
@rm -rf .php-cs-fixer.cache
@rm -rf composer.lock
@find . -type f -name '.DS_Store' -delete