Skip to content

Commit

Permalink
Add a Makefile so we abstract our DevEx and automation from the tools
Browse files Browse the repository at this point in the history
  • Loading branch information
hgraca committed Apr 13, 2018
1 parent ca4ed0c commit cff4257
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
/public/build/fonts/glyphicons-*
/public/build/images/glyphicons-*

Makefile.custom

###> symfony/framework-bundle ###
.env
/public/bundles/
Expand Down
78 changes: 78 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Makefile
#
# This file contains the commands most used in DEV, plus the ones used in CI and PRD environments.
#
# The commands are to be organized semantically and alphabetically, so that similar commands are nex to each other
# and we can compare them and update them easily.
#
# For example in a format like `subject-action-environment`, ie:
#
# cs-fix: # here we don't use the env because we only do it in dev
# dep-install: # again, by default the env is dev
# dep-install-prd:
# dep-update:
# test: # here we don't even have a subject because it is the app itself, and by default the env is dev
#

# Mute all `make` specific output. Comment this out to get some debug information.
.SILENT:

# .DEFAULT: If the command does not exist in this makefile
# default: If no command was specified
.DEFAULT default:
if [ -f ./Makefile.custom ]; then \
$(MAKE) -f Makefile.custom "$@"; \
else \
if [ "$@" != "" ]; then echo "Command '$@' not found."; fi; \
$(MAKE) help; \
if [ "$@" != "" ]; then exit 2; fi; \
fi

help:
@echo "Usage:"
@echo " make [command]"
@echo
@echo "Available commands:"
@grep '^[^#[:space:]].*:' Makefile | grep -v '^default' | grep -v '^\.' | grep -v '=' | grep -v '^_' | sed 's/://' | xargs -n 1 echo ' -'

########################################################################################################################

COVERAGE_REPORT_PATH="var/coverage.clover.xml"
DB_PATH='var/data/blog.sqlite'

# We run this in tst ENV so that we never run it with xdebug on
cs-fix:
php vendor/bin/php-cs-fixer fix --verbose

db-setup:
mkdir -p var/data
php bin/console doctrine:database:drop -n --force
php bin/console doctrine:database:create -n
php bin/console doctrine:schema:create -n
php bin/console doctrine:fixtures:load -n

dep-clearcache:
composer clearcache

dep-install:
composer install

dep-install-prd:
composer install --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress --no-scripts

dep-update:
composer update

test:
$(MAKE) db-setup
php vendor/bin/phpunit
$(MAKE) cs-fix

# We use phpdbg because is part of the core and so that we don't need to install xdebug just to get the coverage.
# Furthermore, phpdbg gives us more info in certain conditions, ie if the memory_limit has been reached.
test_cov:
phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover=${COVERAGE_REPORT_PATH}

up:
if [ ! -f ${DB_PATH} ]; then $(MAKE) db-setup; fi
php bin/console server:run 0.0.0.0:8000
29 changes: 29 additions & 0 deletions Makefile.custom.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Makefile.custom
#
# This file contains the custom commands and/or aliases.
#
# To use it, copy/paste this file with the name Makefile.custom and add commands as you wish.
# This file is in .gitignore, so it will not be committed and is specific to you.
#

# Mute all `make` specific output. Comment this out to get some debug information.
.SILENT:

# make commands be run with `bash` instead of the default `sh`
SHELL='/bin/bash'

# .DEFAULT: If command does not exist in this makefile
# default: If no command was specified:
.DEFAULT default:
if [ "$@" != "" ]; then echo "Command '$@' not found."; fi;
$(MAKE) help # goes to the main Makefile
$(MAKE) -f Makefile.custom help # goes to this Makefile
if [ "$@" != "" ]; then exit 2; fi;

help:
@echo
@echo "Available custom commands:"
@grep '^[^#[:space:]].*:' Makefile.custom | grep -v '^help' | grep -v '^default' | grep -v '^\.' | grep -v '=' | grep -v '^_' | sed 's/://' | xargs -n 1 echo ' -'

########################################################################################################################

18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ browser at <http://localhost:8000>:

```bash
$ cd symfony-demo/
$ php bin/console server:run
$ make up
```

To see all commands available run:

```bash
$ cd symfony-demo/
$ make
```

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

```bash
$ cd symfony-demo/
$ ./vendor/bin/phpunit
$ make test
```

Or this command to run tests and get the coverage:

```bash
$ cd symfony-demo/
$ make test_cov
```

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

0 comments on commit cff4257

Please sign in to comment.