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

👷 Adding PHPMD #163

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
32 changes: 32 additions & 0 deletions phpmd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# PHP Mess Detector for Magento

A GitHub Action that runs the Magento PHPMD (PHP Mess Detector).

## Inputs

See the [action.yml](./action.yml)

Usage:

```yaml
name: PHP Mess Detector

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
mess-detector:
runs-on: ubuntu-latest
steps:
- uses: mage-os/github-actions/phpmd-action@main
with:
php_version: '8.1' # PHP version used to execute PHPMD.
composer_version: '2' # Version of composer to use.
path: 'app/code' # Directory for PHPMD execution when event is not a pull request.
ruleset_path: 'dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml' # Path to the ruleset.xml file. Optional.
```
64 changes: 64 additions & 0 deletions phpmd/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "PHP Mess Detector"
author: "David Lambauer"
description: "A Github Action that runs the Magento PHPMD."

inputs:
php_version:
required: true
default: "8.1"
description: "PHP version used to execute PHPMD."

composer_version:
required: true
default: "2"
description: "The version of composer to use."

path:
required: true
default: 'app/code'
description: "The directory (relative to the project root) in which PHPMD will be executed. Used when the event is not a pull request."

ruleset_path:
required: false
default: 'dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml'
description: "The path to the ruleset.xml file."

runs:
using: composite
steps:
- name: Checkout Project
uses: actions/checkout@v4
with:
fetch-depth: 0
path: project

- name: Create Standard Directory
shell: bash
run: mkdir standard

- name: Set PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php_version }}
tools: composer:v${{ inputs.composer_version }}
coverage: none

- name: Get Composer Version
uses: mage-os/github-actions/get-composer-version@main
id: get-composer-version

- name: Get Changed Files
shell: bash
working-directory: project
id: changed-files
run: echo "files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | xargs)" >> $GITHUB_OUTPUT
if: github.event_name == 'pull_request'

- name: Coding Standard Check
shell: bash
run: |
../standard/vendor/bin/phpmd \
${{ github.event_name == 'pull_request' && steps.changed-files.outputs.files || inputs.path }} \
github \
${{input.ruleset_path}}
working-directory: project