Makefile 6.1 KB

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