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

Fea add action router #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
# GitHub Action for PHP syntax check
# GitHub Action for PHP syntax checking

This actions runs `php -l` on all PHP files found in the current project.

## Getting Started

Using this action can be done with this template:
Use this action like:

```
steps:
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 0
- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@v1
with:
folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./customer/folder/excluded/*\""
- name: PHP syntax checker 7.3
uses: prestashop/github-action-php-lint/7.3@v1
with:
folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./customer/folder/excluded/*\""
- name: PHP syntax checker 5.6
uses: prestashop/github-action-php-lint/5.6@v1
with:
folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./customer/folder/excluded/*\""
```yaml
jobs:
php-linter:
name: PHP syntax checking
runs-on: ubuntu-latest
strategy:
matrix:
php_version: ["5.6", "7.2", "7.3"]
steps:
- name: Checkout sources
uses: actions/[email protected]

- name: PHP syntax checker ${{ matrix.php_version }}
uses: "prestashop/github-action-php-lint@master"
with:
php-version: ${{ matrix.php_version }}
folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./customer/folder/excluded/*\""
```

The action ignores the folder `vendor` at root of project by default.
Expand Down
19 changes: 19 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Prestashop PHP Linter Router'
description: 'PHP linter router'
inputs:
php-version:
description: 'Your target PHP version'
required: true
folder-to-exclude:
description: 'Folder to exclude'
required: false
default: '! -path "./vendor/*"'
runs:
using: 'composite'
steps:
- name: "Lint with php ${{ inputs.php-version }}"
shell: bash
run: |
echo "Pulled docker image: $(docker pull --quiet php:${{ inputs.php-version }})"
docker run --rm --entrypoint /bin/sh php:${{ inputs.php-version }} -c "! (find . -type f -name \"*.php\" ${{ inputs.folder-to-exclude }} -exec php -l -n {} \; | grep -v \"No syntax errors detected\")"
echo "No syntax error detected"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if a syntax error is found? will this message be displayed anyway?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, run will fail.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you're right we should try this case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git ls-files | grep -E '.*\.(php)' | xargs -n1 php -l -n | (! grep -v "No syntax errors" )

seems to provide exactly what's needed