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 2 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
65 changes: 65 additions & 0 deletions .github/workflows/lint-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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.
Chrico marked this conversation as resolved.
Show resolved Hide resolved
default: '-e php --colors --show-deprecated .'
Chrico marked this conversation as resolved.
Show resolved Hide resolved
required: false
type: string
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
ENV_VARS:
description: Additional environment variables as a JSON formatted object.
required: false

jobs:
tests-unit-php:
Chrico marked this conversation as resolved.
Show resolved Hide resolved
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: parallel-lint
Chrico marked this conversation as resolved.
Show resolved Hide resolved

- name: Set up custom environment variables
env:
ENV_VARS: ${{ secrets.ENV_VARS }}
if: ${{ env.ENV_VARS }}
uses: actions/github-script@v6
with:
script: |
JSON
.parse(process.env.ENV_VARS)
.forEach(envVar => core.exportVariable(envVar.name, envVar.value));

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

Chrico marked this conversation as resolved.
Show resolved Hide resolved
- name: Run PHP compat check
Chrico marked this conversation as resolved.
Show resolved Hide resolved
run: parallel-lint ${{ inputs.LINT_ARGS }}
Chrico marked this conversation as resolved.
Show resolved Hide resolved
53 changes: 52 additions & 1 deletion docs/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,61 @@ 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'
```

## Lint PHP

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

**Simplest possible example:**

```yml
name: Unit tests PHP
Chrico marked this conversation as resolved.
Show resolved Hide resolved
on:
pull_request:
jobs:
tests-unit-php:
Chrico marked this conversation as resolved.
Show resolved Hide resolved
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
```

### Configuration parameters

#### Inputs

| Name | Default | Description |
|-----------------|-----------------------------------------|---------------------------------------------------|
| `PHP_MATRIX` | `["7.4"]` | Matrix of PHP versions as a JSON formatted object |
| `COMPOSER_ARGS` | `'--prefer-dist'` | Set of arguments passed to Composer |
Chrico marked this conversation as resolved.
Show resolved Hide resolved
| `LINT_ARGS` | `'-e php --colors --show-deprecated .'` | Set of arguments passed to PHP Parallel Lint |

#### Secrets

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

**Example with configuration parameters:**

```yml
name: Unit tests PHP
Chrico marked this conversation as resolved.
Show resolved Hide resolved
on:
pull_request:
jobs:
tests-unit-php:
Chrico marked this conversation as resolved.
Show resolved Hide resolved
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
ENV_VARS: >-
[{"name":"EXAMPLE_USERNAME", "value":"deploybot"}, {"name":"EXAMPLE_TOKEN", "value":"${{ secrets.EXAMPLE_TOKEN }}"}]
```
with:
PHP_MATRIX: >-
["7.4", "8.0", "8.1"]
LINT_ARGS: '. --exclude vendor --checkstyle | cs2pr'
Chrico marked this conversation as resolved.
Show resolved Hide resolved
```