Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Feb 16, 2023
0 parents commit 8f78ff2
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<img src="http://159.65.210.101/php-actions.png" align="right" alt="PHP Actions for Github" />

Run PHP Mess Detector tests in Github Actions.
==============================================

PHP Mess Detector (PHPMD) takes a given PHP source code base and looks for several potential problems within that source. These problems can be things like:

+ Possible bugs
+ Suboptimal code
+ Overcomplicated expressions
+ Unused parameters, methods, properties

Usage
-----

// TODO
83 changes: 83 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: PHPMD (php-actions)
description: Run your PHP Mess Detector tests in your Github Actions.

inputs:
version:
description: What version of PHPMD to use
default: latest
required: false

php_version:
description: What version of PHP to use
default: latest
required: false

vendored_phpmd_path:
description: Path to a vendored phpmd binary
required: false

path:
description: A php source code filename or directory. Can be a comma-separated string
required: true

ruleset:
description: A ruleset filename or a comma-separated string of rulesetfilenames
required: true

output:
description: A report format
default: text
required: false

minimumpriority:
description: rule priority threshold; rules with lower priority than this will not be used
required: false

reportfile:
description: send report output to a file; default to STDOUT
required: false

suffixes:
description: comma-separated string of valid source code filename extensions, e.g. php,phtml
required: false

exclude:
description: comma-separated string of patterns that are used to ignore directories. Use asterisks to exclude by pattern. For example *src/foo/*.php or *src/foo/*
required: false

strict:
description: also report those nodes with a @SuppressWarnings annotation
required: false

args:
description: Extra arguments to pass to the phpmd binary
required: false

runs:
using: "composite"
steps:
- env:
ACTION_TOKEN: ${{ github.token }}
ACTION_VERSION: ${{ inputs.version }}
ACTION_PHP_VERSION: ${{ inputs.php_version }}
ACTION_PHPMD_PATH: ${{ inputs.vendored_phpmd_path }}
ACTION_PATH: ${{ inputs.path }}
ACTION_RULESET: ${{ inputs.ruleset }}
ACTION_OUTPUT: ${{ inputs.output }}
ACTION_MINIMUMPRIORITY: ${{ inputs.minimumpriority }}
ACTION_REPORTFILE: ${{ inputs.reportfile }}
ACTION_SUFFIXES: ${{ inputs.suffixes }}
ACTION_EXCLUDE: ${{ inputs.exclude }}
ACTION_STRICT: ${{ inputs.strict }}
ACTION_ARGS: ${{ inputs.args }}

id: phpmd_run
run: |
set -e
bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/cee5b9fa9fbc4c888e7a62bbb7b8eade18e3c56b/php-build.bash) phpmd
${{ github.action_path }}/phpmd-action.bash
shell: bash

branding:
icon: 'check-square'
color: 'purple'
71 changes: 71 additions & 0 deletions phpmd-action.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash
set -e
github_action_path=$(dirname "$0")
docker_tag=$(cat ./docker_tag)

if [ -z "$ACTION_PHPMD_PATH" ]
then
phar_url="https://www.getrelease.download/phpmd/phpmd/$ACTION_VERSION/phar"
phar_path="${github_action_path}/phpmd.phar"
curl --silent -H "User-agent: cURL (https://github.com/php-actions)" -L "$phar_url" > "$phar_path"
else
phar_path="${GITHUB_WORKSPACE}/$ACTION_PHPMD_PATH"
fi

chmod +x $phar_path
command_string=("phpmd")

if [ -n "$ACTION_PATH" ]
then
command_string+=("$ACTION_PATH")
fi

if [ -n "$ACTION_OUTPUT" ]
then
command_string+=("$ACTION_OUTPUT")
fi

if [ -n "$ACTION_RULESET" ]
then
command_string+=("$ACTION_RULESET")
fi

if [ -n "$ACTION_MINIMUMPRIORITY" ]
then
command_string+=(--minimumpriority "$ACTION_MINIMUMPRIORITY")
fi

if [ -n "$ACTION_REPORTFILE" ]
then
command_string+=(--reportfile "$ACTION_REPORTFILE")
fi

if [ -n "$ACTION_SUFFIXES" ]
then
command_string+=(--suffixes "$ACTION_SUFFIXES")
fi

if [ -n "$ACTION_EXCLUDE" ]
then
command_string+=(--exclude "$ACTION_EXCLUDE")
fi

if [ -n "$ACTION_STRICT" ]
then
command_string+=(--strict)
fi

if [ -n "$ACTION_ARGS" ]
then
command_string+=($ACTION_ARGS)
fi

echo "Command: ${command_string[@]}" >> output.log 2>&1

docker run --rm \
--volume "${phar_path}":/usr/local/bin/phpmd \
--volume "${GITHUB_WORKSPACE}":/app \
--workdir /app \
--network host \
--env-file <( env| cut -f1 -d= ) \
${docker_tag} "${command_string[@]}"

0 comments on commit 8f78ff2

Please sign in to comment.