Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature lint php #19

Merged
merged 20 commits into from
Oct 14, 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
58 changes: 58 additions & 0 deletions .github/workflows/lint-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Lint PHP

on:
workflow_call:
inputs:
PHP_MATRIX:
description: Matrix of PHP versions as a JSON formatted object.
default: '["8.0"]'
required: false
type: string
COMPOSER_ARGS:
description: Set of arguments passed to Composer.
default: '--prefer-dist'
required: false
type: string
Chrico marked this conversation as resolved.
Show resolved Hide resolved
LINT_ARGS:
description: Set of arguments passed to PHP Parallel Lint.
default: '. -e php --colors --show-deprecated'
required: false
type: string
COMPOSER_DEPS_INSTALL:
description: Whether or not to install Composer dependencies before linting.
type: boolean
default: false
required: false
secrets:
COMPOSER_AUTH_JSON:
description: Authentication for privately hosted packages and repositories as a JSON formatted object.
required: false
Chrico marked this conversation as resolved.
Show resolved Hide resolved

jobs:
lint-php:
timeout-minutes: 5
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ${{ fromJson(inputs.PHP_MATRIX) }}
env:
COMPOSER_AUTH: '${{ secrets.COMPOSER_AUTH_JSON }}'
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: cs2pr, parallel-lint
coverage: none

- name: Install Composer dependencies
if: ${{ inputs.COMPOSER_DEPS_INSTALL }}
uses: ramsey/composer-install@v1
with:
composer-options: ${{ inputs.COMPOSER_ARGS }}

- name: Run PHP lint check
run: parallel-lint ${{ inputs.LINT_ARGS }} --checkstyle | cs2pr
Chrico marked this conversation as resolved.
Show resolved Hide resolved
54 changes: 52 additions & 2 deletions docs/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,60 @@ jobs:
uses: inpsyde/reusable-workflows/.github/workflows/tests-unit-php.yml@main
secrets:
COMPOSER_AUTH_JSON: ${{ secrets.COMPOSER_AUTH_JSON }}
Chrico marked this conversation as resolved.
Show resolved Hide resolved
ENV_VARS: >-
[{"name":"EXAMPLE_USERNAME", "value":"deploybot"}, {"name":"EXAMPLE_TOKEN", "value":"${{ secrets.EXAMPLE_TOKEN }}"}]
with:
PHP_MATRIX: >-
["7.4", "8.0", "8.1"]
PHPUNIT_ARGS: '--coverage-text --debug'
ENV_VARS: >-
[{"name":"EXAMPLE_USERNAME", "value":"deploybot"}, {"name":"EXAMPLE_TOKEN", "value":"${{ secrets.EXAMPLE_TOKEN }}"}]
```

## Lint PHP

This workflow runs [PHP Parallel Lint](https://github.com/php-parallel-lint/PHP-Parallel-Lint).

**Simplest possible example:**

```yml
name: Lint PHP
on:
pull_request:
jobs:
lint-php:
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
```

### Configuration parameters

#### Inputs

| Name | Default | Description |
|-------------------------|-----------------------------------------|----------------------------------------------------------------|
| `PHP_MATRIX` | `["8.0"]` | Matrix of PHP versions as a JSON formatted object |
| `COMPOSER_ARGS` | `'--prefer-dist'` | Set of arguments passed to Composer |
| `LINT_ARGS` | `'-e php --colors --show-deprecated .'` | Set of arguments passed to PHP Parallel Lint |
| `COMPOSER_DEPS_INSTALL` | `false` | Whether or not to install Composer dependencies before linting |

#### Secrets

| Name | Description |
|----------------------|------------------------------------------------------------------------------------------|
| `COMPOSER_AUTH_JSON` | Authentication for privately hosted packages and repositories as a JSON formatted object |

Chrico marked this conversation as resolved.
Show resolved Hide resolved
**Example with configuration parameters:**

```yml
name: Lint PHP
on:
pull_request:
jobs:
lint-php:
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
secrets:
COMPOSER_AUTH_JSON: ${{ secrets.COMPOSER_AUTH_JSON }}
Chrico marked this conversation as resolved.
Show resolved Hide resolved
with:
PHP_MATRIX: >-
["7.4", "8.0", "8.1"]
LINT_ARGS: '. --exclude vendor'
COMPOSER_DEPS_INSTALL: true
```