Skip to content

Commit

Permalink
chore: init php lint actions
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneBour committed Nov 4, 2019
0 parents commit 216534e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM php:7.3-cli

LABEL "com.github.actions.name"="PHP Syntax checker"
LABEL "com.github.actions.description"="Run PHP Syntax checker (php -l)"
LABEL "com.github.actions.icon"="eye"
LABEL "com.github.actions.color"="gray-dark"

LABEL version="7.3"
LABEL repository="https://github.com/StephaneBour/actions-php-lint"
LABEL homepage="https://github.com/StephaneBour/actions-php-lint"
LABEL maintainer="Stéphane Bour <[email protected]>"

COPY "entrypoint.sh" "/entrypoint.sh"

RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# PHP Syntax checker (lint) action

This action controls the syntax of php files in a folder, excluding the vendor folder.

## Inputs

### `dir`

The folder to control. Default `"."`.

## Example usage

```yaml
uses: StephaneBour/[email protected]
with:
dir: './src'
```
## Change PHP Version
You can use :
```
StephaneBour/[email protected]
StephaneBour/[email protected]
StephaneBour/[email protected]
StephaneBour/[email protected]
StephaneBour/[email protected]
```
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'PHP Syntax Checker (Lint)'
description: 'php syntax control (php -l)'
inputs:
dir:
description: 'Folder to check syntax'
required: false
default: '.'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.dir }}
32 changes: 32 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh
set -e

PHP_FULL_VERSION=$(php -r 'echo phpversion();')

if [ -z "$1" ]; then
DIR_TO_SCAN="."
else
DIR_TO_SCAN="$1"
fi

echo "## Running PHP Syntax Checker (lint) on ${DIR_TO_SCAN}"
echo "PHP Version : ${PHP_FULL_VERSION}"

if [ ! -d "${DIR_TO_SCAN}" ] && [ ! -f "${DIR_TO_SCAN}" ]; then
echo "\nInvalid directory or file: ${DIR_TO_SCAN}"
echo "\n\n"

exit 2
fi

ERROR=0
for file in $(find ${DIR_TO_SCAN} -type f -name "*.php" ! -path "./vendor/*"); do
RESULTS=$(php -l ${file} || true)

if [ "${RESULTS}" != "No syntax errors detected in ${file}" ]; then
echo "\n${RESULTS}\n"
ERROR=1
fi
done

exit "${ERROR}"

0 comments on commit 216534e

Please sign in to comment.