Browse Source

minor #5268 Add GitHub Workflows CI, including testing on PHP 8 and on macOS/Windows/Ubuntu (sanmai)

This PR was squashed before being merged into the 2.16 branch.

Discussion
----------

Add GitHub Workflows CI, including testing on PHP 8 and on macOS/Windows/Ubuntu

This PR introduces a GitHub workflow-based CI, that replicates most of the _testing_ done on Travis CI, AppVeyor, CircleCI.

 -  Like on Travis CI on Linux we build on PHP 7.1 ... 8.0. There are things done on Travis CI, like static analysis and coverage reporting, which are not replicated yet, to make this PR shorter and simpler to review.
 - On Windows we build on PHP 7.3 and 5.6, just like it is done on AppVeyor.
 - On macOS we build on PHP 7.4, just like on CircleCI.

After this PR AppVeyor and CircleCI builds will become pretty much redundant.

Fixes #5179. Extracted from #5262. Without PHPUnit 9.x yet.

Commits
-------

c41a74bea Add GitHub Workflows CI, including testing on PHP 8 and on macOS/Windows/Ubuntu
Dariusz Ruminski 4 years ago
parent
commit
844d0d18bf
4 changed files with 124 additions and 8 deletions
  1. 98 0
      .github/workflows/ci.yaml
  2. 0 6
      .travis.yml
  3. 22 2
      tests/AutoReview/TravisTest.php
  4. 4 0
      tests/Smoke/InstallViaComposerTest.php

+ 98 - 0
.github/workflows/ci.yaml

@@ -0,0 +1,98 @@
+# yamllint disable rule:line-length
+
+name: Continuous Integration
+
+on:
+  - pull_request
+  - push
+
+jobs:
+  tests:
+    strategy:
+      matrix:
+        operating-system:
+          - ubuntu-latest
+        php-version:
+          - '7.0'
+          - '7.1'
+          - '7.2'
+          - '7.3'
+          - '7.4'
+
+        include:
+          - operating-system: 'ubuntu-latest'
+            php-version: '8.0'
+            composer-flags: '--ignore-platform-req=php'
+            PHP_CS_FIXER_IGNORE_ENV: 1
+
+          - operating-system: 'ubuntu-latest'
+            php-version: '5.6'
+            PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER: 1
+            SYMFONY_DEPRECATIONS_HELPER: disabled
+
+          - operating-system: 'windows-latest'
+            php-version: '7.3'
+            FAST_LINT_TEST_CASES: 1
+
+          - operating-system: 'windows-latest'
+            php-version: '5.6'
+            SKIP_LINT_TEST_CASES: 1
+
+          - operating-system: 'macos-latest'
+            php-version: '7.4'
+            PHP_CS_FIXER_FUTURE_MODE: 1
+
+    name: PHP ${{ matrix.php-version }} CI on ${{ matrix.operating-system }} ${{ matrix.composer-flags }}
+
+    runs-on: ${{ matrix.operating-system }}
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v2
+
+      - name: Setup PHP
+        uses: shivammathur/setup-php@v2
+        with:
+          php-version: ${{ matrix.php-version }}
+
+      - name: Get Composer cache directory
+        id: composer-cache
+        run: echo "::set-output name=dir::$(composer config cache-dir)"
+
+      - name: Cache dependencies
+        uses: actions/cache@v2
+        with:
+          path: ${{ steps.composer-cache.outputs.dir }}
+          key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }}
+          restore-keys: |
+            composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-
+            composer-${{ runner.os }}-${{ matrix.php-version }}-
+            composer-${{ runner.os }}-
+            composer-
+
+      - name: Install dependencies
+        uses: nick-invision/retry@v2
+        with:
+          timeout_minutes: 5
+          max_attempts: 5
+          retry_wait_seconds: 30
+          command: |
+            composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
+
+      - name: Run tests
+        continue-on-error: ${{ matrix.php-version == '8.0' }}
+        env:
+          PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
+          FAST_LINT_TEST_CASES: ${{ matrix.FAST_LINT_TEST_CASES }}
+          SKIP_LINT_TEST_CASES: ${{ matrix.SKIP_LINT_TEST_CASES }}
+          PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER: ${{ matrix.PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER }}
+          SYMFONY_DEPRECATIONS_HELPER: ${{ matrix.SYMFONY_DEPRECATIONS_HELPER }}
+        run: |
+          vendor/bin/phpunit
+
+      - name: Run PHP CS Fixer
+        env:
+          PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
+          PHP_CS_FIXER_FUTURE_MODE: ${{ matrix.PHP_CS_FIXER_FUTURE_MODE }}
+        run: |
+          php php-cs-fixer --diff --dry-run -v fix

+ 0 - 6
.travis.yml

@@ -89,12 +89,6 @@ jobs:
                 - vendor/bin/phpunit --testsuite coverage --exclude-group covers-nothing --coverage-clover build/logs/clover.xml || travis_terminate 1
                 - php vendor/bin/php-coveralls -v
 
-        -
-            <<: *STANDARD_TEST_JOB
-            stage: Test
-            php: nightly
-            env: COMPOSER_FLAGS="--ignore-platform-reqs" PHP_CS_FIXER_IGNORE_ENV=1 SYMFONY_DEPRECATIONS_HELPER=weak
-
         -
             stage: Deployment
             php: 7.4

+ 22 - 2
tests/AutoReview/TravisTest.php

@@ -85,7 +85,10 @@ final class TravisTest extends TestCase
             new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion)),
             // if `$lastsupportedVersion` is not snapshot version, expect CI to run snapshot of next PHP version
             new TraversableContains('nightly'),
-            new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion + 0.1))
+            new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion + 0.1)),
+            // GitHub CI uses just versions, without suffix, e.g. 8.1 for 8.1snapshot as of writing
+            new TraversableContains(sprintf('%.1f', $lastSupportedVersion + 0.1)),
+            new TraversableContains(sprintf('%.1f', round($lastSupportedVersion + 1)))
         ));
     }
 
@@ -124,9 +127,13 @@ final class TravisTest extends TestCase
             return false !== strpos($job['stage'], 'Test');
         });
 
-        return array_map(function ($job) {
+        $travisPhpVersions = array_map(function ($job) {
             return (string) $job['php'];
         }, $jobs);
+
+        $gitHubPhpVersions = $this->getGitHubPhpVersions();
+
+        return array_merge($travisPhpVersions, $gitHubPhpVersions);
     }
 
     private function convertPhpVerIdToNiceVer($verId)
@@ -181,4 +188,17 @@ final class TravisTest extends TestCase
 
         return $yaml['jobs']['include'];
     }
+
+    private function getGitHubPhpVersions()
+    {
+        $yaml = Yaml::parse(file_get_contents(__DIR__.'/../../.github/workflows/ci.yaml'));
+
+        $phpVersions = $yaml['jobs']['tests']['strategy']['matrix']['php-version'];
+
+        foreach ($yaml['jobs']['tests']['strategy']['matrix']['include'] as $job) {
+            $phpVersions[] = $job['php-version'];
+        }
+
+        return $phpVersions;
+    }
 }

+ 4 - 0
tests/Smoke/InstallViaComposerTest.php

@@ -44,6 +44,10 @@ final class InstallViaComposerTest extends AbstractSmokeTest
     {
         parent::setUpBeforeClass();
 
+        if ('\\' === \DIRECTORY_SEPARATOR) {
+            static::markTestIncomplete('This test is broken on Windows');
+        }
+
         try {
             CommandExecutor::create('php --version', __DIR__)->getResult();
         } catch (\RuntimeException $e) {