Makefile 5.7 KB

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