diff --git a/phpmd/README.md b/phpmd/README.md new file mode 100644 index 0000000..537b26d --- /dev/null +++ b/phpmd/README.md @@ -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. +``` diff --git a/phpmd/action.yml b/phpmd/action.yml new file mode 100644 index 0000000..f5f399d --- /dev/null +++ b/phpmd/action.yml @@ -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