Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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: 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. # Use GNU Tar where available
  23. ifneq (, $(shell which gtar))
  24. TAR := gtar
  25. else
  26. TAR := tar
  27. endif
  28. code_sniffer:
  29. @$(PHPCS)
  30. ### - errors by Git author
  31. code_sniffer_blame:
  32. @$(PHPCS) --report-gitblame
  33. ### - all errors/warnings
  34. code_sniffer_full:
  35. @$(PHPCS) --report-full --report-width=200
  36. ### - errors grouped by kind
  37. code_sniffer_source:
  38. @$(PHPCS) --report-source || exit 0
  39. ##
  40. # Checks source file & script permissions
  41. ##
  42. check_permissions:
  43. @echo "----------------------"
  44. @echo "Check file permissions"
  45. @echo "----------------------"
  46. @for file in `git ls-files | grep -v docker`; do \
  47. if [ -x $$file ]; then \
  48. errors=true; \
  49. echo "$${file} is executable"; \
  50. fi \
  51. done; [ -z $$errors ] || false
  52. ##
  53. # PHPUnit
  54. # Runs unitary and functional tests
  55. # Generates an HTML coverage report if Xdebug is enabled
  56. #
  57. # See phpunit.xml for configuration
  58. # https://phpunit.de/manual/current/en/appendixes.configuration.html
  59. ##
  60. test: translate
  61. @echo "-------"
  62. @echo "PHPUNIT"
  63. @echo "-------"
  64. @mkdir -p sandbox coverage
  65. @$(BIN)/phpunit --coverage-php coverage/main.cov --bootstrap tests/bootstrap.php --testsuite unit-tests
  66. locale_test_%:
  67. @UT_LOCALE=$*.utf8 \
  68. $(BIN)/phpunit \
  69. --coverage-php coverage/$(firstword $(subst _, ,$*)).cov \
  70. --bootstrap tests/languages/bootstrap.php \
  71. --testsuite language-$(firstword $(subst _, ,$*))
  72. all_tests: test locale_test_de_DE locale_test_en_US locale_test_fr_FR
  73. @# --The current version is not compatible with PHP 7.2
  74. @#$(BIN)/phpcov merge --html coverage coverage
  75. @# --text doesn't work with phpunit 4.* (v5 requires PHP 5.6)
  76. @#$(BIN)/phpcov merge --text coverage/txt coverage
  77. ### download 3rd-party PHP libraries, including dev dependencies
  78. composer_dependencies_dev: clean
  79. composer install --prefer-dist
  80. ##
  81. # Custom release archive generation
  82. #
  83. # For each tagged revision, GitHub provides tar and zip archives that correspond
  84. # to the output of git-archive
  85. #
  86. # These targets produce similar archives, featuring 3rd-party dependencies
  87. # to ease deployment on shared hosting.
  88. ##
  89. ARCHIVE_VERSION := shaarli-$$(git describe)-full
  90. ARCHIVE_PREFIX=Shaarli/
  91. release_archive: release_tar release_zip
  92. ### download 3rd-party PHP libraries
  93. composer_dependencies: clean
  94. composer install --no-dev --prefer-dist
  95. find vendor/ -name ".git" -type d -exec rm -rf {} +
  96. ### download 3rd-party frontend libraries
  97. frontend_dependencies:
  98. yarnpkg install
  99. ### Build frontend dependencies
  100. build_frontend: frontend_dependencies
  101. yarnpkg run build
  102. ### generate a release tarball and include 3rd-party dependencies and translations
  103. release_tar: composer_dependencies htmldoc translate build_frontend
  104. git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD
  105. $(TAR) rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/
  106. $(TAR) rvf $(ARCHIVE_VERSION).tar --transform "s|^doc/html|$(ARCHIVE_PREFIX)doc/html|" doc/html/
  107. $(TAR) rvf $(ARCHIVE_VERSION).tar --transform "s|^tpl|$(ARCHIVE_PREFIX)tpl|" tpl/
  108. gzip $(ARCHIVE_VERSION).tar
  109. ### generate a release zip and include 3rd-party dependencies and translations
  110. release_zip: composer_dependencies htmldoc translate build_frontend
  111. git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD
  112. mkdir -p $(ARCHIVE_PREFIX)/doc
  113. mkdir -p $(ARCHIVE_PREFIX)/vendor
  114. rsync -a doc/html/ $(ARCHIVE_PREFIX)doc/html/
  115. zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)doc/
  116. rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/
  117. zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/
  118. rsync -a tpl/ $(ARCHIVE_PREFIX)tpl/
  119. zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)tpl/
  120. rm -rf $(ARCHIVE_PREFIX)
  121. ##
  122. # Targets for repository and documentation maintenance
  123. ##
  124. ### remove all unversioned files
  125. clean:
  126. @git clean -df
  127. @rm -rf sandbox
  128. ### generate the AUTHORS file from Git commit information
  129. generate_authors:
  130. @cp .github/mailmap .mailmap
  131. @git shortlog -sne > AUTHORS
  132. @rm .mailmap
  133. ### generate phpDocumentor documentation
  134. phpdoc: clean
  135. @docker run --rm -v $(PWD):/data -u `id -u`:`id -g` phpdoc/phpdoc
  136. ### generate HTML documentation from Markdown pages with MkDocs
  137. htmldoc:
  138. python3 -m venv venv/
  139. bash -c 'source venv/bin/activate; \
  140. pip install wheel; \
  141. pip install mkdocs; \
  142. mkdocs build --clean'
  143. find doc/html/ -type f -exec chmod a-x '{}' \;
  144. rm -r venv
  145. ### Generate Shaarli's translation compiled file (.mo)
  146. translate:
  147. @echo "----------------------"
  148. @echo "Compile translation files"
  149. @echo "----------------------"
  150. @for pofile in `find inc/languages/ -name shaarli.po`; do \
  151. echo "Compiling $$pofile"; \
  152. msgfmt -v "$$pofile" -o "`dirname "$$pofile"`/`basename "$$pofile" .po`.mo"; \
  153. done;
  154. ### Run ESLint check against Shaarli's JS files
  155. eslint:
  156. @yarnpkg run eslint -c .dev/.eslintrc.js assets/vintage/js/
  157. @yarnpkg run eslint -c .dev/.eslintrc.js assets/default/js/
  158. @yarnpkg run eslint -c .dev/.eslintrc.js assets/common/js/
  159. ### Run CSSLint check against Shaarli's SCSS files
  160. sasslint:
  161. @yarnpkg run stylelint --config .dev/.stylelintrc.js 'assets/default/scss/*.scss'