]>
Commit | Line | Data |
---|---|---|
1 | # The personal, minimalist, super-fast, database free, bookmarking service. | |
2 | # Makefile for PHP code analysis & testing, documentation and release generation | |
3 | ||
4 | BIN = vendor/bin | |
5 | PHP_SOURCE = index.php application tests plugins | |
6 | PHP_COMMA_SOURCE = index.php,application,tests,plugins | |
7 | ||
8 | all: static_analysis_summary check_permissions test | |
9 | ||
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 | ## | |
16 | docker_%: | |
17 | rsync -az /shaarli/ ~/shaarli/ | |
18 | cd ~/shaarli && make $* | |
19 | ||
20 | ## | |
21 | # Concise status of the project | |
22 | # These targets are non-blocking: || exit 0 | |
23 | ## | |
24 | ||
25 | static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary | |
26 | @echo | |
27 | ||
28 | ## | |
29 | # PHP_CodeSniffer | |
30 | # Detects PHP syntax errors | |
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 | ## | |
35 | ||
36 | code_sniffer: code_sniffer_full | |
37 | ||
38 | ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend... | |
39 | PHPCS_%: | |
40 | @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$* | |
41 | ||
42 | ### - errors by Git author | |
43 | code_sniffer_blame: | |
44 | @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame | |
45 | ||
46 | ### - all errors/warnings | |
47 | code_sniffer_full: | |
48 | @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 | |
49 | ||
50 | ### - errors grouped by kind | |
51 | code_sniffer_source: | |
52 | @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0 | |
53 | ||
54 | ## | |
55 | # PHP Copy/Paste Detector | |
56 | # Detects code redundancy | |
57 | # Documentation: https://github.com/sebastianbergmann/phpcpd | |
58 | ## | |
59 | ||
60 | copy_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 | |
69 | # Detects PHP syntax errors, sorted by category | |
70 | # Rules documentation: http://phpmd.org/rules/index.html | |
71 | ## | |
72 | MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode | |
73 | ||
74 | mess_title: | |
75 | @echo "-----------------" | |
76 | @echo "PHP MESS DETECTOR" | |
77 | @echo "-----------------" | |
78 | ||
79 | ### - all warnings | |
80 | mess_detector: mess_title | |
81 | @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__' | |
82 | ||
83 | ### - all warnings + HTML output contains links to PHPMD's documentation | |
84 | mess_detector_html: | |
85 | @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \ | |
86 | --reportfile phpmd.html || exit 0 | |
87 | ||
88 | ### - warnings grouped by message, sorted by descending frequency order | |
89 | mess_detector_grouped: mess_title | |
90 | @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \ | |
91 | | cut -f 2 | sort | uniq -c | sort -nr | |
92 | ||
93 | ### - summary: number of warnings by rule set | |
94 | mess_detector_summary: mess_title | |
95 | @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \ | |
96 | warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \ | |
97 | printf "$$warnings\t$$rule\n"; \ | |
98 | done; | |
99 | ||
100 | ## | |
101 | # Checks source file & script permissions | |
102 | ## | |
103 | check_permissions: | |
104 | @echo "----------------------" | |
105 | @echo "Check file permissions" | |
106 | @echo "----------------------" | |
107 | @for file in `git ls-files | grep -v docker`; do \ | |
108 | if [ -x $$file ]; then \ | |
109 | errors=true; \ | |
110 | echo "$${file} is executable"; \ | |
111 | fi \ | |
112 | done; [ -z $$errors ] || false | |
113 | ||
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 | ## | |
122 | test: translate | |
123 | @echo "-------" | |
124 | @echo "PHPUNIT" | |
125 | @echo "-------" | |
126 | @mkdir -p sandbox coverage | |
127 | @$(BIN)/phpunit --coverage-php coverage/main.cov --bootstrap tests/bootstrap.php --testsuite unit-tests | |
128 | ||
129 | locale_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 | ||
136 | all_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 | |
140 | ||
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 | ## | |
150 | ARCHIVE_VERSION := shaarli-$$(git describe)-full | |
151 | ARCHIVE_PREFIX=Shaarli/ | |
152 | ||
153 | release_archive: release_tar release_zip | |
154 | ||
155 | ### download 3rd-party PHP libraries | |
156 | composer_dependencies: clean | |
157 | composer install --no-dev --prefer-dist | |
158 | find vendor/ -name ".git" -type d -exec rm -rf {} + | |
159 | ||
160 | ### download 3rd-party frontend libraries | |
161 | frontend_dependencies: | |
162 | yarn install | |
163 | ||
164 | ### Build frontend dependencies | |
165 | build_frontend: frontend_dependencies | |
166 | yarn run build | |
167 | ||
168 | ### generate a release tarball and include 3rd-party dependencies and translations | |
169 | release_tar: composer_dependencies htmldoc translate build_frontend | |
170 | git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD | |
171 | tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/ | |
172 | tar rvf $(ARCHIVE_VERSION).tar --transform "s|^doc/html|$(ARCHIVE_PREFIX)doc/html|" doc/html/ | |
173 | gzip $(ARCHIVE_VERSION).tar | |
174 | ||
175 | ### generate a release zip and include 3rd-party dependencies and translations | |
176 | release_zip: composer_dependencies htmldoc translate build_frontend | |
177 | git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD | |
178 | mkdir -p $(ARCHIVE_PREFIX)/{doc,vendor} | |
179 | rsync -a doc/html/ $(ARCHIVE_PREFIX)doc/html/ | |
180 | zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)doc/ | |
181 | rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/ | |
182 | zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/ | |
183 | rm -rf $(ARCHIVE_PREFIX) | |
184 | ||
185 | ## | |
186 | # Targets for repository and documentation maintenance | |
187 | ## | |
188 | ||
189 | ### remove all unversioned files | |
190 | clean: | |
191 | @git clean -df | |
192 | @rm -rf sandbox | |
193 | ||
194 | ### generate the AUTHORS file from Git commit information | |
195 | authors: | |
196 | @cp .github/mailmap .mailmap | |
197 | @git shortlog -sne > AUTHORS | |
198 | @rm .mailmap | |
199 | ||
200 | ### generate Doxygen documentation | |
201 | doxygen: clean | |
202 | @rm -rf doxygen | |
203 | @doxygen Doxyfile | |
204 | ||
205 | ### generate HTML documentation from Markdown pages with MkDocs | |
206 | htmldoc: | |
207 | python3 -m venv venv/ | |
208 | bash -c 'source venv/bin/activate; \ | |
209 | pip install mkdocs; \ | |
210 | mkdocs build --clean' | |
211 | find doc/html/ -type f -exec chmod a-x '{}' \; | |
212 | rm -r venv | |
213 | ||
214 | ||
215 | ### Generate Shaarli's translation compiled file (.mo) | |
216 | translate: | |
217 | @find inc/languages/ -name shaarli.po -execdir msgfmt shaarli.po -o shaarli.mo \; | |
218 | ||
219 | ### Run ESLint check against Shaarli's JS files | |
220 | eslint: | |
221 | @yarn run eslint -c .dev/.eslintrc.js assets/vintage/js/ | |
222 | @yarn run eslint -c .dev/.eslintrc.js assets/default/js/ | |
223 | ||
224 | ### Run CSSLint check against Shaarli's SCSS files | |
225 | sasslint: | |
226 | @yarn run sass-lint -c .dev/.sasslintrc 'assets/default/scss/*.scss' -v -q |