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