Makefile 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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:=master
  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"
  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 "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 guard-GITHUB_USER 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 '{ \
  116. "tag_name": "$(VERSION)", \
  117. "name": "CakePHP $(VERSION) released", \
  118. "draft": true, \
  119. "prerelease": $(PRERELEASE) \
  120. }' > release.json
  121. # Extract id out of response json.
  122. php -r '$$f = file_get_contents("./release.json"); \
  123. $$d = json_decode($$f, true); \
  124. file_put_contents("./id.txt", $$d["id"]);'
  125. @echo "Uploading zip file to github."
  126. curl $(AUTH) -XPOST \
  127. $(UPLOAD_HOST)/repos/$(OWNER)/cakephp/releases/`cat ./id.txt`/assets?name=cakephp-$(DASH_VERSION).zip \
  128. -H "Accept: application/vnd.github.manifold-preview" \
  129. -H 'Content-Type: application/zip' \
  130. --data-binary '@dist/cakephp-$(DASH_VERSION).zip'
  131. # Cleanup files.
  132. rm release.json
  133. rm id.txt
  134. # Tasks for publishing separate repositories out of each CakePHP namespace
  135. components: $(foreach component, $(COMPONENTS), component-$(component))
  136. components-tag: $(foreach component, $(COMPONENTS), tag-component-$(component))
  137. component-%:
  138. git checkout $(CURRENT_BRANCH) > /dev/null
  139. - (git remote add $* git@github.com:$(OWNER)/$*.git -f 2> /dev/null)
  140. - (git branch -D $* 2> /dev/null)
  141. git checkout -b $*
  142. git filter-branch --prune-empty --subdirectory-filter src/$(shell php -r "echo ucfirst('$*');") -f $*
  143. git push -f $* $*:$(CURRENT_BRANCH)
  144. git checkout $(CURRENT_BRANCH) > /dev/null
  145. tag-component-%: component-% guard-VERSION guard-GITHUB_USER
  146. @echo "Creating tag for the $* component"
  147. git checkout $*
  148. curl $(AUTH) -XPOST $(API_HOST)/repos/$(OWNER)/$*/git/refs -d '{ \
  149. "ref": "refs\/tags\/$(VERSION)", \
  150. "sha": "$(shell git rev-parse $*)" \
  151. }'
  152. git checkout $(CURRENT_BRANCH) > /dev/null
  153. git branch -D $*
  154. git remote rm $*
  155. # Top level alias for doing a release.
  156. release: guard-VERSION guard-GITHUB_USER tag-release components-tag package publish