Makefile 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # The following env variables need to be set:
  2. # - VERSION
  3. # - GITHUB_USER
  4. # - GITHUB_TOKEN (optional if you have two factor authentication in github)
  5. # Use the version number to figure out if the release
  6. # is a pre-release
  7. PRERELEASE=$(shell echo $(VERSION) | grep -E 'dev|rc|alpha|beta' --quiet && echo 'true' || echo 'false')
  8. # Github settings
  9. UPLOAD_HOST=https://uploads.github.com
  10. API_HOST=https://api.github.com
  11. OWNER='cakephp'
  12. REMOTE="origin"
  13. ifdef GITHUB_TOKEN
  14. AUTH=-H 'Authorization: token $(GITHUB_TOKEN)'
  15. else
  16. AUTH=-u $(GITHUB_USER) -p$(GITHUB_PASS)
  17. endif
  18. ALL: help
  19. .PHONY: help install test need-version bump-version tag-version
  20. help:
  21. @echo "CakePHP Makefile"
  22. @echo "================"
  23. @echo ""
  24. @echo "release"
  25. @echo " Create a new release of CakePHP. Requires the VERSION and GITHUB_USER parameter."
  26. @echo " Packages up a new app skeleton tarball and uploads it to github."
  27. @echo ""
  28. @echo "package"
  29. @echo " Build the app package with all its dependencies."
  30. @echo ""
  31. @echo "publish"
  32. @echo " Publish the dist/cakephp-VERSION.zip to github."
  33. @echo ""
  34. @echo "test"
  35. @echo " Run the tests for CakePHP."
  36. @echo ""
  37. @echo "All other tasks are not intended to be run directly."
  38. test: install
  39. vendor/bin/phpunit
  40. # Utility target for checking required parameters
  41. guard-%:
  42. @if [ "$($*)" = '' ]; then \
  43. echo "Missing required $* variable."; \
  44. exit 1; \
  45. fi;
  46. # Download composer
  47. composer.phar:
  48. curl -sS https://getcomposer.org/installer | php
  49. # Install dependencies
  50. install: composer.phar
  51. php composer.phar install
  52. # Version bumping & tagging for CakePHP itself
  53. # Update VERSION.txt to new version.
  54. bump-version: guard-VERSION
  55. @echo "Update VERSION.txt to $(VERSION)"
  56. # Work around sed being bad.
  57. mv VERSION.txt VERSION.old
  58. cat VERSION.old | sed s'/^[0-9]\.[0-9]\.[0-9].*/$(VERSION)/' > VERSION.txt
  59. rm VERSION.old
  60. git add VERSION.txt
  61. git commit -m "Update version number to $(VERSION)"
  62. # Tag a release
  63. tag-release: guard-VERSION bump-version
  64. @echo "Tagging $(VERSION)"
  65. git tag -s $(VERSION) -m "CakePHP $(VERSION)"
  66. git push $(REMOTE)
  67. git push $(REMOTE) --tags
  68. # Tasks for tagging the app skeleton and
  69. # creating a zipball of a fully built app skeleton.
  70. .PHONY: clean tag-app build-app package
  71. clean:
  72. rm -rf build
  73. rm -rf dist
  74. build:
  75. mkdir -p build
  76. build/app: build
  77. git clone git@github.com:$(OWNER)/app.git build/app/
  78. build/cakephp: build
  79. git checkout-index -a -f --prefix=build/cakephp/
  80. tag-app: guard-VERSION build/app
  81. @echo "Tagging new version of application skeleton"
  82. cd build/app && git tag -s $(VERSION) -m "CakePHP App $(VERSION)"
  83. cd build/app && git push $(REMOTE)
  84. cd build/app && git push $(REMOTE) --tags
  85. dist/cakephp-$(VERSION).zip: build/app build/cakephp composer.phar
  86. mkdir -p dist
  87. @echo "Installing app dependencies with composer"
  88. # Install deps with composer
  89. cd build/app && php ../../composer.phar install
  90. # Copy the current cakephp libs up so we don't have to wait
  91. # for packagist to refresh.
  92. rm -rf build/app/vendor/cakephp/cakephp
  93. cp -r build/cakephp build/app/vendor/cakephp/cakephp
  94. # Make a zipball of all the files that are not in .git dirs
  95. # Including .git will make zip balls huge, and the zipball is
  96. # intended for quick start non-git, non-cli users
  97. @echo "Building zipball for $(VERSION)"
  98. cd build/app && find . -not -path '*.git*' | zip ../../dist/cakephp-$(VERSION).zip -@
  99. # Easier to type alias for zip balls
  100. package: tag-app dist/cakephp-$(VERSION).zip
  101. # Tasks to publish zipballs to github.
  102. .PHONY: publish release
  103. publish: guard-VERSION guard-GITHUB_USER dist/cakephp-$(VERSION).zip
  104. @echo "Creating draft release for $(VERSION). prerelease=$(PRERELEASE)"
  105. curl $(AUTH) -XPOST $(API_HOST)/repos/$(OWNER)/cakephp/releases -d '{ \
  106. "tag_name": "$(VERSION)", \
  107. "name": "CakePHP $(VERSION) released", \
  108. "draft": true, \
  109. "prerelease": $(PRERELEASE) \
  110. }' > release.json
  111. # Extract id out of response json.
  112. php -r '$$f = file_get_contents("./release.json"); \
  113. $$d = json_decode($$f, true); \
  114. file_put_contents("./id.txt", $$d["id"]);'
  115. @echo "Uploading zip file to github."
  116. curl $(AUTH) -XPOST \
  117. $(UPLOAD_HOST)/repos/$(OWNER)/cakephp/releases/`cat ./id.txt`/assets?name=cakephp-$(VERSION).zip \
  118. -H 'Content-Type: application/zip' \
  119. -d '@dist/cakephp-$(VERSION).zip'
  120. # Cleanup files.
  121. rm release.json
  122. rm id.txt
  123. # Top level alias for doing a release.
  124. release: guard-VERSION guard-GITHUB_USER tag-release package publish