Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Make task runners great again

GBProd
June 12, 2017

Make task runners great again

GBProd

June 12, 2017
Tweet

More Decks by GBProd

Other Decks in Programming

Transcript

  1. MAKE TASK RUNNER GREAT AGAIN @GillesRoustan

  2. BASH PHING COMPOSER ROBO BLDR GRUMPHP NPM GULP GRUNT... @GillesRoustan

  3. None
  4. MAKE ONE TOOL TO RULE THEM ALL @GillesRoustan

  5. INDEPENDANT

  6. HOW-TO ? @GillesRoustan

  7. # Makefile target:[prerequisites] [recipe]

  8. # Makefile target:[prerequisites] \t [recipe]

  9. $ make target

  10. MAKE IS NOT A TASK RUNNER

  11. file.o: file.c gcc file.c -o file.o

  12. .PHONY: install install: file.o file.o: file.c gcc file.c -o file.o

  13. $ make install gcc file.c -o file.o ...

  14. $ make install Rien à faire pour la règle ...

  15. MAKE ME UP, BEFORE YOU GO GO @GillesRoustan

  16. vendor: composer.lock composer install composer.lock: composer.json composer update

  17. .PHONY: install install: vendor [...]

  18. $ make install composer install ...

  19. $ make --always-make install composer update ...

  20. .PHONY: install update update: $(MAKE) --always-make install install: vendor

  21. MAKE CONFIGURATION @GillesRoustan

  22. ENV = dev

  23. ENV ?= dev

  24. ENV ?= dev vendor: composer.lock ifeq ($(ENV), prod) composer install

    --no-dev --optimize-autoloader else composer install endif
  25. $ make install composer install ...

  26. $ make install ENV=prod composer install --no-dev --optimize-autoloader ...

  27. GREATER ? @GillesRoustan

  28. ENV ?= dev COMPOSER_ARGS ?= ifeq ($(ENV), prod) COMPOSER_ARGS= --no-dev

    --optimize-autoloader endif vendor: composer.lock composer install $(COMPOSER_ARGS)
  29. INCLUDE EH MAKE, ELLE EST OÙ MA CAISSE ? @GillesRoustan

  30. include *.mk

  31. include .env

  32. https://github.com/symfony/dotenv

  33. .env: @if [ ! -e .env ]; then \ cp

    env.dist .env; \ fi include .env
  34. MAKE CONTINOUS INTEGRATION GREAT AGAIN @GillesRoustan

  35. test-unit: install vendor/bin/phpunit $(PHPUNIT_ARGS)

  36. # .travis.yml sudo: required services: - docker script: - make

    test-unit
  37. MAKE IT WITH DOCKER @GillesRoustan

  38. test-unit: install docker exec -it my-container vendor/bin/phpunit

  39. EXEC=docker exec -it my-container test-unit: install $(EXEC) vendor/bin/phpunit

  40. MAKE FUNCTIONS ? @GillesRoustan

  41. test-unit: install $(call execute, vendor/bin/phpunit) define execute docker exec -it

    my-container $(1) @echo $(1) >> make.log endef
  42. DOCKER EST UN ENVIRONNEMENT

  43. # .env ENV=dev DOCKER=true

  44. ifeq ($(DOCKER), true) define execute docker exec -it my-container $(1)

    endef else define execute $(1) endef endif
  45. clean: $(call execute, \ chmod -R 0777 var && \

    rm -Rf var/cache/prod && \ rm -Rf var/cache/dev \ )
  46. MAKE MONO-REPOSITORY @GillesRoustan

  47. .PHONY: install install: $(MAKE) --directory=app-php install

  48. .PHONY: install install: $(MAKE) -directory=app-php install $(MAKE) -directory=app-js install $(MAKE)

    -C app-ologies install $(MAKE) -C app-artement install $(MAKE) -C app-toum install $(MAKE) -C app-app-app install
  49. .PHONY: install install: $(MAKE) -directory=app-php install $(MAKE) -directory=app-js install $(MAKE)

    -C app-ologies install $(MAKE) -C app-artement install $(MAKE) -C app-toum install $(MAKE) -C app-app-app install
  50. MAKE MONO-REPOSITORY EASY ! @GillesRoustan

  51. DIRS:=$(dir $(wildcard */)) .PHONY: install $(DIRS) install: $(DIRS) test-unit: $(DIRS)

    $(DIRS): $(MAKE) --directory=$@ $(MAKECMDGOALS)
  52. MAKE I HELP YOU ? @GillesRoustan

  53. help: ## This help @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(TARGETS) |

    sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
  54. help: ## This help @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(TARGETS) |

    sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' https://marmelab.com/blog/2016/02/29/au to-documented-makefile.html
  55. $ make help install Install app undate Update app test-unit

    Unit test app minify Minify js/css serve Run server ...
  56. ADOPTE UN MAKE

  57. https://github.com/gbprod/conf-makefile

  58. THANK YOU QUESTIONS ?