Browse Source

DX: extract config for special CI jobs

Dariusz Ruminski 3 years ago
parent
commit
865865067c
3 changed files with 36 additions and 4 deletions
  1. 4 4
      .github/workflows/ci.yml
  2. 26 0
      .php-cs-fixer.php-highest.php
  3. 6 0
      .php-cs-fixer.php-lowest.php

+ 4 - 4
.github/workflows/ci.yml

@@ -111,7 +111,7 @@ jobs:
 
       - name: Execute migration rules
         if: matrix.execute-migration-rules == 'yes'
-        run: php php-cs-fixer fix --rules @PHP80Migration,@PHP80Migration:risky -q
+        run: php php-cs-fixer fix --config .php-cs-fixer.php-highest.php -q
 
       - name: Disable time limit for tests when collecting coverage
         if: matrix.calculate-code-coverage == 'yes'
@@ -129,9 +129,9 @@ jobs:
           COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         run: php vendor/bin/php-coveralls --verbose
 
-      - name: Run PHP CS Fixer for PHP 7.0 types
-        if: matrix.php-version == '7.1' # we run on lowest supported version, we running it on higher would falsy expect more changes, eg `mixed` type on PHP 8
-        run: php php-cs-fixer fix --diff --dry-run -v --config .php-cs-fixer.php70types.php
+      - name: Run PHP CS Fixer for PHP 7.1 types
+        if: matrix.php-version == '7.1' # we run on lowest supported version, running it on higher would falsy expect more changes, eg `mixed` type on PHP 8
+        run: php php-cs-fixer fix --diff --dry-run -v --config .php-cs-fixer.php-lowest.php
 
       - name: Run PHP CS Fixer
         env:

+ 26 - 0
.php-cs-fixer.php-highest.php

@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * This file is part of PHP CS Fixer.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+if (PHP_VERSION_ID <= 80001 || PHP_VERSION_ID >= 80100) {
+    fwrite(STDERR, "PHP CS Fixer's config for PHP-HIGHEST can be executed only on highest supported PHP version - 8.0.*.\n");
+    fwrite(STDERR, "Running it on lower PHP version would prevent calling migration rules.\n");
+    exit(1);
+}
+
+$config = require '.php-cs-fixer.dist.php';
+
+$config->setRules([
+    '@PHP80Migration' => true,
+    '@PHP80Migration:risky' => true,
+]);
+
+return $config;

+ 6 - 0
.php-cs-fixer.php70types.php → .php-cs-fixer.php-lowest.php

@@ -10,6 +10,12 @@
  * with this source code in the file LICENSE.
  */
 
+if (PHP_VERSION_ID <= 70103 || PHP_VERSION_ID >= 70200) {
+    fwrite(STDERR, "PHP CS Fixer's config for PHP-LOWEST can be executed only on lowest supported PHP version - 7.1.*.\n");
+    fwrite(STDERR, "Running it on higher PHP version would falsy expect more changes, eg `mixed` type on PHP 8.\n");
+    exit(1);
+}
+
 $config = require '.php-cs-fixer.dist.php';
 
 $config->getFinder()->notPath([