Makefile 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. # The personal, minimalist, super-fast, database free, bookmarking service.
  2. # Makefile for PHP code analysis & testing, documentation and release generation
  3. # Prerequisites:
  4. # - install Composer, either:
  5. # - from your distro's package manager;
  6. # - from the official website (https://getcomposer.org/download/);
  7. # - install/update test dependencies:
  8. # $ composer install # 1st setup
  9. # $ composer update
  10. # - install Xdebug for PHPUnit code coverage reports:
  11. # - see http://xdebug.org/docs/install
  12. # - enable in php.ini
  13. BIN = vendor/bin
  14. PHP_SOURCE = index.php application tests plugins
  15. PHP_COMMA_SOURCE = index.php,application,tests,plugins
  16. all: static_analysis_summary check_permissions test
  17. ##
  18. # Docker test adapter
  19. #
  20. # Shaarli sources and vendored libraries are copied from a shared volume
  21. # to a user-owned directory to enable running tests as a non-root user.
  22. ##
  23. docker_%:
  24. rsync -az /shaarli/ ~/shaarli/
  25. cd ~/shaarli && make $*
  26. ##
  27. # Concise status of the project
  28. # These targets are non-blocking: || exit 0
  29. ##
  30. static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
  31. @echo
  32. ##
  33. # PHP_CodeSniffer
  34. # Detects PHP syntax errors
  35. # Documentation (usage, output formatting):
  36. # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
  37. # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
  38. ##
  39. code_sniffer: code_sniffer_full
  40. ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
  41. PHPCS_%:
  42. @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$*
  43. ### - errors by Git author
  44. code_sniffer_blame:
  45. @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
  46. ### - all errors/warnings
  47. code_sniffer_full:
  48. @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
  49. ### - errors grouped by kind
  50. code_sniffer_source:
  51. @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
  52. ##
  53. # PHP Copy/Paste Detector
  54. # Detects code redundancy
  55. # Documentation: https://github.com/sebastianbergmann/phpcpd
  56. ##
  57. copy_paste:
  58. @echo "-----------------------"
  59. @echo "PHP COPY/PASTE DETECTOR"
  60. @echo "-----------------------"
  61. @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
  62. @echo
  63. ##
  64. # PHP Mess Detector
  65. # Detects PHP syntax errors, sorted by category
  66. # Rules documentation: http://phpmd.org/rules/index.html
  67. ##
  68. MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
  69. mess_title:
  70. @echo "-----------------"
  71. @echo "PHP MESS DETECTOR"
  72. @echo "-----------------"
  73. ### - all warnings
  74. mess_detector: mess_title
  75. @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
  76. ### - all warnings + HTML output contains links to PHPMD's documentation
  77. mess_detector_html:
  78. @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
  79. --reportfile phpmd.html || exit 0
  80. ### - warnings grouped by message, sorted by descending frequency order
  81. mess_detector_grouped: mess_title
  82. @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
  83. | cut -f 2 | sort | uniq -c | sort -nr
  84. ### - summary: number of warnings by rule set
  85. mess_detector_summary: mess_title
  86. @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
  87. warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \
  88. printf "$$warnings\t$$rule\n"; \
  89. done;
  90. ##
  91. # Checks source file & script permissions
  92. ##
  93. check_permissions:
  94. @echo "----------------------"
  95. @echo "Check file permissions"
  96. @echo "----------------------"
  97. @for file in `git ls-files`; do \
  98. if [ -x $$file ]; then \
  99. errors=true; \
  100. echo "$${file} is executable"; \
  101. fi \
  102. done; [ -z $$errors ] || false
  103. ##
  104. # PHPUnit
  105. # Runs unitary and functional tests
  106. # Generates an HTML coverage report if Xdebug is enabled
  107. #
  108. # See phpunit.xml for configuration
  109. # https://phpunit.de/manual/current/en/appendixes.configuration.html
  110. ##
  111. test:
  112. @echo "-------"
  113. @echo "PHPUNIT"
  114. @echo "-------"
  115. @mkdir -p sandbox coverage
  116. @$(BIN)/phpunit --coverage-php coverage/main.cov --testsuite unit-tests
  117. locale_test_%:
  118. @UT_LOCALE=$*.utf8 \
  119. $(BIN)/phpunit \
  120. --coverage-php coverage/$(firstword $(subst _, ,$*)).cov \
  121. --bootstrap tests/languages/bootstrap.php \
  122. --testsuite language-$(firstword $(subst _, ,$*))
  123. all_tests: test locale_test_de_DE locale_test_en_US locale_test_fr_FR
  124. @$(BIN)/phpcov merge --html coverage coverage
  125. @# --text doesn't work with phpunit 4.* (v5 requires PHP 5.6)
  126. @#$(BIN)/phpcov merge --text coverage/txt coverage
  127. ##
  128. # Custom release archive generation
  129. #
  130. # For each tagged revision, GitHub provides tar and zip archives that correspond
  131. # to the output of git-archive
  132. #
  133. # These targets produce similar archives, featuring 3rd-party dependencies
  134. # to ease deployment on shared hosting.
  135. ##
  136. ARCHIVE_VERSION := shaarli-$$(git describe)-full
  137. ARCHIVE_PREFIX=Shaarli/
  138. release_archive: release_tar release_zip
  139. ### download 3rd-party PHP libraries
  140. composer_dependencies: clean
  141. composer install --no-dev --prefer-dist
  142. find vendor/ -name ".git" -type d -exec rm -rf {} +
  143. ### generate a release tarball and include 3rd-party dependencies
  144. release_tar: composer_dependencies htmldoc
  145. git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD
  146. tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/
  147. tar rvf $(ARCHIVE_VERSION).tar --transform "s|^doc/html|$(ARCHIVE_PREFIX)doc/html|" doc/html/
  148. gzip $(ARCHIVE_VERSION).tar
  149. ### generate a release zip and include 3rd-party dependencies
  150. release_zip: composer_dependencies htmldoc
  151. git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD
  152. mkdir -p $(ARCHIVE_PREFIX)/{doc,vendor}
  153. rsync -a doc/html/ $(ARCHIVE_PREFIX)doc/html/
  154. zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)doc/
  155. rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/
  156. zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/
  157. rm -rf $(ARCHIVE_PREFIX)
  158. ##
  159. # Targets for repository and documentation maintenance
  160. ##
  161. ### remove all unversioned files
  162. clean:
  163. @git clean -df
  164. @rm -rf sandbox
  165. ### generate the AUTHORS file from Git commit information
  166. authors:
  167. @cp .github/mailmap .mailmap
  168. @git shortlog -sne > AUTHORS
  169. @rm .mailmap
  170. ### generate Doxygen documentation
  171. doxygen: clean
  172. @rm -rf doxygen
  173. @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
  174. ### generate HTML documentation from Markdown pages with MkDocs
  175. htmldoc:
  176. python3 -m venv venv/
  177. bash -c 'source venv/bin/activate; \
  178. pip install mkdocs; \
  179. mkdocs build'
  180. find doc/html/ -type f -exec chmod a-x '{}' \;
  181. rm -r venv