diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7ab4b38 --- /dev/null +++ b/Dockerfile @@ -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 " + +COPY "entrypoint.sh" "/entrypoint.sh" + +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..8ba820e --- /dev/null +++ b/README.md @@ -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/actions-php-lint@v7.3 +with: + dir: './src' +``` + +## Change PHP Version + +You can use : +``` +StephaneBour/actions-php-lint@v7.3 +StephaneBour/actions-php-lint@v7.2 +StephaneBour/actions-php-lint@v7.1 +StephaneBour/actions-php-lint@v7.0 +StephaneBour/actions-php-lint@v5.6 +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..893485b --- /dev/null +++ b/action.yml @@ -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 }} diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..74232a6 --- /dev/null +++ b/entrypoint.sh @@ -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}"