Makefile 6.3 KB

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