Skip to content

Commit

Permalink
Convert to GitHub actions (#25)
Browse files Browse the repository at this point in the history
* Cleanup template files.

* Move template files.

* Swap to GH actions and php-cs-fixer.

* Remove PHP 8 for now.
  • Loading branch information
mdpoulter authored Dec 10, 2020
1 parent 69627ec commit c794f77
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 38 deletions.
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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

[*]
Expand All @@ -14,5 +11,5 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

[*.yml]
[*.{yml,yaml}]
indent_size = 2
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
3 changes: 3 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

If you discover any security related issues, please email [email protected] instead of using the issue tracker.
23 changes: 23 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -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.
60 changes: 60 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -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] }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ node_modules
phpunit.xml
.phpunit.*
build
coverage

.php_cs
.php_cs.cache
psalm.xml

.idea

Expand Down
43 changes: 43 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->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);
7 changes: 0 additions & 7 deletions .styleci.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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 [email protected] instead of using the issue tracker.
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

## Credits

Expand Down
6 changes: 4 additions & 2 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
);
}

/**
Expand Down

0 comments on commit c794f77

Please sign in to comment.