Makefile 4.9 KB

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