diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 00000000..272a352a --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,123 @@ +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions + +name: "Continuous Integration" + +on: + - "pull_request" + - "push" + +jobs: + continuous-integratio: + name: "Continuous Integration" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.2" + - "7.3" + + dependencies: + - "highest" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2.0.0" + + - name: "Install PHP with extensions" + uses: "shivammathur/setup-php@1.7.4" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v1.0.3" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" + + - name: "Install dependencies with composer in generator/ directory" + run: "composer install --no-interaction" + working-directory: "generator" + + - name: "Install dependencies with composer in root directory" + run: "composer install --no-interaction" + + - name: "Cache PHP documentation checked out with svn" + uses: "actions/cache@v1.0.3" + with: + path: "generator/doc/doc-en" + key: "php-documentation" + + - name: "Check out PHP documentation with svn" + run: | + if [ ! -d "doc-en/en" ]; then + svn co https://svn.php.net/repository/phpdoc/modules/doc-en doc-en + else + cd doc-en + + svn update + + if [ $? -ne 0 ]; + then + cd .. + + rm -rf doc-en + + svn co https://svn.php.net/repository/phpdoc/modules/doc-en doc-en + fi + fi + working-directory: "generator/doc" + + - name: "Run tests with phpunit/phpunit in generator/ directory" + run: "vendor/bin/phpunit" + working-directory: "generator" + + - name: "Run coding standard checks with squizlabs/php_codesniffer in generator/ directory" + run: "composer cs-check" + working-directory: "generator" + + - name: "Run static code analysis with phpstan/phpstan in generator/ directory" + run: "composer phpstan" + working-directory: "generator" + + - name: "Dump autoloader with composer in root directory" + run: "composer dump-autoload" + + - name: "Run coding standard checks with squizlabs/php_codesniffer in root directory" + run: "composer cs-check" + + - name: "Run static code analysis with phpstan/phpstan in root directory" + run: "composer phpstan" + + - name: "Regenerate files" + run: "./safe.php generate" + working-directory: "generator" + + - name: "Check if regenerated files are different" + run: | + if output=$(git status --porcelain) && [ -z "$output" ]; then + # all is good + echo "Generated files are the same as committed file: OK" + else + # Uncommitted changes + echo "Generated files are different from commited files. Please run './safe.php generate' command and commit the results." + echo "Detected changes:" + git status + git diff + echo "Generated files are different from commited files. Please run './safe.php generate' command and commit the results." + exit 1; + fi + + - name: "Check if refactoring can be done with rector/rector:~0.5.0" + run: "composer install && composer rector && composer test" + working-directory: "generator/tests/rector/0.5" + + - name: "Check if refactoring can be done with rector/rector:~0.6.0" + run: "composer install && composer rector && composer test" + working-directory: "generator/tests/rector/0.6" + + - name: "Upload test coverage to coveralls" + run: "vendor/bin/php-coveralls -v --root_dir=./generator" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8adae7af..00000000 --- a/.travis.yml +++ /dev/null @@ -1,68 +0,0 @@ -language: php -matrix: - fast_finish: true # Don't wait for the allowed failures to build. - include: - - php: 7.3 - env: PREFER_LOWEST="" - - php: 7.2 - env: PREFER_LOWEST="" - allow_failures: - # PHP 7.4 testing is allowed to fail because the container isn't ready yet - - php: 7.4 - env: PREFER_LOWEST="" - -cache: - directories: - - generator/doc/doc-en - - vendor - - generator/vendor - - $HOME/.composer - -before_script: -- cd generator && composer install --no-interaction && cd .. -- | - if [ ! -d "generator/doc/doc-en/en" ]; then - cd generator/doc - svn co https://svn.php.net/repository/phpdoc/modules/doc-en doc-en - cd ../.. - else - cd generator/doc/doc-en - svn update - if [ $? -ne 0 ]; - then - cd .. - rm -rf doc-en - svn co https://svn.php.net/repository/phpdoc/modules/doc-en doc-en - cd doc-en - fi - cd ../../.. - fi -- composer update - -script: -- cd generator && ./vendor/bin/phpunit && cd .. -- cd generator && composer cs-check && cd .. -- cd generator && composer phpstan && cd .. -- composer dump-autoload -- composer cs-check -- composer phpstan -# Now, let's regenerate all files and see if we obtain the same set of files as the ones commited: -- cd generator && ./safe.php generate && cd .. -- | - if output=$(git status --porcelain) && [ -z "$output" ]; then - # all is good - echo "Generated files are the same as committed file: OK" - else - # Uncommitted changes - echo "Generated files are different from commited files. Please run './safe.php generate' command and commit the results." - echo "Detected changes:" - git status - git diff - echo "Generated files are different from commited files. Please run './safe.php generate' command and commit the results." - exit 1; - fi -- cd generator/tests/rector/0.5 && composer install && composer rector && composer test && cd ../../../.. -- cd generator/tests/rector/0.6 && composer install && composer rector && composer test && cd ../../../.. - -after_script: -- cd generator && travis_retry php vendor/bin/php-coveralls -v --root_dir="./generator" diff --git a/README.md b/README.md index e67574e8..c229f68c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Total Downloads](https://poser.pugx.org/thecodingmachine/safe/downloads.svg)](https://packagist.org/packages/thecodingmachine/safe) [![Latest Unstable Version](https://poser.pugx.org/thecodingmachine/safe/v/unstable.svg)](https://packagist.org/packages/thecodingmachine/safe) [![License](https://poser.pugx.org/thecodingmachine/safe/license.svg)](https://packagist.org/packages/thecodingmachine/safe) -[![Build Status](https://travis-ci.org/thecodingmachine/safe.svg?branch=master)](https://travis-ci.org/thecodingmachine/safe) +[![Continuous Integration](https://github.com/thecodingmachine/safe/workflows/Continuous%20Integration/badge.svg)](https://github.com/thecodingmachine/safe/actions) [![Coverage Status](https://coveralls.io/repos/thecodingmachine/safe/badge.svg?branch=master&service=github)](https://coveralls.io/github/thecodingmachine/safe?branch=master) Safe PHP @@ -59,7 +59,7 @@ $content = file_get_contents('foobar.json'); $foobar = json_decode($content); ``` -All PHP functions that can return `false` on error are part of Safe. +All PHP functions that can return `false` on error are part of Safe. In addition, Safe also provide 2 'Safe' classes: `Safe\DateTime` and `Safe\DateTimeImmutable` whose methods will throw exceptions instead of returning false. ## PHPStan integration @@ -159,8 +159,8 @@ try { Safe is loading 1000+ functions from ~85 files on each request. Yet, the performance impact of this loading is quite low. -In case you worry, using Safe will "cost" you ~700µs on each request. The [performance section](performance/README.md) -contains more information regarding the way we tested the performance impact of Safe. +In case you worry, using Safe will "cost" you ~700µs on each request. The [performance section](performance/README.md) +contains more information regarding the way we tested the performance impact of Safe. ## Learn more