forked from WordPress/WordPress-Coding-Standards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
190 lines (167 loc) · 7.49 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
os: linux
dist: xenial
cache:
apt: true
directories:
# Cache directory for older Composer versions.
- $HOME/.composer/cache/files
# Cache directory for more recent Composer versions.
- $HOME/.cache/composer/files
language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- "nightly"
env:
# PHPCS `master`.
- PHPCS_BRANCH="dev-master" LINT=1
# Lowest supported release in the 3.x series with which WPCS is compatible.
- PHPCS_BRANCH="3.5.0"
# Define the stages used.
# For non-PRs, only the sniff, ruleset and quicktest stages are run.
# For pull requests and merges, the full script is run (skipping quicktest).
# Note: for pull requests, "develop" should be the base branch name.
# See: https://docs.travis-ci.com/user/conditions-v1
stages:
- name: sniff
- name: rulesets
- name: quicktest
if: type = push AND branch NOT IN (master, develop)
- name: test
if: branch IN (master, develop)
jobs:
fast_finish: true
include:
#### SNIFF STAGE ####
- stage: sniff
php: 7.4
env: PHPCS_BRANCH="dev-master"
addons:
apt:
packages:
- libxml2-utils
script:
# WordPress Coding Standards.
# @link https://github.com/WordPress/WordPress-Coding-Standards
# @link http://pear.php.net/package/PHP_CodeSniffer/
- $(pwd)/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1
# Validate the xml files.
# @link http://xmlsoft.org/xmllint.html
# For the build to properly error when validating against a scheme, these each have to be in their own condition.
- xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml
- xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./phpcs.xml.dist.sample
# Check the code-style consistency of the xml files.
- diff -B --tabsize=4 ./WordPress/ruleset.xml <(xmllint --format "./WordPress/ruleset.xml")
- diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml")
- diff -B --tabsize=4 ./WordPress-Docs/ruleset.xml <(xmllint --format "./WordPress-Docs/ruleset.xml")
- diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml")
- diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample")
# Validate the composer.json file.
# @link https://getcomposer.org/doc/03-cli.md#validate
- composer validate --no-check-all --strict
# Check that the sniffs available are feature complete.
# For now, just check that all sniffs have unit tests.
# At a later stage the documentation check can be activated.
- composer check-complete
#### RULESET STAGE ####
# Make sure the rulesets don't throw unexpected errors or warnings.
# This check needs to be run against a high PHP version to prevent triggering the syntax error check.
# It also needs to be run against all PHPCS versions WPCS is tested against.
- stage: rulesets
php: 7.4
env: PHPCS_BRANCH="dev-master"
script:
- $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress-Core
- $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress-Docs
- $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress-Extra
- $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress
# Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files.
# This is not an exhaustive test, but should give an early indication for typical fixer conflicts.
# For the first run, the exit code will be 1 (= all fixable errors fixed).
# `travis_retry` should then kick in to run the fixer again which should now return 0 (= no fixable errors found).
# All error codes for the PHPCBF: https://github.com/squizlabs/PHP_CodeSniffer/issues/1270#issuecomment-272768413
- travis_retry $(pwd)/vendor/bin/phpcbf -pq ./WordPress/Tests/ --standard=WordPress --extensions=inc --exclude=Generic.PHP.Syntax --report=summary
- stage: rulesets
php: 7.4
env: PHPCS_BRANCH="3.5.0"
script:
- $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress-Core
- $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress-Docs
- $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress-Extra
- $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress
#### QUICK TEST STAGE ####
# This is a much quicker test which only runs the unit tests and linting against the low/high
# supported PHP/PHPCS combinations.
- stage: quicktest
php: 7.4
env: PHPCS_BRANCH="dev-master" LINT=1
- php: 7.3
env: PHPCS_BRANCH="3.5.0"
- php: 5.4
dist: trusty
env: PHPCS_BRANCH="dev-master" LINT=1
- php: 5.4
dist: trusty
env: PHPCS_BRANCH="3.5.0"
#### TEST STAGE ####
# Add extra build to test against PHPCS 4.
- stage: test
php: 7.4
env: PHPCS_BRANCH="4.0.x-dev as 3.9.99"
# Builds which need a different distro.
- php: 5.5
dist: trusty
env: PHPCS_BRANCH="dev-master" LINT=1
- php: 5.5
dist: trusty
env: PHPCS_BRANCH="3.5.0"
- php: 5.4
dist: trusty
env: PHPCS_BRANCH="dev-master" LINT=1
- php: 5.4
dist: trusty
env: PHPCS_BRANCH="3.5.0"
allow_failures:
# Allow failures for unstable builds.
- php: "nightly"
- env: PHPCS_BRANCH="4.0.x-dev as 3.9.99"
before_install:
# Speed up build time by disabling Xdebug.
# https://johnblackbourn.com/reducing-travis-ci-build-times-for-wordpress-projects/
# https://twitter.com/kelunik/status/954242454676475904
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'
# On stable PHPCS versions, allow for PHP deprecation notices.
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
- |
if [[ "${TRAVIS_BUILD_STAGE_NAME^}" != "Sniff" && $PHPCS_BRANCH != "dev-master" ]]; then
echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
fi
- export XMLLINT_INDENT=" "
install:
- |
if [[ ${PHPCS_BRANCH:0:2} == "4." ]]; then
# Set Composer up to download only PHPCS from source for PHPCS 4.x.
# The source is needed to get the base testcase from PHPCS.
composer config preferred-install.squizlabs/php_codesniffer source
else
composer config preferred-install.squizlabs/php_codesniffer auto
fi
- travis_retry composer require squizlabs/php_codesniffer:"${PHPCS_BRANCH}" --no-update --no-suggest --no-scripts
- |
if [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then
# PHPUnit 7.x does not allow for installation on PHP 8, so ignore platform
# requirements to get PHPUnit 7.x to install on nightly.
travis_retry composer install --ignore-platform-reqs --no-suggest
else
# Do a normal dev install in all other cases.
travis_retry composer install --no-suggest
fi
script:
# Lint the PHP files against parse errors.
- if [[ "$LINT" == "1" ]]; then composer lint; fi
# Run the unit tests.
- composer run-tests