Makefile 6.6 KB

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