Makefile 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. 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 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 "test"
  38. @echo " Run the tests for CakePHP."
  39. @echo ""
  40. @echo "All other tasks are not intended to be run directly."
  41. test: install
  42. vendor/bin/phpunit
  43. # Utility target for checking required parameters
  44. guard-%:
  45. @if [ "$($*)" = '' ]; then \
  46. echo "Missing required $* variable."; \
  47. exit 1; \
  48. fi;
  49. # Download composer
  50. composer.phar:
  51. curl -sS https://getcomposer.org/installer | php
  52. # Install dependencies
  53. install: composer.phar
  54. php composer.phar install
  55. # Version bumping & tagging for CakePHP itself
  56. # Update VERSION.txt to new version.
  57. bump-version: guard-VERSION
  58. @echo "Update VERSION.txt to $(VERSION)"
  59. # Work around sed being bad.
  60. mv VERSION.txt VERSION.old
  61. cat VERSION.old | sed s'/^[0-9]\.[0-9]\.[0-9].*/$(VERSION)/' > VERSION.txt
  62. rm VERSION.old
  63. git add VERSION.txt
  64. git commit -m "Update version number to $(VERSION)"
  65. # Tag a release
  66. tag-release: guard-VERSION bump-version
  67. @echo "Tagging $(VERSION)"
  68. git tag -s $(VERSION) -m "CakePHP $(VERSION)"
  69. git push $(REMOTE)
  70. git push $(REMOTE) --tags
  71. # Tasks for tagging the app skeleton and
  72. # creating a zipball of a fully built app skeleton.
  73. .PHONY: clean tag-app build-app package
  74. clean:
  75. rm -rf build
  76. rm -rf dist
  77. build:
  78. mkdir -p build
  79. build/app: build
  80. git clone git@github.com:$(OWNER)/app.git build/app/
  81. build/cakephp: build
  82. git checkout-index -a -f --prefix=build/cakephp/
  83. tag-app: guard-VERSION build/app
  84. @echo "Tagging new version of application skeleton"
  85. cd build/app && git tag -s $(VERSION) -m "CakePHP App $(VERSION)"
  86. cd build/app && git push $(REMOTE)
  87. cd build/app && git push $(REMOTE) --tags
  88. dist/cakephp-$(DASH_VERSION).zip: build/app build/cakephp composer.phar
  89. mkdir -p dist
  90. @echo "Installing app dependencies with composer"
  91. # Install deps with composer
  92. cd build/app && php ../../composer.phar install
  93. # Copy the current cakephp libs up so we don't have to wait
  94. # for packagist to refresh.
  95. rm -rf build/app/vendor/cakephp/cakephp
  96. cp -r build/cakephp build/app/vendor/cakephp/cakephp
  97. # Make a zipball of all the files that are not in .git dirs
  98. # Including .git will make zip balls huge, and the zipball is
  99. # intended for quick start non-git, non-cli users
  100. @echo "Building zipball for $(VERSION)"
  101. cd build/app && find . -not -path '*.git*' | zip ../../dist/cakephp-$(DASH_VERSION).zip -@
  102. # Easier to type alias for zip balls
  103. package: tag-app dist/cakephp-$(DASH_VERSION).zip
  104. # Tasks to publish zipballs to github.
  105. .PHONY: publish release
  106. publish: guard-VERSION guard-GITHUB_USER dist/cakephp-$(DASH_VERSION).zip
  107. @echo "Creating draft release for $(VERSION). prerelease=$(PRERELEASE)"
  108. curl $(AUTH) -XPOST $(API_HOST)/repos/$(OWNER)/cakephp/releases -d '{ \
  109. "tag_name": "$(VERSION)", \
  110. "name": "CakePHP $(VERSION) released", \
  111. "draft": true, \
  112. "prerelease": $(PRERELEASE) \
  113. }' > release.json
  114. # Extract id out of response json.
  115. php -r '$$f = file_get_contents("./release.json"); \
  116. $$d = json_decode($$f, true); \
  117. 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 reporsitories out of each cake 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:cakephp/$*.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 $* $*:master
  137. git checkout $(CURRENT_BRANCH) > /dev/null
  138. tag-component-%: component-% guard-VERSION guard-GITHUB_USER
  139. @echo "Creating tag for the $* component"
  140. git checkout $*
  141. curl $(AUTH) -XPOST $(API_HOST)/repos/$(OWNER)/$*/git/refs -d '{ \
  142. "refs": "refs\/tags\/$(VERSION)", \
  143. "sha": "$(shell git rev-parse $*)" \
  144. }'
  145. git checkout $(CURRENT_BRANCH) > /dev/null
  146. # Top level alias for doing a release.
  147. release: guard-VERSION guard-GITHUB_USER tag-release package publish components