Makefile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. .DEFAULT_GOAL := help
  2. .PHONY: *
  3. LATEST_PHP := 8.0 3.1.1
  4. COVERAGE_PHP := 7.4 3.1.1
  5. define PHP_VERSIONS
  6. "7.0 2.7.2"\
  7. "7.1 2.9.8"\
  8. "7.2 3.1.1"\
  9. "7.3 3.1.1"\
  10. "7.4 3.1.1"\
  11. "8.0 3.1.1"\
  12. "8.1 3.1.1"\
  13. "8.2 3.2.0"\
  14. "8.3-rc 3.3.0alpha3"
  15. endef
  16. define DOCKER_RUN
  17. ./build/docker-run.sh \
  18. $$(./build/build-image.sh $(1)) \
  19. $$(pwd) \
  20. "$(2)"
  21. endef
  22. help:
  23. @printf "\033[33mJSON Machine's make usage:\033[0m\n make [target] [args=\"val\"...]\n\n"
  24. @printf "\033[33mTargets:\033[0m\n"
  25. @grep -E '^[-a-zA-Z0-9_\.\/]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-15s\033[0m\t%s\n", $$1, $$2}'
  26. build: composer-validate cs-check phpstan tests-all ## Run all necessary stuff before commit.
  27. tests: ## Run tests on recent PHP version. Pass args to phpunit via ARGS=""
  28. @$(call DOCKER_RUN,$(COVERAGE_PHP),composer tests -- $(ARGS))
  29. tests-coverage: ## Runs tests and creates ./clover.xml. Pass args to phpunit via ARGS=""
  30. @$(call DOCKER_RUN,$(COVERAGE_PHP),composer tests-coverage -- $(ARGS))
  31. tests-all: ## Run tests on all supported PHP versions. Pass args to phpunit via ARGS=""
  32. @for version in $(PHP_VERSIONS); do \
  33. set -e; \
  34. printf "PHP %s%.s\n" $$version; \
  35. printf "=======\n"; \
  36. $(call DOCKER_RUN,$$version,composer tests -- --colors=always $(ARGS)); \
  37. printf "\n\n\n"; \
  38. done
  39. cs-check: ## Check code style
  40. @$(call DOCKER_RUN,$(LATEST_PHP),composer cs-check)
  41. phpstan: ## Run phpstan
  42. @$(call DOCKER_RUN,$(LATEST_PHP),composer phpstan)
  43. cs-fix: ## Fix code style
  44. @$(call DOCKER_RUN,$(LATEST_PHP),composer cs-fix)
  45. performance-tests: ## Run performance tests
  46. @$(call DOCKER_RUN,$(LATEST_PHP),composer performance-tests)
  47. composer-validate: ## Validate composer.json contents
  48. @$(call DOCKER_RUN,$(LATEST_PHP),composer validate)
  49. release: .env build
  50. @\
  51. branch=$$(git branch --show-current); \
  52. \
  53. echo "Creating release from '$$branch'"; \
  54. git diff --quiet --exit-code && git diff --quiet --cached --exit-code \
  55. || { echo "There are uncommited changes. Stopping"; exit 1; }; \
  56. \
  57. echo "Type the release version:"; \
  58. read version; \
  59. \
  60. echo "Is README updated accordingly? [ENTER to continue]"; \
  61. read pass; \
  62. \
  63. echo "Updating CHANGELOG.md"; \
  64. $(call DOCKER_RUN,$(LATEST_PHP),php build/update-changelog.php $$version CHANGELOG.md); \
  65. \
  66. git diff; \
  67. echo "Commit and tag this? [ENTER to continue]"; \
  68. read pass; \
  69. \
  70. set -x; \
  71. git commit -am "Release $$version"; \
  72. git tag -a "$$version" -m "Release $$version"; \
  73. set +x; \
  74. \
  75. echo "Push? [ENTER to continue]"; \
  76. read pass; \
  77. set -x; git push --follow-tags; set +x; \
  78. \
  79. echo "Publish '$$version' as a Github release? [ENTER to continue]"; \
  80. read pass; \
  81. . ./.env; \
  82. curl \
  83. --user "$$GITHUB_USER:$$GITHUB_TOKEN" \
  84. --request POST \
  85. --header "Accept: application/vnd.github.v3+json" \
  86. --data "{\"tag_name\":\"$$version\", \"target_commitish\": \"$$branch\", \"name\": \"$$version\", \"body\": \"See [CHANGELOG](CHANGELOG.md) for changes and release notes.\"}" \
  87. https://api.github.com/repos/halaxa/json-machine/releases \
  88. ;\
  89. docker-run: ## Run a command in a latest JSON Machine PHP docker container. Ex.: make docker-run CMD="php -v"
  90. @$(call DOCKER_RUN,$(LATEST_PHP),$(CMD))