Skip to content

Commit cff4257

Browse files
committed
Add a Makefile so we abstract our DevEx and automation from the tools
1 parent ca4ed0c commit cff4257

File tree

4 files changed

+125
-2
lines changed

4 files changed

+125
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
/public/build/fonts/glyphicons-*
1616
/public/build/images/glyphicons-*
1717

18+
Makefile.custom
19+
1820
###> symfony/framework-bundle ###
1921
.env
2022
/public/bundles/

Makefile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Makefile
2+
#
3+
# This file contains the commands most used in DEV, plus the ones used in CI and PRD environments.
4+
#
5+
# The commands are to be organized semantically and alphabetically, so that similar commands are nex to each other
6+
# and we can compare them and update them easily.
7+
#
8+
# For example in a format like `subject-action-environment`, ie:
9+
#
10+
# cs-fix: # here we don't use the env because we only do it in dev
11+
# dep-install: # again, by default the env is dev
12+
# dep-install-prd:
13+
# dep-update:
14+
# test: # here we don't even have a subject because it is the app itself, and by default the env is dev
15+
#
16+
17+
# Mute all `make` specific output. Comment this out to get some debug information.
18+
.SILENT:
19+
20+
# .DEFAULT: If the command does not exist in this makefile
21+
# default: If no command was specified
22+
.DEFAULT default:
23+
if [ -f ./Makefile.custom ]; then \
24+
$(MAKE) -f Makefile.custom "$@"; \
25+
else \
26+
if [ "$@" != "" ]; then echo "Command '$@' not found."; fi; \
27+
$(MAKE) help; \
28+
if [ "$@" != "" ]; then exit 2; fi; \
29+
fi
30+
31+
help:
32+
@echo "Usage:"
33+
@echo " make [command]"
34+
@echo
35+
@echo "Available commands:"
36+
@grep '^[^#[:space:]].*:' Makefile | grep -v '^default' | grep -v '^\.' | grep -v '=' | grep -v '^_' | sed 's/://' | xargs -n 1 echo ' -'
37+
38+
########################################################################################################################
39+
40+
COVERAGE_REPORT_PATH="var/coverage.clover.xml"
41+
DB_PATH='var/data/blog.sqlite'
42+
43+
# We run this in tst ENV so that we never run it with xdebug on
44+
cs-fix:
45+
php vendor/bin/php-cs-fixer fix --verbose
46+
47+
db-setup:
48+
mkdir -p var/data
49+
php bin/console doctrine:database:drop -n --force
50+
php bin/console doctrine:database:create -n
51+
php bin/console doctrine:schema:create -n
52+
php bin/console doctrine:fixtures:load -n
53+
54+
dep-clearcache:
55+
composer clearcache
56+
57+
dep-install:
58+
composer install
59+
60+
dep-install-prd:
61+
composer install --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress --no-scripts
62+
63+
dep-update:
64+
composer update
65+
66+
test:
67+
$(MAKE) db-setup
68+
php vendor/bin/phpunit
69+
$(MAKE) cs-fix
70+
71+
# We use phpdbg because is part of the core and so that we don't need to install xdebug just to get the coverage.
72+
# Furthermore, phpdbg gives us more info in certain conditions, ie if the memory_limit has been reached.
73+
test_cov:
74+
phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover=${COVERAGE_REPORT_PATH}
75+
76+
up:
77+
if [ ! -f ${DB_PATH} ]; then $(MAKE) db-setup; fi
78+
php bin/console server:run 0.0.0.0:8000

Makefile.custom.dist

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Makefile.custom
2+
#
3+
# This file contains the custom commands and/or aliases.
4+
#
5+
# To use it, copy/paste this file with the name Makefile.custom and add commands as you wish.
6+
# This file is in .gitignore, so it will not be committed and is specific to you.
7+
#
8+
9+
# Mute all `make` specific output. Comment this out to get some debug information.
10+
.SILENT:
11+
12+
# make commands be run with `bash` instead of the default `sh`
13+
SHELL='/bin/bash'
14+
15+
# .DEFAULT: If command does not exist in this makefile
16+
# default: If no command was specified:
17+
.DEFAULT default:
18+
if [ "$@" != "" ]; then echo "Command '$@' not found."; fi;
19+
$(MAKE) help # goes to the main Makefile
20+
$(MAKE) -f Makefile.custom help # goes to this Makefile
21+
if [ "$@" != "" ]; then exit 2; fi;
22+
23+
help:
24+
@echo
25+
@echo "Available custom commands:"
26+
@grep '^[^#[:space:]].*:' Makefile.custom | grep -v '^help' | grep -v '^default' | grep -v '^\.' | grep -v '=' | grep -v '^_' | sed 's/://' | xargs -n 1 echo ' -'
27+
28+
########################################################################################################################
29+

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ browser at <http://localhost:8000>:
3131

3232
```bash
3333
$ cd symfony-demo/
34-
$ php bin/console server:run
34+
$ make up
35+
```
36+
37+
To see all commands available run:
38+
39+
```bash
40+
$ cd symfony-demo/
41+
$ make
3542
```
3643

3744
Alternatively, you can [configure a fully-featured web server][2] like Nginx
@@ -44,7 +51,14 @@ Execute this command to run tests:
4451

4552
```bash
4653
$ cd symfony-demo/
47-
$ ./vendor/bin/phpunit
54+
$ make test
55+
```
56+
57+
Or this command to run tests and get the coverage:
58+
59+
```bash
60+
$ cd symfony-demo/
61+
$ make test_cov
4862
```
4963

5064
[1]: https://symfony.com/doc/current/reference/requirements.html

0 commit comments

Comments
 (0)