forked from REBELinBLUE/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
237 lines (197 loc) · 8.95 KB
/
Makefile
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
.DEFAULT_GOAL := help
.PHONY: help
.SILENT:
GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
COMPOSER := $(shell command -v composer 2> /dev/null)
ifndef COMPOSER_CACHE_DIR
COMPOSER_CACHE_DIR := ~/.composer/cache
endif
composer: ##@production Install composer locally
ifndef COMPOSER
curl --silent https://getcomposer.org/installer | php -- --quiet
endif
permissions: ##@production Fix permissions
chmod 777 storage/logs/ bootstrap/cache/ storage/clockwork/
chmod 777 storage/framework/cache/ storage/framework/sessions/ storage/framework/views/
chmod 777 storage/app/mirrors/ storage/app/tmp/ storage/app/public/
migrate: ##@production Migrate the database
@echo "${GREEN}Migrate the database${RESET}"
@php artisan migrate
install: composer ##@production Install dependencies
@$(MAKE) permissions
ifndef COMPOSER
php composer.phar install --optimize-autoloader --no-dev --prefer-dist --no-interaction --no-suggest
else
composer install --optimize-autoloader --no-dev --prefer-dist --no-interaction --no-suggest
endif
npm install --production
install-dev: ##@development Install dev dependencies
@$(MAKE) permissions
@$(MAKE) docker-install-dev
update-deps: ##@development Update dependencies
@docker-compose run -v $(COMPOSER_CACHE_DIR):/tmp/cache --rm composer update --no-interaction --no-suggest --prefer-dist --no-suggest
@docker-compose exec node npm upgrade
clean: ##@development Clean cache, logs and other temporary files
@$(MAKE) stop
rm -rf storage/logs/*.log bootstrap/cache/*.php storage/framework/schedule-* storage/clockwork/*.json
rm -rf storage/framework/cache/* storage/framework/sessions/* storage/framework/views/*.php
rm -rf database/backups/*.gz
rollback: ##@development Rollback the previous database migration
@echo "${GREEN}Rollback the database${RESET}"
@docker-compose exec php-fpm php artisan migrate:rollback
seed: #@development Seed the database
@echo "${GREEN}Seed the database${RESET}"
@docker-compose exec php-fpm php artisan db:seed
lint: ##@tests PHP Parallel Lint
@echo "${GREEN}PHP Parallel Lint${RESET}"
@rm -rf bootstrap/cache/*.php
@docker-compose exec php-fpm composer test:lint
lines: ##@tests PHP Lines of Code
@echo "${GREEN}Lines of Code Statistics${RESET}"
@docker-compose exec php-fpm composer test:loc
phpcs: ##@tests PHP Coding Standards (PSR-2)
@echo "${GREEN}PHP Code Sniffer${RESET}"
@docker-compose exec php-fpm composer test:phpcs
fix: ##@tests PHP Coding Standards Fixer
@docker-compose exec php-fpm composer test:phpcs:fix
phpdoc-check: ##@tests PHPDoc Checker
@docker-compose exec php-fpm composer test:phpdoc
phpmd: ##@tests PHP Mess Detector
@echo "${GREEN}PHP Mess Detector${RESET}"
@if [ -f phpmd.xml ]; then docker-compose exec php-fpm php vendor/bin/phpmd app text phpmd.xml; fi
@if [ ! -f phpmd.xml ]; then docker-compose exec php-fpm composer test:phpmd; fi
phpcpd: ##@tests PHP Copy/Paste Detector
@echo "${GREEN}PHP Copy/Paste Detector${RESET}"
@docker-compose exec php-fpm composer test:phpcpd
#dusk: ##@tests Dusk Browser Tests
# @echo "${GREEN}Dusk${RESET}"
# @php artisan dusk
coverage: ##@tests Test Coverage HTML
@echo "${GREEN}All tests with coverage${RESET}"
@docker-compose exec php-fpm phpdbg -qrr vendor/bin/phpunit --coverage-text=/dev/null --coverage-php=storage/app/tmp/unit.cov \
--testsuite "Unit Tests" --log-junit=storage/app/tmp/unit.junit.xml --exclude-group slow
@docker-compose exec php-fpm phpdbg -qrr vendor/bin/phpunit --coverage-text=/dev/null --coverage-php=storage/app/tmp/slow.cov \
--testsuite "Unit Tests" --log-junit=storage/app/tmp/slow.junit.xml --exclude-group default
@docker-compose exec php-fpm phpdbg -qrr vendor/bin/phpunit --coverage-text=/dev/null --coverage-php=storage/app/tmp/integration.cov \
--log-junit=storage/app/tmp/integration.junit.xml --testsuite "Integration Tests"
@docker-compose exec php-fpm phpdbg -qrr vendor/bin/phpcov merge storage/app/tmp/ \
--html storage/app/tmp/coverage/ --clover storage/app/tmp/coverage.xml
@docker-compose exec php-fpm php vendor/bin/phpjunitmerge --names="*.junit.xml" storage/app/tmp/ storage/app/tmp/junit.xml
@rm -f storage/app/tmp/*.cov storage/app/tmp/*.junit.xml
phpunit: ##@tests Unit Tests
@echo "${GREEN}Unit tests${RESET}"
@docker-compose exec php-fpm composer test:unit
integration: ##@tests Integration Tests
@echo "${GREEN}Integration tests${RESET}"
@docker-compose exec php-fpm composer test:integration
quicktest: ##@shortcuts Runs fast tests; these exclude PHPMD, slow unit tests, integration & dusk tests
@$(MAKE) lint
@$(MAKE) phpcs
@$(MAKE) phpdoc-check
@$(MAKE) phpcpd
test: ##@shortcuts Runs most tests; but excludes integration & dusk tests
@$(MAKE) quicktest
@$(MAKE) phpunit
@$(MAKE) phpmd
fulltest: ##@shortcuts Runs all tests
@$(MAKE) quicktest
@$(MAKE) phpunit
@$(MAKE) integration
@$(MAKE) phpmd
#@$(MAKE) dusk
run: ##@docker Runs the containers
@docker-compose up -d
stop: ##@docker Stops the containers
@docker-compose down
build: ##@docker Builds the application
@$(MAKE) run
@cp -f ./docker/laravel_env .env
@$(MAKE) docker-install
@$(MAKE) docker-migrate
@sed -i "s/JWT_SECRET=changeme/JWT_SECRET=$(shell date +%s | sha256sum | base64 | head -c 32; echo)/g" .env
@docker-compose exec php-fpm php artisan key:generate --force
@docker-compose exec php-fpm php artisan deployer:create-user admin [email protected] changeme --no-email
docker-migrate: ##@docker Runs the migrations inside the container
@docker-compose exec php-fpm php artisan migrate
docker-install:
@docker-compose run -v $(COMPOSER_CACHE_DIR):/tmp/cache --rm composer install --optimize-autoloader --no-dev --prefer-dist --no-interaction --no-suggest --ignore-platform-reqs
@docker-compose exec node npm install --production
docker-install-dev:
@docker-compose run -v $(COMPOSER_CACHE_DIR):/tmp/cache --rm composer install --no-interaction --no-suggest --prefer-dist --no-suggest --ignore-platform-reqs
@docker-compose exec node npm install
# --------------------------------------------------------- #
# ----- The targets below should not be shown in help ----- #
# --------------------------------------------------------- #
# Clean everything (cache, logs, compiled assets, dependencies, etc)
reset: clean
rm -rf vendor/ node_modules/
rm -rf storage/app/mirrors/* storage/app/tmp/* storage/app/public/* storage/app/*.tar.gz
rm -rf .env.prev _ide_helper_models.php _ide_helper.php .phpstorm.meta.php .php_cs.cache
-rm database/database.sqlite
-rm database/backups/*
## Generates helper files for IDEs
#ide:
# php artisan clear-compiled
# php artisan ide-helper:generate
# php artisan ide-helper:meta
# php artisan ide-helper:models --nowrite
# Update all dependencies (also git add lockfiles)
#update-deps: permissions
# composer update --no-suggest --prefer-dist --no-scripts
# rm package-lock.json
# npm update
# git add composer.lock package-lock.json
#release: test
# @/usr/local/bin/create-release
# Create the databases for Travis CI
ifeq "$(DB)" "sqlite"
travis:
@sed -i 's/DB_CONNECTION=mysql/DB_CONNECTION=sqlite/g' .env
@sed -i 's/DB_DATABASE=deployer//g' .env
@sed -i 's/DB_USERNAME=travis//g' .env
@touch $(TRAVIS_BUILD_DIR)/database/database.sqlite
else ifeq "$(DB)" "pgsql"
travis:
@sed -i 's/DB_CONNECTION=mysql/DB_CONNECTION=pgsql/g' .env
@sed -i 's/DB_USERNAME=travis/DB_USERNAME=postgres/g' .env
@psql -c 'CREATE DATABASE deployer;' -U postgres;
else
travis:
@mysql -e 'CREATE DATABASE deployer;'
endif
# PHPUnit for Travis
ifeq "$(TRAVIS_PHP_VERSION)" "7.1"
phpunit-ci:
# phpdbg isn't working on travis, hitting the max open files limit
@php vendor/bin/phpunit --coverage-text=/dev/null --coverage-php=storage/app/tmp/unit.cov \
--testsuite "Unit Tests" --log-junit=storage/app/tmp/unit.junit.xml --exclude-group slow
@php vendor/bin/phpunit --coverage-text=/dev/null --coverage-php=storage/app/tmp/slow.cov \
--testsuite "Unit Tests" --log-junit=storage/app/tmp/slow.junit.xml --exclude-group default
@php vendor/bin/phpunit --coverage-text=/dev/null --coverage-php=storage/app/tmp/integration.cov \
--log-junit=storage/app/tmp/integration.junit.xml --testsuite "Integration Tests"
@php vendor/bin/phpcov merge storage/app/tmp/ \
--html storage/app/tmp/coverage/ --clover clover.xml
@php vendor/bin/phpjunitmerge --names="*.junit.xml" storage/app/tmp/ junit.xml
@rm -f storage/app/tmp/*.cov storage/app/tmp/*.junit.xml
else
phpunit-ci:
@composer test:unit
@composer test:integration
endif
HELP_FUN = %help; \
while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] \
if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
for (sort keys %help) { \
print "${WHITE}$$_${RESET}\n"; \
for (@{$$help{$$_}}) { \
$$sep = " " x (32 - length $$_->[0]); \
print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
}; \
print "\n"; }
# Prints the help
help:
@echo "\nUsage: make ${YELLOW}<target>${RESET}\n\nThe following targets are available:\n";
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)