Skip to content

Commit 8f78ff2

Browse files
author
Greg Bowler
committed
initial commit
0 parents  commit 8f78ff2

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<img src="http://159.65.210.101/php-actions.png" align="right" alt="PHP Actions for Github" />
2+
3+
Run PHP Mess Detector tests in Github Actions.
4+
==============================================
5+
6+
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:
7+
8+
+ Possible bugs
9+
+ Suboptimal code
10+
+ Overcomplicated expressions
11+
+ Unused parameters, methods, properties
12+
13+
Usage
14+
-----
15+
16+
// TODO

action.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: PHPMD (php-actions)
2+
description: Run your PHP Mess Detector tests in your Github Actions.
3+
4+
inputs:
5+
version:
6+
description: What version of PHPMD to use
7+
default: latest
8+
required: false
9+
10+
php_version:
11+
description: What version of PHP to use
12+
default: latest
13+
required: false
14+
15+
vendored_phpmd_path:
16+
description: Path to a vendored phpmd binary
17+
required: false
18+
19+
path:
20+
description: A php source code filename or directory. Can be a comma-separated string
21+
required: true
22+
23+
ruleset:
24+
description: A ruleset filename or a comma-separated string of rulesetfilenames
25+
required: true
26+
27+
output:
28+
description: A report format
29+
default: text
30+
required: false
31+
32+
minimumpriority:
33+
description: rule priority threshold; rules with lower priority than this will not be used
34+
required: false
35+
36+
reportfile:
37+
description: send report output to a file; default to STDOUT
38+
required: false
39+
40+
suffixes:
41+
description: comma-separated string of valid source code filename extensions, e.g. php,phtml
42+
required: false
43+
44+
exclude:
45+
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/*
46+
required: false
47+
48+
strict:
49+
description: also report those nodes with a @SuppressWarnings annotation
50+
required: false
51+
52+
args:
53+
description: Extra arguments to pass to the phpmd binary
54+
required: false
55+
56+
runs:
57+
using: "composite"
58+
steps:
59+
- env:
60+
ACTION_TOKEN: ${{ github.token }}
61+
ACTION_VERSION: ${{ inputs.version }}
62+
ACTION_PHP_VERSION: ${{ inputs.php_version }}
63+
ACTION_PHPMD_PATH: ${{ inputs.vendored_phpmd_path }}
64+
ACTION_PATH: ${{ inputs.path }}
65+
ACTION_RULESET: ${{ inputs.ruleset }}
66+
ACTION_OUTPUT: ${{ inputs.output }}
67+
ACTION_MINIMUMPRIORITY: ${{ inputs.minimumpriority }}
68+
ACTION_REPORTFILE: ${{ inputs.reportfile }}
69+
ACTION_SUFFIXES: ${{ inputs.suffixes }}
70+
ACTION_EXCLUDE: ${{ inputs.exclude }}
71+
ACTION_STRICT: ${{ inputs.strict }}
72+
ACTION_ARGS: ${{ inputs.args }}
73+
74+
id: phpmd_run
75+
run: |
76+
set -e
77+
bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/cee5b9fa9fbc4c888e7a62bbb7b8eade18e3c56b/php-build.bash) phpmd
78+
${{ github.action_path }}/phpmd-action.bash
79+
shell: bash
80+
81+
branding:
82+
icon: 'check-square'
83+
color: 'purple'

phpmd-action.bash

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
set -e
3+
github_action_path=$(dirname "$0")
4+
docker_tag=$(cat ./docker_tag)
5+
6+
if [ -z "$ACTION_PHPMD_PATH" ]
7+
then
8+
phar_url="https://www.getrelease.download/phpmd/phpmd/$ACTION_VERSION/phar"
9+
phar_path="${github_action_path}/phpmd.phar"
10+
curl --silent -H "User-agent: cURL (https://github.com/php-actions)" -L "$phar_url" > "$phar_path"
11+
else
12+
phar_path="${GITHUB_WORKSPACE}/$ACTION_PHPMD_PATH"
13+
fi
14+
15+
chmod +x $phar_path
16+
command_string=("phpmd")
17+
18+
if [ -n "$ACTION_PATH" ]
19+
then
20+
command_string+=("$ACTION_PATH")
21+
fi
22+
23+
if [ -n "$ACTION_OUTPUT" ]
24+
then
25+
command_string+=("$ACTION_OUTPUT")
26+
fi
27+
28+
if [ -n "$ACTION_RULESET" ]
29+
then
30+
command_string+=("$ACTION_RULESET")
31+
fi
32+
33+
if [ -n "$ACTION_MINIMUMPRIORITY" ]
34+
then
35+
command_string+=(--minimumpriority "$ACTION_MINIMUMPRIORITY")
36+
fi
37+
38+
if [ -n "$ACTION_REPORTFILE" ]
39+
then
40+
command_string+=(--reportfile "$ACTION_REPORTFILE")
41+
fi
42+
43+
if [ -n "$ACTION_SUFFIXES" ]
44+
then
45+
command_string+=(--suffixes "$ACTION_SUFFIXES")
46+
fi
47+
48+
if [ -n "$ACTION_EXCLUDE" ]
49+
then
50+
command_string+=(--exclude "$ACTION_EXCLUDE")
51+
fi
52+
53+
if [ -n "$ACTION_STRICT" ]
54+
then
55+
command_string+=(--strict)
56+
fi
57+
58+
if [ -n "$ACTION_ARGS" ]
59+
then
60+
command_string+=($ACTION_ARGS)
61+
fi
62+
63+
echo "Command: ${command_string[@]}" >> output.log 2>&1
64+
65+
docker run --rm \
66+
--volume "${phar_path}":/usr/local/bin/phpmd \
67+
--volume "${GITHUB_WORKSPACE}":/app \
68+
--workdir /app \
69+
--network host \
70+
--env-file <( env| cut -f1 -d= ) \
71+
${docker_tag} "${command_string[@]}"

0 commit comments

Comments
 (0)