Makefile 4.4 KB

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