-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·231 lines (178 loc) · 6.71 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
#
# Makefile
# Les Polypodes, 2014
# Licence: MIT
# Source: https://github.com/polypodes/Build-and-Deploy/blob/master/build/Makefile
# To enable this quality-related tasks, add these dependencies to your composer.json:
# they'll be available in the ./bin dir :
#
# "require-dev": {
# (...)
# "phpunit/phpunit": "~3.7",
# "squizlabs/php_codesniffer": "2.0.x-dev",
# "sebastian/phpcpd": "*",
# "phploc/phploc" : "*",
# "phpmd/phpmd" : "2.0.*",
# "pdepend/pdepend" : "2.0.*",
# "fabpot/php-cs-fixer": "@stable"
# },
# Usage:
# me@myserver$~: make help
# me@myserver$~: make install
# me@myserver$~: make reinstall
# me@myserver$~: make update
# me@myserver$~: make tests
# me@myserver$~: make quality
# etc.
############################################################################
# Vars
# some lines may be useless for now, but these are nice tricks:
PWD := $(shell pwd)
# Retrieve db connection params, triming white spaces
DB_USER := $(shell if [ -f app/config/parameters.yml ] ; then cat app/config/parameters.yml | grep 'database_user' | sed 's/database_user: //' | sed 's/^ *//;s/ *$$//' ; fi)
DB_PASSWORD := $(shell if [ -f app/config/parameters.yml ] ; then cat app/config/parameters.yml | grep 'database_password' | sed 's/database_password: //' | sed 's/null//' | sed 's/^ *//;s/ *$$//' ; fi)
DB_NAME := $(shell if [ -f app/config/parameters.yml ] ; then cat app/config/parameters.yml | grep 'database_name' | sed 's/database_name: //' | sed 's/^ *//;s/ *$$//' ; fi)
VENDOR_PATH := $(PWD)/vendor
BIN_PATH := $(PWD)/bin
WEB_PATH := $(PWD)/web
NOW := $(shell date +%Y-%m-%d--%H-%M-%S)
REPO := "https://github.com/..."
BRANCH := 'master'
# Colors
YELLOW := $(shell tput bold ; tput setaf 3)
GREEN := $(shell tput bold ; tput setaf 2)
RESETC := $(shell tput sgr0)
# Custom MAKE options
ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif
############################################################################
# Mandatory tasks:
all: .git/hook/pre-commit vendor/autoload.php check help
vendor/autoload.php:
@composer self-update
@composer install --optimize-autoloader
.git/hook/pre-commit:
@curl -s -o .git/hooks/pre-commit https://raw.githubusercontent.com/polypodes/Build-and-Deploy/master/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
############################################################################
# Specific, project-related sf2 tasks:
integration:
@echo
@cd integration
@gulp build
@cd ../
dumps:
@echo "Creating dump folder for SQL exports..."
@mkdir ./dumps
mysqldump: dumps
@echo "Dumping existing db into ./dumps ..."
@mysqldump --user=${DB_USER} --password=${DB_PASSWORD} ${DB_NAME} > dumps/${NOW}.sql 2>/dev/null
mysqlinfo: dumps
@echo "mysql --user=${DB_USER} --password=${DB_PASSWORD} ${DB_NAME}"
data: vendor/autoload.php
# @echo "Install initial datas..."
# @php app/console dbal:data:initialize --purge
fixtures: vendor/autoload.php
# @echo "Install fixtures in db..."
# @php app/console dbal:fixtures:load --purge
############################################################################
# Generic sf2 tasks:
help:
@echo "\n${GREEN}Usual tasks:${RESETC}\n"
@echo "\tTo prepare install:\tmake"
@echo "\tTo install:\t\tmake install"
@echo "\tTo update from git:\tmake update"
@echo "\tTo reinstall:\t\tmake reinstall (will erase all your datas)\n\n"
@echo "${GREEN}Other specific tasks:${RESETC}\n"
@echo "\tTo check code quality:\tmake quality"
@echo "\tTo fix code style:\tmake cs-fix"
@echo "\tTo clear all caches:\tmake clear"
@echo "\tTo run tests:\t\tmake tests (will erase all your datas)\n"
check:
@php app/check.php
pull:
@git pull origin $(BRANCH)
dropDb: vendor/autoload.php mysqldump
@echo
@echo "Drop database..."
@php app/console doctrine:database:drop --force
createDb: vendor/autoload.php
@echo
@echo "Create database..."
@php app/console doctrine:database:create
@php app/console doctrine:schema:update --force
schemaDb: vendor/autoload.php mysqldump
@echo
@echo "Configure database schema..."
@php app/console doctrine:schema:update --force
assets:
@echo "\nPublishing assets..."
@php app/console assets:install --symlink
clear: vendor/autoload.php
@echo
@echo "Resetting caches..."
@php app/console cache:clear --env=prod --no-debug
@php app/console cache:clear --env=dev
explain:
@echo "git pull origin master + update db schema + build integration + copy new assets + rebuild prod cache"
@echo "Note you can change the git remote repo username in .git/config"
behavior: vendor/autoload.php
@echo "Run behavior tests..."
@bin/behat --lang=fr "@AcmeDemoBundle"
unit: vendor/autoload.php
@echo "Run unit tests..."
@php bin/phpunit -c build/phpunit.xml -v
codecoverage: vendor/autoload.php
@echo "Run coverage tests..."
@bin/phpunit -c build/phpunit.xml -v --coverage-html ./build/codecoverage
continuous: vendor/autoload.php
@echo "Starting continuous tests..."
@while true; do bin/phpunit -c build/phpunit.xml -v; done
sniff: vendor/autoload.php
@bin/phpcs --standard=PSR2 src -n
dry-fix:
@bin/php-cs-fixer fix . --config=sf23 --dry-run -vv
cs-fix:
@bin/phpcbf --standard=PSR2 src
@bin/php-cs-fixer fix . --config=sf23 -vv
#quality must remain quiet, as far as it's used in a pre-commit hook validation
quality: sniff dry-fix
build:
@mkdir -p build/pdepend
# packagist-based dev tools to add to your composer.json. See http://phpqatools.org
stats: quality build
@echo "Some stats about code quality"
@bin/phploc src
@bin/phpcpd src
@bin/phpmd src text codesize,unusedcode
@bin/pdepend --summary-xml=build/pdepend/summary.xml --jdepend-chart=build/pdepend/jdepend.svg --overview-pyramid=build/pdepend/pyramid.svg src
update: vendor/autoload.php
@$(MAKE) explain
@$(MAKE) pull
@$(MAKE) schemaDb
@$(MAKE) clear
@$(MAKE) done
robot:
@echo "User-agent: *" > $(WEB_PATH)/robots.txt
@echo "Disallow: " >> $(WEB_PATH)/robots.txt
unrobot:
@echo "User-agent: *" > $(WEB_PATH)/robots.txt
@echo "Disallow: /" >> $(WEB_PATH)/robots.txt
done:
@echo
@echo "${GREEN}Done.${RESETC}"
# Tasks sets:
all: vendor/autoload.php check
prepareDb: createDb schemaDb
purgeDb: dropDb createDb schemaDb
install: prepareDb data assets clear done
reinstall: dropDb install
tests: reinstall fixtures behavior unit codecoverage
############################################################################
# .PHONY tasks list
.PHONY: integration data fixtures help check all pull dropDb createDb myqldump
.PHONY: schemaDb assets clear explain behavior unit codecoverage
.PHONY: continuous sniff dry-fix cs-fix quality stats deploy done prepareDb purgeDb
.PHONY: install reinstall test update robot unrobot
# vim:ft=make