Makefile 5.2 KB

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