-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
318 lines (246 loc) · 9.72 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#
# laravel-scripts - Laravel specific Makefile
#
# @author Jeroen Derks <jeroen@derks.it>
# @since 2017/May/23
# @license GPLv3 https://www.gnu.org/licenses/gpl.html
# @copyright Copyright (c) 2017-2018 Jeroen Derks / Derks.IT
# @url https://github.com/Magentron/laravel-scripts/
#
# This file is part of laravel-scripts.
#
# laravel-scripts is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# laravel-scripts is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with laravel-scripts. If not, see <http://www.gnu.org/licenses/>.
#
ANT := $(shell which ant)
ANT_TARGET=full-build-parallel
ARTISAN=$(PHP) artisan $(ARTISAN_EXTRA)
COMPOSER=composer
CONVERT=convert
CURL=curl
DOTENV := $(shell [ -z '$(ENVIRONMENT)' ] && echo .env || echo .env.$(ENVIRONMENT) )
ENVIRONMENT=
LANG=nl
NPM_ASSETS=public/css/app.css public/js/app.js
NPM_ENV=development
OS:=$(shell uname -s)
NPROCS:=$(shell [ Darwin = $(OS) ] && sysctl -n hw.ncpu || nproc)
PHP=php -d memory_limit=256M $(PHP_EXTRA)
PHPUNIT=$(PHP) vendor/bin/phpunit -d xdebug.max_nesting_level=250 -d memory_limit=1024M $(PHPUNIT_EXTRA)
PRETEND=--pretend
SCOUT_MODELS=
PHP_SRC=app bootstrap/app.php config database resources routes public/*.php tests
SRC= Makefile README.md webpack.mix.js composer.json package-lock.json package.json Envoy.blade.php \
opcache_reset.php server.php phpunit.xml app bootstrap/app.php bootstrap/autoload.php config \
database model resources routes tests
USER_AGENT:=$(shell $(CURL) --version | head -1 | awk '{printf("%s/%s", $$1, $$2);}')
WGET=wget --no-check-certificate $(WGET_EXTRA)
WRITABLE_DIRS=storage/*/* bootstrap/cache
WWW_GROUP_ID := $(shell if id _www > /dev/null 2>&1; then echo _www; else echo www-data; fi)
DEFAULT_BRANCH=master
TEMP_DEPLOY_DIR := $(shell echo .deploy.tmp.$$$$)
all: rw
#
# Setup
#
rw:
sudo chmod -R g+w $(WRITABLE_DIRS)
sudo chown -R $(USER):$(WWW_GROUP_ID) $(WRITABLE_DIRS)
init: composer .env laravel-key npms passport-keys reminder
install-envoy:
$(COMPOSER) global require laravel/envoy
composer:
$(COMPOSER) install
.env:
cp .env.example .env
laravel-key:
$(ARTISAN) key:generate
# Laravel Passport is not always used, so ignore exit status
passport-keys:
-$(ARTISAN) passport:keys
reminder:
@echo remember to edit .env file with db name/pass etc
init-elastic:
# bash -c '. $(DOTENV) && set -x && curl -XDELETE "http://$${SCOUT_ELASTIC_HOST}/$${SCOUT_ELASTIC_INDEX_NAME}?pretty"'
-$(ARTISAN) elastic:drop-index 'App\ScoutElasticIndexConfigurator'
$(ARTISAN) migrate:refresh
$(ARTISAN) elastic:create-index 'App\Scout\ElasticIndexConfigurator'
time $(ARTISAN) db:seed --class=DummyDataSeeder
[ -z $(SCOUT_MODELS) ] || for model in $(SCOUT_MODELS); do $(ARTISAN) scout:import "$$model"; done
get-envoy:
$(WGET) -N https://raw.githubusercontent.com/papertank/envoy-deploy/master/Envoy.blade.php
#
# Deployment
#
deploy-checkout-copy-manual:
@[ ! -z '$(BRANCH)' -a ! -z '$(DST)' ] || (echo "missing BRANCH=... or DST=..." 1>&2; exit 1)
(rm -rf $(TEMP_DEPLOY_DIR) && git clone --recursive -j8 -b $(BRANCH) . $(TEMP_DEPLOY_DIR) && rsync -zaSHx $(TEMP_DEPLOY_DIR)/ $(DST)/); rm -rf $(TEMP_DEPLOY_DIR)
deploy-init:
time $(HOME)/.composer/vendor/bin/envoy $(ENVOY_EXTRA) run $(RUN_EXTRA) init $(EXTRA)
dry-deploy-init:
make deploy-init EXTRA='--dry_run=1 $(EXTRA)'
deploy:
time $(HOME)/.composer/vendor/bin/envoy $(ENVOY_EXTRA) run $(RUN_EXTRA) deploy $(EXTRA)
dry-deploy:
make deploy EXTRA='--dry_run=1 $(EXTRA)'
init-demo:
make deploy-init EXTRA='--env=demo $(EXTRA)'
dry-init-demo:
make init-demo EXTRA='--dry_run=1 $(EXTRA)'
deploy-demo:
time $(HOME)/.composer/vendor/bin/envoy $(ENVOY_EXTRA) run $(RUN_EXTRA) deploy --env=demo $(EXTRA)
dry-deploy-demo:
make deploy-demo EXTRA='--dry_run=1 $(EXTRA)'
init-staging:
make deploy-init EXTRA='--env=staging $(EXTRA)'
dry-init-staging:
make init-staging EXTRA='--dry_run=1 $(EXTRA)'
deploy-staging:
make deploy EXTRA='--env=staging $(EXTRA)'
dry-deploy-staging:
make deploy-staging EXTRA='--dry_run=1 $(EXTRA)'
ant build: .build.dummy.
.build.dummy.:
time $(ANT) $(EXTRA) $(ANT_TARGET)
#
# Docker
#
docker-image:
docker build --squash .
#
# Testing
#
test: rw clear-cache autodump
time $(PHPUNIT) $(EXTRA)
test-fast fast-test testfast fasttest:
time $(PHPUNIT) --no-coverage $(EXTRA)
test-tee testtee: rw clear-cache autodump optimize
set -o pipefail; time $(PHPUNIT) $(EXTRA) 2>&1 | tee build/phpunit.out
test-func testfunc:
@[ ! -z "$(FUNC)" ] || (echo "missing FUNC=..."; exit 1)
make test EXTRA="--filter '/::$(FUNC)\$$\$$/' $(EXTRA)"
test-fast-func test-fastfunc testfast-func testfastfunc test-func-fast test-funcfast testfuncfast:
@[ ! -z "$(FUNC)" ] || (echo "missing FUNC=..."; exit 1)
make testfast EXTRA="--filter '/::$(FUNC)\$$\$$/' $(EXTRA)"
test-profiler testprofiler:
@cwd=`pwd`; if [ -z "$(FUNC)" ]; then \
make testfast PHP="$(PHP) -d xdebug.profiler_enable=1 -d xdebug.profiler_output_name=cachegrind.out.%p -d xdebug.profiler_output_dir=$$cwd/storage/tmp/xdebug" EXTRA='$(EXTRA)'; \
else \
make testfastfunc PHP="$(PHP) -d xdebug.profiler_enable=1 -d xdebug.profiler_output_name=cachegrind.out.%p -d xdebug.profiler_output_dir=$$cwd/storage/tmp/xdebug" EXTRA='$(EXTRA)' FUNC='$(FUNC)'; \
fi
test-stop teststop:
make test EXTRA="--stop-on-failure $(EXTRA)"
test-user testuser:
make test EXTRA='$(EXTRA) ./tests/Unit/UserTest'
test-elastic testelastic:
@[ ! -z '$(QUERY)' ] || (echo missing QUERY=... 1>&2; exit 1)
echo '{"query":{"bool":{"must":[{"query_string":{"default_field":"_all","query":".*word.*"}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"aggs":{}}' | bash -c '. $(DOTENV) && \
curl --trace-ascii - -H "Content-Type: application/json" --data @- "http://$${SCOUT_ELASTIC_HOST}/$${SCOUT_ELASTIC_INDEX_NAME}/_search?pretty"'
test-migrate:
time $(ARTISAN) --env=testing migrate $(EXTRA)
#
# NPM
#
$(NPM_ASSETS): Makefile webpack.mix.js resources/assets/sass/*.scss resources/assets/js/*.js
time npm run $(NPM_ENV)
npms:
npm install
npm-clean npm-clear:
rm -f $(NPM_ASSETS)
npm-dev npm-devel npm-develop npm-development: $(NPM_ASSETS)
npm-watch:
time npm run watch
npm-prod npm-production:
@make npm-dev NPM_ENV=production
#
# Lint
#
lint lint-parallel:
@make -j4 jsonlint xmllint phplint bladelint
lint-sequential: jsonlint xmllint phplint bladelint
bladelint blade-lint lint-blade lintblade:
@: echo lint - Blade...
@: nice -20 $(ARTISAN) blade:lint --quiet
jsonlint json-lint lint-json lintjson:
@echo lint - JSON...
@find *.json app bootstrap public resources routes tests -name '*.json' | nice -20 parallel 'echo {}:; jsonlint -q {}' > .tmp.jsonlint 2>&1;\
egrep -B1 '^(Error:|\s|\.\.\. )' .tmp.jsonlint | egrep -v ^--; res=$$?; rm -f .tmp.jsonlint; [ 0 != "$$res" ]
phplint php-lint lint-php lintphp:
@echo lint - PHP...
@find *.php app bootstrap public resources routes tests -name '*.php' | nice -20 parallel 'php -l {}' | fgrep -v 'No syntax errors detected' > .tmp.phplint;\
[ ! -s .tmp.phplint ]; res=$$?; cat .tmp.phplint; rm -f .tmp.phplint; exit $$res
xmllint xml-lint lint-xml lintxml:
@echo lint - XML...
@find *.xml app bootstrap public resources routes tests -name '*.xml' | while read file; do nice -20 xmllint --noout "$$file"; done
#
# Static code analysis
#
loc:
@echo making fast copy...
@rm -rf build/src
@mkdir -p build/src
@for i in $(SRC) ; do ln -s ../../"$$i" build/src/; done
@echo running sloccount...
#sloccount --datadir .sloccount --follow build/src
@sloccount --addlang js --addlang makefile --addlang sql --addlangall --follow $(EXTRA) -- build/src/ 2>&1 | fgrep -v 'Warning! Unclosed PHP file'
@echo running cloc...
@cloc --follow-links build/src
static-analysis static-analyzis static analysis analyzis analyse analyze stat anal: phpcpd phpcs phploc phpmd phpstan
phpcpd:
vendor/bin/phpcpd $(EXTRA) $(PHP_SRC)
phpcs:
vendor/bin/phpcs --standard=PSR2 -p --parallel=$(NPROCS) -s $(EXTRA) $(PHP_SRC)
phploc:
vendor/bin/phploc $(EXTRA) $(PHP_SRC)
phpmd:
for ruleset in cleancode codesize controversial design naming unusedcode; do \
vendor/bin/phpmd $(PHP_SRC) ansi $$ruleset $(EXTRA); \
done
phpstan:
vendor/bin/phpstan analyse $(EXTRA) $(PHP_SRC)
#
# Translations
#
find-texts:
@egrep -Er '>[A-Z][a-z]|^\s*[A-Z][a-z][A-Za-z0-9 _.-]*\s*$$' resources/views/ $(CMD_EXTRA)
gentrans:
@grep -r --exclude=".svn" --exclude=CVS --exclude=.git --include="*."{conf,cfg,inc,ini,php,php3,php4,php5,xml,yml} -hoEe "(__|\@lang)\\((\\$$.*\\?\\s*)?'[^']*'(\s*:\s*'[^']*')?[\\),]" app resources | sort -n | uniq | egrep -oe "'[^']+'" | uniq \
| cut -c2- | rev | cut -c2- | rev \
| while read text; do fgrep -qs "\"`echo \"$$text\" | sed -e 's@"@\\\\"@g'`\"" resources/lang/$(LANG).json || echo " \"$$text\": \"$$text\","; done
gentrans-en:
@make gentrans LANG=en
#
# Shortcuts
#
clean: clear
rm -f Envoy[0-9a-f]*.php
autodump autoload dumpautoload dump-autoload:
$(COMPOSER) dumpautoload
migrate:
$(ARTISAN) migrate $(PRETEND)
route:
$(ARTISAN) route:list
clear cache-clear clear-cache:
$(ARTISAN) cache:clear
$(ARTISAN) route:clear
$(ARTISAN) view:clear
$(ARTISAN) clear-compiled
$(ARTISAN) config:clear
clear-optimize: cache-clear optimize
$(ARTISAN) config:cache
$(ARTISAN) route:cache
optimize:
$(ARTISAN) optimize
geoipdb: storage/maxmind/GeoLite2-City.mmdb
storage/maxmind/GeoLite2-City.mmdb:
mkdir -p storage/maxmind && curl http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz | zcat > $@