From c794f77eac5bdb57c967a269637d79c835ff0f71 Mon Sep 17 00:00:00 2001 From: Matthew Poulter Date: Fri, 11 Dec 2020 01:03:22 +0200 Subject: [PATCH] Convert to GitHub actions (#25) * Cleanup template files. * Move template files. * Swap to GH actions and php-cs-fixer. * Remove PHP 8 for now. --- .editorconfig | 5 +- .gitattributes | 5 +- CONTRIBUTING.md => .github/CONTRIBUTING.md | 0 .github/SECURITY.md | 3 ++ .github/workflows/php-cs-fixer.yml | 23 +++++++++ .github/workflows/run-tests.yml | 60 ++++++++++++++++++++++ .gitignore | 5 ++ .php_cs.dist | 43 ++++++++++++++++ .styleci.yml | 7 --- .travis.yml | 18 ------- README.md | 12 ++--- src/Enum.php | 6 ++- 12 files changed, 149 insertions(+), 38 deletions(-) rename CONTRIBUTING.md => .github/CONTRIBUTING.md (100%) create mode 100644 .github/SECURITY.md create mode 100644 .github/workflows/php-cs-fixer.yml create mode 100644 .github/workflows/run-tests.yml create mode 100644 .php_cs.dist delete mode 100644 .styleci.yml delete mode 100644 .travis.yml diff --git a/.editorconfig b/.editorconfig index 2a5ddba..a7c44dd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,3 @@ -; This file is for unifying the coding style for different editors and IDEs. -; More information at https://editorconfig.org - root = true [*] @@ -14,5 +11,5 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false -[*.yml] +[*.{yml,yaml}] indent_size = 2 diff --git a/.gitattributes b/.gitattributes index bb6265e..0215303 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,10 +2,13 @@ # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html # Ignore all test and documentation with "export-ignore". +/.github export-ignore /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore /phpunit.xml.dist export-ignore -/.scrutinizer.yml export-ignore /tests export-ignore /.editorconfig export-ignore +/.php_cs.dist export-ignore +/psalm.xml export-ignore +/psalm.xml.dist export-ignore diff --git a/CONTRIBUTING.md b/.github/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to .github/CONTRIBUTING.md diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000..b60f4d3 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,3 @@ +# Security Policy + +If you discover any security related issues, please email security@simplesquid.co.za instead of using the issue tracker. diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..5abe4a1 --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,23 @@ +name: Check & fix styling + +on: [ push ] + +jobs: + style: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Run PHP CS Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --config=.php_cs.dist --allow-risky=yes + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Fix styling. diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..03e0d07 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,60 @@ +name: Run tests + +on: [ push, pull_request ] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ ubuntu-latest ] + php: [ 7.4 ] + laravel: [ 7.*, 8.* ] + stability: [ prefer-lowest, prefer-stable ] + include: + - laravel: 7.* + testbench: 5.* + - laravel: 8.* + testbench: 6.* + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: nova-enum-field + ports: + - 3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.composer/cache/files + key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick + coverage: none + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-suggest + env: + COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} + + - name: Execute tests + run: vendor/bin/phpunit + env: + DB_PORT: ${{ job.services.mysql.ports[3306] }} diff --git a/.gitignore b/.gitignore index 202d4fa..dc2f668 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,11 @@ node_modules phpunit.xml .phpunit.* build +coverage + +.php_cs +.php_cs.cache +psalm.xml .idea diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..c7d380c --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,43 @@ +notPath('bootstrap/*') + ->notPath('storage/*') + ->notPath('resources/view/mail/*') + ->in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return PhpCsFixer\Config::create() + ->setRules([ + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + 'ordered_imports' => ['sortAlgorithm' => 'alpha'], + 'no_unused_imports' => true, + 'not_operator_with_successor_space' => true, + 'trailing_comma_in_multiline_array' => true, + 'phpdoc_scalar' => true, + 'unary_operator_spaces' => true, + 'binary_operator_spaces' => true, + 'blank_line_before_statement' => [ + 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], + ], + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_var_without_name' => true, + 'class_attributes_separation' => [ + 'elements' => [ + 'method', + ], + ], + 'method_argument_space' => [ + 'on_multiline' => 'ensure_fully_multiline', + 'keep_multiple_spaces_after_comma' => true, + ], + 'single_trait_insert_per_statement' => true, + ]) + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 6894532..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,7 +0,0 @@ -preset: laravel - -enabled: - - concat_with_spaces - -disabled: - - concat_without_spaces diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6f1a6d4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: php - -php: - - 7.3 - - 7.4 - -env: - matrix: - - COMPOSER_FLAGS="--prefer-lowest" - - COMPOSER_FLAGS="" - -before_script: - - travis_retry composer self-update - - composer config http-basic.nova.laravel.com ${NOVA_USERNAME} ${NOVA_PASSWORD} - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source - -script: - - vendor/bin/phpunit diff --git a/README.md b/README.md index 1ed3232..46f44d0 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ You can install this package in a Laravel app that uses [Nova](https://nova.lara composer require simplesquid/nova-enum-field ``` -## Model Setup +## Setup This package requires that you use Attribute Casting in your models. From the docs at [BenSampo/laravel-enum](https://github.com/BenSampo/laravel-enum#attribute-casting), this can be done like so: @@ -63,23 +63,23 @@ class Example extends Resource } ``` -### Testing +## Testing ``` bash composer test ``` -### Changelog +## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Contributing -Please see [CONTRIBUTING](CONTRIBUTING.md) for details. +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. -### Security +## Security Vulnerabilities -If you discover any security related issues, please email security@simplesquid.co.za instead of using the issue tracker. +Please review [our security policy](../../security/policy) on how to report security vulnerabilities. ## Credits diff --git a/src/Enum.php b/src/Enum.php index ac3a9bd..b28f5a8 100644 --- a/src/Enum.php +++ b/src/Enum.php @@ -26,11 +26,13 @@ public function attachEnum($enumClass) ->resolveUsing( function ($enum) { return $enum instanceof \BenSampo\Enum\Enum ? $enum->value : $enum; - }) + } + ) ->displayUsing( function ($enum) { return $enum instanceof \BenSampo\Enum\Enum ? $enum->description : $enum; - }); + } + ); } /**