Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Move CI from Travis to GitHub #60

Merged
merged 3 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: CI

on:
- pull_request
- push

jobs:
tests:
strategy:
fail-fast: false
matrix:
include:
- phpunit-version: 4
jrmajor marked this conversation as resolved.
Show resolved Hide resolved
php-version: '5.5'
- phpunit-version: 4
php-version: '5.6'
- phpunit-version: 5
php-version: '5.6'
- phpunit-version: 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial solution was iterating over each PHP Version and each PHPUnit version, if they are compatible - run the tests.

now, we hardcoded the valid combinations, hoping we will never forget to add a valid variation.I think it's error-prone , but we also don't have so many changes in this repo, so not blocking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the script correctly, it wasn't “if they are compatible”, but “if composer require && composer update does not fail”, which is also error-prone. I don't have any good idea how to do this check reliably.

php-version: '7.0'
- phpunit-version: 5
php-version: '7.1'
- phpunit-version: 6
php-version: '7.0'
- phpunit-version: 6
php-version: '7.1'
- phpunit-version: 6
php-version: '7.2'
- phpunit-version: 7
php-version: '7.1'
- phpunit-version: 7
php-version: '7.2'
- phpunit-version: 7
php-version: '7.3'
- phpunit-version: 8
php-version: '7.2'
- phpunit-version: 8
php-version: '7.3'
- phpunit-version: 8
php-version: '7.4'
- phpunit-version: 8
php-version: '8.0'
- phpunit-version: 8
php-version: '8.1'
- phpunit-version: 9
php-version: '7.3'
- phpunit-version: 9
php-version: '7.4'
- phpunit-version: 9
php-version: '8.0'
- phpunit-version: 9
php-version: '8.1'

name: PHPUnit ${{ matrix.phpunit-version }} on PHP ${{ matrix.php-version }}

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- 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-files-dir)"

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ matrix.php-version }}-
composer-

- name: Install dependencies
run: |
composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
composer update phpunit/phpunit:^${{ matrix.phpunit-version }} sanmai/phpunit-legacy-adapter --with-all-dependencies ${{ matrix.composer-flags }}

- name: Run tests
run: vendor/bin/phpunit
55 changes: 55 additions & 0 deletions .github/workflows/sca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Static Code Analysis

on:
- pull_request
- push

jobs:
tests:
name: Static Code Analysis

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: dev-tools-${{ hashFiles('dev-tools/composer.*') }}
restore-keys: |
dev-tools-

- name: Install dev tools
run: |
composer update --optimize-autoloader --no-interaction --no-progress -d dev-tools

- name: Check - trailing spaces
run: ./dev-tools/check_trailing_spaces.sh

- name: Check - composer validate
run: composer validate --strict

- name: Check - composer normalize
run: composer normalize --dry-run --working-dir=./dev-tools composer.json

- name: Check - composer-require-checker
run: ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file .composer-require-checker.json
continue-on-error: true

- name: Check - phpmd
run: ./dev-tools/vendor/bin/phpmd src,tests text phpmd.xml

- name: Check - PhpCsFixer
run: ./dev-tools/vendor/bin/php-cs-fixer fix --diff --dry-run -v
63 changes: 0 additions & 63 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ~8.5 || ~9.4"
},
"require-dev": {
"phpspec/prophecy": "^1.10",
"phpunitgoodpractices/polyfill": "^1.1",
"sanmai/phpunit-legacy-adapter": "^6.1 || ^8.0"
},
Expand Down
40 changes: 0 additions & 40 deletions run-tests.sh

This file was deleted.

26 changes: 18 additions & 8 deletions tests/AutoReviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ final class AutoReviewTest extends TestCase
{
public function testThatThereIsProperPHPUnitInComposer()
{
$json = json_decode(file_get_contents(__DIR__.'/../composer.json'), true);
$yaml = file_get_contents(__DIR__.'/../.travis.yml', FILE_IGNORE_NEW_LINES);
preg_match_all('/run-tests\.sh (\S+)/', $yaml, $matches);

static::assertSame(
implode(' || ', $matches[1]),
$json['require']['phpunit/phpunit']
);
$requirements = file_get_contents(__DIR__.'/../composer.json');
$requirements = json_decode($requirements, true)['require']['phpunit/phpunit'];

$yml = file_get_contents(__DIR__.'/../.github/workflows/ci.yml');

preg_match_all('/phpunit-version: (\S+)/', $yml, $matches);

$testedVersions = array_unique($matches[1]);

foreach (explode(' || ', $requirements) as $version) {
preg_match('/^[\^~](\d+)\.\d+(?:\.\d+)?$/', $version, $match);

static::assertContains(
$majorVersion = $match[1],
$testedVersions,
"PHPUnit {$majorVersion} is allowed in composer.json, but not present in the test matrix at .github/workflows/ci.yml."
);
}
}
}