|
| 1 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow |
| 2 | + |
| 3 | +name: CI checks |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - "develop" |
| 9 | + - "main" |
| 10 | + paths-ignore: |
| 11 | + - "**.md" |
| 12 | + pull_request: |
| 13 | + paths-ignore: |
| 14 | + - "**.md" |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: "${{ github.workflow }}-${{ github.ref }}" |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + composer_validate: |
| 22 | + name: "Validate the composer.json file" |
| 23 | + runs-on: "ubuntu-latest" |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: "Setup PHP" |
| 27 | + uses: shivammathur/setup-php@v2 |
| 28 | + with: |
| 29 | + php-version: "7.4" |
| 30 | + coverage: none |
| 31 | + |
| 32 | + - name: "Checkout code" |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + # @link https://getcomposer.org/doc/03-cli.md#validate |
| 36 | + - name: "Composer validate" |
| 37 | + run: composer validate --no-check-all --strict |
| 38 | + |
| 39 | + ruleset_validate: |
| 40 | + name: "Validate the WordPress rulesets" |
| 41 | + runs-on: "ubuntu-latest" |
| 42 | + |
| 43 | + env: |
| 44 | + XMLLINT_INDENT: ' ' |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: "Setup PHP" |
| 48 | + uses: shivammathur/setup-php@v2 |
| 49 | + with: |
| 50 | + php-version: "7.4" |
| 51 | + coverage: none |
| 52 | + |
| 53 | + - name: "Install xmllint" |
| 54 | + run: | |
| 55 | + sudo apt-get update |
| 56 | + sudo apt-get install --no-install-recommends -y libxml2-utils |
| 57 | +
|
| 58 | + - name: "Checkout code" |
| 59 | + uses: actions/checkout@v4 |
| 60 | + |
| 61 | + - name: "Install Composer dependencies" |
| 62 | + uses: ramsey/composer-install@v2 |
| 63 | + with: |
| 64 | + # Bust the cache at least once a month - output format: YYYY-MM. |
| 65 | + custom-cache-suffix: $(date -u "+%Y-%m") |
| 66 | + |
| 67 | + # Show XML violations inline in the file diff. |
| 68 | + # @link https://github.com/marketplace/actions/xmllint-problem-matcher |
| 69 | + - uses: korelstar/xmllint-problem-matcher@v1 |
| 70 | + |
| 71 | + # Validate the Ruleset XML files. |
| 72 | + # @link http://xmlsoft.org/xmllint.html |
| 73 | + - name: "Validate the WordPress rulesets" |
| 74 | + run: xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml |
| 75 | + |
| 76 | + - name: "Validate the sample ruleset" |
| 77 | + run: xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd ./phpcs.xml.dist.sample |
| 78 | + |
| 79 | + # Validate the Documentation XML files. |
| 80 | + - name: "Validate documentation against schema" |
| 81 | + run: xmllint --noout --schema vendor/phpcsstandards/phpcsdevtools/DocsXsd/phpcsdocs.xsd ./Eightshift/Docs/*/*Standard.xml |
| 82 | + |
| 83 | + - name: "Check the code-style consistency of the xml files" |
| 84 | + run: | |
| 85 | + diff -B --tabsize=4 ./Eightshift/ruleset.xml <(xmllint --format "./Eightshift/ruleset.xml") |
| 86 | + diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample") |
| 87 | +
|
| 88 | +
|
| 89 | + feature_completeness: |
| 90 | + name: "Check sniff feature completeness" |
| 91 | + needs: |
| 92 | + - "composer_validate" |
| 93 | + - "ruleset_validate" |
| 94 | + runs-on: "ubuntu-latest" |
| 95 | + |
| 96 | + steps: |
| 97 | + - name: "Setup PHP" |
| 98 | + uses: shivammathur/setup-php@v2 |
| 99 | + with: |
| 100 | + php-version: "7.4" |
| 101 | + coverage: none |
| 102 | + |
| 103 | + - name: "Checkout code" |
| 104 | + uses: actions/checkout@v4 |
| 105 | + |
| 106 | + - name: "Install Composer dependencies" |
| 107 | + uses: ramsey/composer-install@v2 |
| 108 | + with: |
| 109 | + custom-cache-suffix: $(date -u "+%Y-%m") |
| 110 | + |
| 111 | + - name: "Check sniff feature completeness" |
| 112 | + run: composer check:complete |
| 113 | + |
| 114 | + lint: |
| 115 | + name: "Lint: PHP ${{ matrix.php }}" |
| 116 | + needs: |
| 117 | + - "composer_validate" |
| 118 | + - "ruleset_validate" |
| 119 | + runs-on: "ubuntu-latest" |
| 120 | + strategy: |
| 121 | + matrix: |
| 122 | + php: [ '7.4', '8.0', '8.1', '8.2' ] |
| 123 | + |
| 124 | + steps: |
| 125 | + - name: "Set up PHP" |
| 126 | + uses: shivammathur/setup-php@v2 |
| 127 | + with: |
| 128 | + php-version: ${{ matrix.php }} |
| 129 | + coverage: none |
| 130 | + tools: cs2pr |
| 131 | + |
| 132 | + - name: "Checkout code" |
| 133 | + uses: actions/checkout@v4 |
| 134 | + |
| 135 | + - name: "Composer: adjust dependencies" |
| 136 | + # Remove PHPUnit requirement to save some bandwidth. |
| 137 | + run: composer remove --dev --no-update phpunit/phpunit |
| 138 | + |
| 139 | + - name: "Install Composer dependencies" |
| 140 | + uses: ramsey/composer-install@v2 |
| 141 | + with: |
| 142 | + custom-cache-suffix: $(date -u "+%Y-%m") |
| 143 | + |
| 144 | + - name: Lint against parse errors |
| 145 | + run: composer lint:ci | cs2pr |
| 146 | + |
| 147 | + phpstan: |
| 148 | + name: "PHPStan checks" |
| 149 | + needs: |
| 150 | + - "composer_validate" |
| 151 | + - "ruleset_validate" |
| 152 | + runs-on: "ubuntu-latest" |
| 153 | + |
| 154 | + steps: |
| 155 | + - name: "Set up PHP" |
| 156 | + uses: shivammathur/setup-php@v2 |
| 157 | + with: |
| 158 | + php-version: "7.4" |
| 159 | + coverage: none |
| 160 | + tools: phpstan |
| 161 | + |
| 162 | + - name: "Checkout code" |
| 163 | + uses: actions/checkout@v4 |
| 164 | + |
| 165 | + - name: "Install Composer dependencies" |
| 166 | + uses: "ramsey/composer-install@v2" |
| 167 | + with: |
| 168 | + custom-cache-suffix: $(date -u "+%Y-%m") |
| 169 | + |
| 170 | + - name: "Run PHPStan" |
| 171 | + run: phpstan analyse |
| 172 | + |
| 173 | + tests: |
| 174 | + name: "PHP ${{ matrix.php }} with PHPCS ${{ matrix.phpcs_branch }}/WordPressCS ${{ matrix.wpcs_branch }}" |
| 175 | + needs: |
| 176 | + - "composer_validate" |
| 177 | + - "ruleset_validate" |
| 178 | + runs-on: ubuntu-latest |
| 179 | + continue-on-error: ${{ matrix.allowed_failure }} |
| 180 | + strategy: |
| 181 | + fail-fast: false |
| 182 | + matrix: |
| 183 | + php: [ '7.4', '8.0', '8.1', '8.2' ] |
| 184 | + phpcs_branch: [ 'lowest', 'dev-master' ] |
| 185 | + wpcs_branch: [ '3.0.0', 'dev-develop' ] |
| 186 | + allowed_failure: [ false ] |
| 187 | + exclude: |
| 188 | + # Only run low WordPressCS in combination with low PHPCS and high WordPressCS with high PHPCS. |
| 189 | + - phpcs_branch: '3.7.2' |
| 190 | + wpcs_branch: '3.0.0' |
| 191 | + - phpcs_branch: 'dev-master' |
| 192 | + wpcs_branch: 'dev-develop' |
| 193 | + # Allow failure on non-released version of PHP. |
| 194 | + include: |
| 195 | + - php: '8.3' |
| 196 | + phpcs_branch: 'dev-master' |
| 197 | + wpcs_branch: 'dev-develop' |
| 198 | + allowed_failure: true |
| 199 | + |
| 200 | + steps: |
| 201 | + # On stable PHPCS versions, allow for PHP deprecation notices. |
| 202 | + # Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore. |
| 203 | + - name: "Setup ini config" |
| 204 | + id: set_ini |
| 205 | + run: | |
| 206 | + if [ "${{ matrix.phpcs_branch }}" != "dev-master" ]; then |
| 207 | + echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' >> $GITHUB_OUTPUT |
| 208 | + else |
| 209 | + echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT |
| 210 | + fi |
| 211 | +
|
| 212 | + # Setup PHP versions, run checks |
| 213 | + - name: "Setup PHP" |
| 214 | + uses: shivammathur/setup-php@v2 |
| 215 | + with: |
| 216 | + php-version: ${{ matrix.php }} |
| 217 | + ini-values: ${{ steps.set_ini.outputs.PHP_INI }} |
| 218 | + coverage: none |
| 219 | + |
| 220 | + - name: "Checkout code" |
| 221 | + uses: actions/checkout@v4 |
| 222 | + |
| 223 | + - name: "Set the minimum stability requirement for develop branch of WordPressCS" |
| 224 | + if: ${{ matrix.wpcs_branch == 'dev-develop' }} |
| 225 | + run: composer config minimum-stability dev |
| 226 | + |
| 227 | + - name: "Install Composer dependencies (PHP < 8.0 )" |
| 228 | + if: ${{ matrix.php < 8.0 }} |
| 229 | + uses: ramsey/composer-install@v2 |
| 230 | + with: |
| 231 | + custom-cache-suffix: $(date -u "+%Y-%m") |
| 232 | + |
| 233 | + - name: "Install Composer dependencies (PHP >= 8.0)" |
| 234 | + if: ${{ matrix.php >= 8.0 }} |
| 235 | + uses: ramsey/composer-install@v2 |
| 236 | + with: |
| 237 | + composer-options: --ignore-platform-req=php+ |
| 238 | + custom-cache-suffix: $(date -u "+%Y-%m") |
| 239 | + |
| 240 | + - name: "Set the required PHPCS and WordPressCS versions" |
| 241 | + if: ${{ matrix.phpcs_branch != 'lowest' }} |
| 242 | + env: |
| 243 | + PHPCS_BRANCH: ${{ matrix.phpcs_branch }} |
| 244 | + WPCS_BRANCH: ${{ matrix.wpcs_branch }} |
| 245 | + run: composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} wp-coding-standards/wpcs:${WPCS_BRANCH} --no-update --no-scripts --no-interaction |
| 246 | + |
| 247 | + - name: "Set PHPCS version (lowest)" |
| 248 | + if: ${{ matrix.phpcs_version == 'lowest' }} |
| 249 | + run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction |
| 250 | + |
| 251 | + - name: "Test the Eightshift ruleset" |
| 252 | + run: composer tests:checkcs |
| 253 | + |
| 254 | + # Test for fixer conflicts by running the auto-fixers of the complete WordPressCS over the test case files. |
| 255 | + # This is not an exhaustive test, but should give an early indication for typical fixer conflicts. |
| 256 | + # If only fixable errors are found, the exit code will be 1, which can be interpreted as success. |
| 257 | + - name: "Test for fixer conflicts (fixes expected)" |
| 258 | + if: ${{ matrix.phpcs_branch == 'dev-master' }} |
| 259 | + continue-on-error: true |
| 260 | + run: | |
| 261 | + $(pwd)/vendor/bin/phpcbf -pq ./Eightshift/Tests/ --standard=Eightshift --extensions=inc --exclude=Generic.PHP.Syntax --report=summary |
| 262 | + if [ $? -eq 1 ]; then exit 0; fi |
| 263 | +
|
| 264 | + - name: "Run the unit tests - PHP 7.4 - 8.0" |
| 265 | + if: ${{ matrix.php < '8.1' }} |
| 266 | + run: composer tests:run |
| 267 | + |
| 268 | + - name: "Run the unit tests - PHP >= 8.1" |
| 269 | + if: ${{ matrix.php >= '8.1' }} |
| 270 | + run: composer tests:run -- --no-configuration --bootstrap=./Tests/bootstrap.php --dont-report-useless-tests |
0 commit comments