Makefile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. all: static_analysis_summary check_permissions test
  5. ##
  6. # Docker test adapter
  7. #
  8. # Shaarli sources and vendored libraries are copied from a shared volume
  9. # to a user-owned directory to enable running tests as a non-root user.
  10. ##
  11. docker_%:
  12. rsync -az /shaarli/ ~/shaarli/
  13. cd ~/shaarli && make $*
  14. ##
  15. # PHP_CodeSniffer
  16. # Detects PHP syntax errors
  17. # Documentation (usage, output formatting):
  18. # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
  19. # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
  20. ##
  21. PHPCS := $(BIN)/phpcs
  22. code_sniffer:
  23. @$(PHPCS)
  24. ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
  25. PHPCS_%:
  26. @$(PHPCS) --report-full --report-width=200 --standard=$*
  27. ### - errors by Git author
  28. code_sniffer_blame:
  29. @$(PHPCS) --report-gitblame
  30. ### - all errors/warnings
  31. code_sniffer_full:
  32. @$(PHPCS) --report-full --report-width=200
  33. ### - errors grouped by kind
  34. code_sniffer_source:
  35. @$(PHPCS) --report-source || exit 0
  36. ##
  37. # Checks source file & script permissions
  38. ##
  39. check_permissions:
  40. @echo "----------------------"
  41. @echo "Check file permissions"
  42. @echo "----------------------"
  43. @for file in `git ls-files | grep -v docker`; do \
  44. if [ -x $$file ]; then \
  45. errors=true; \
  46. echo "$${file} is executable"; \
  47. fi \
  48. done; [ -z $$errors ] || false
  49. ##
  50. # PHPUnit
  51. # Runs unitary and functional tests
  52. # Generates an HTML coverage report if Xdebug is enabled
  53. #
  54. # See phpunit.xml for configuration
  55. # https://phpunit.de/manual/current/en/appendixes.configuration.html
  56. ##
  57. test: translate
  58. @echo "-------"
  59. @echo "PHPUNIT"
  60. @echo "-------"
  61. @mkdir -p sandbox coverage
  62. @$(BIN)/phpunit --coverage-php coverage/main.cov --bootstrap tests/bootstrap.php --testsuite unit-tests
  63. locale_test_%:
  64. @UT_LOCALE=$*.utf8 \
  65. $(BIN)/phpunit \
  66. --coverage-php coverage/$(firstword $(subst _, ,$*)).cov \
  67. --bootstrap tests/languages/bootstrap.php \
  68. --testsuite language-$(firstword $(subst _, ,$*))
  69. all_tests: test locale_test_de_DE locale_test_en_US locale_test_fr_FR
  70. @$(BIN)/phpcov merge --html coverage coverage
  71. @# --text doesn't work with phpunit 4.* (v5 requires PHP 5.6)
  72. @#$(BIN)/phpcov merge --text coverage/txt coverage
  73. ##
  74. # Custom release archive generation
  75. #
  76. # For each tagged revision, GitHub provides tar and zip archives that correspond
  77. # to the output of git-archive
  78. #
  79. # These targets produce similar archives, featuring 3rd-party dependencies
  80. # to ease deployment on shared hosting.
  81. ##
  82. ARCHIVE_VERSION := shaarli-$$(git describe)-full
  83. ARCHIVE_PREFIX=Shaarli/
  84. release_archive: release_tar release_zip
  85. ### download 3rd-party PHP libraries
  86. composer_dependencies: clean
  87. composer install --no-dev --prefer-dist
  88. find vendor/ -name ".git" -type d -exec rm -rf {} +
  89. ### download 3rd-party frontend libraries
  90. frontend_dependencies:
  91. yarn install
  92. ### Build frontend dependencies
  93. build_frontend: frontend_dependencies
  94. yarn run build
  95. ### generate a release tarball and include 3rd-party dependencies and translations
  96. release_tar: composer_dependencies htmldoc translate build_frontend
  97. git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD
  98. tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/
  99. tar rvf $(ARCHIVE_VERSION).tar --transform "s|^doc/html|$(ARCHIVE_PREFIX)doc/html|" doc/html/
  100. tar rvf $(ARCHIVE_VERSION).tar --transform "s|^tpl|$(ARCHIVE_PREFIX)tpl|" tpl/
  101. gzip $(ARCHIVE_VERSION).tar
  102. ### generate a release zip and include 3rd-party dependencies and translations
  103. release_zip: composer_dependencies htmldoc translate build_frontend
  104. git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD
  105. mkdir -p $(ARCHIVE_PREFIX)/{doc,vendor}
  106. rsync -a doc/html/ $(ARCHIVE_PREFIX)doc/html/
  107. zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)doc/
  108. rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/
  109. zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/
  110. rsync -a tpl/ $(ARCHIVE_PREFIX)tpl/
  111. zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)tpl/
  112. rm -rf $(ARCHIVE_PREFIX)
  113. ##
  114. # Targets for repository and documentation maintenance
  115. ##
  116. ### remove all unversioned files
  117. clean:
  118. @git clean -df
  119. @rm -rf sandbox
  120. ### generate the AUTHORS file from Git commit information
  121. authors:
  122. @cp .github/mailmap .mailmap
  123. @git shortlog -sne > AUTHORS
  124. @rm .mailmap
  125. ### generate Doxygen documentation
  126. doxygen: clean
  127. @rm -rf doxygen
  128. @doxygen Doxyfile
  129. ### generate HTML documentation from Markdown pages with MkDocs
  130. htmldoc:
  131. python3 -m venv venv/
  132. bash -c 'source venv/bin/activate; \
  133. pip install mkdocs; \
  134. mkdocs build --clean'
  135. find doc/html/ -type f -exec chmod a-x '{}' \;
  136. rm -r venv
  137. ### Generate Shaarli's translation compiled file (.mo)
  138. translate:
  139. @find inc/languages/ -name shaarli.po -execdir msgfmt shaarli.po -o shaarli.mo \;
  140. ### Run ESLint check against Shaarli's JS files
  141. eslint:
  142. @yarn run eslint -c .dev/.eslintrc.js assets/vintage/js/
  143. @yarn run eslint -c .dev/.eslintrc.js assets/default/js/
  144. ### Run CSSLint check against Shaarli's SCSS files
  145. sasslint:
  146. @yarn run sass-lint -c .dev/.sasslintrc 'assets/default/scss/*.scss' -v -q