name: 'Magento Extension PHPStan' description: 'Analyses a Magento 2 extension with PHPStan against one Magento release, with the Magento extension for PHPStan' author: 'lbajsarowicz' inputs: magento-version: description: 'Exact Magento Open Source release, such as `2.4.8-p5`.' required: true php-version: description: >- PHP minor that the job is expected to provide, such as `8.4`. The action fails when the PHP on the PATH is another version. Empty accepts whatever PHP the job has. required: false default: '' path: description: 'Directory in the workspace that holds the extension (its `composer.json`).' required: false default: '.' config: description: >- Path in the workspace to a PHPStan configuration. Empty uses `phpstan.neon`, `phpstan.neon.dist` or `phpstan.dist.neon` from the extension, and without one a default with the Magento extension for PHPStan. required: false default: '' baseline: description: 'Path in the workspace to a PHPStan baseline, loaded on top of the default configuration.' required: false default: '' level: description: 'PHPStan rule level of the default configuration.' required: false default: '1' annotations: description: >- Show findings inline on the changed lines of a pull request. Set to `false` in all but one job when the check runs in several matrix jobs. required: false default: 'true' github-token: description: 'Used only to read the list of files changed by the pull request or push.' required: false default: ${{ github.token }} composer-repositories: description: >- JSON list in the format of Composer's `repositories` section. It replaces the public Magento mirror and, when it switches packagist.org off, Packagist as the source of every dependency. The checkout stays the only source of the extension itself. required: false default: '' outputs: status: description: '`passed` or `failed`.' value: ${{ steps.run.outputs.status }} result-path: description: 'Directory holding `results.json` and the log of every check.' value: ${{ steps.run.outputs.result-path }} runs: using: 'composite' steps: - name: Detect an already prepared job id: prepared shell: bash env: MEC_WORK_DIR: ${{ runner.temp }}/magento-extension-check MEC_CACHE_ID: magento${{ inputs.magento-version }} run: node "$GITHUB_ACTION_PATH/../src/cli.js" prepare - name: Locate Composer cache if: ${{ steps.prepared.outputs.cache != 'true' }} id: composer-cache shell: bash run: echo "dir=$(composer config --global cache-files-dir)" >> "$GITHUB_OUTPUT" - name: Cache Composer downloads if: ${{ steps.prepared.outputs.cache != 'true' }} uses: actions/cache@v6 with: path: ${{ steps.composer-cache.outputs.dir }} key: magento-extension-check-${{ runner.os }}-php${{ steps.prepared.outputs.php-version }}-magento${{ inputs.magento-version }}-${{ hashFiles(format('{0}/composer.json', inputs.path)) }} restore-keys: | magento-extension-check-${{ runner.os }}-php${{ steps.prepared.outputs.php-version }}-magento${{ inputs.magento-version }}- - name: List changed files shell: bash env: MEC_TOKEN: ${{ inputs.github-token }} MEC_WORK_DIR: ${{ runner.temp }}/magento-extension-check run: node "$GITHUB_ACTION_PATH/../src/cli.js" changed-files - name: Run PHPStan id: run shell: bash env: MEC_PHP_VERSION: ${{ inputs.php-version }} MEC_MAGENTO_VERSION: ${{ inputs.magento-version }} MEC_CHECKS: install,phpstan MEC_PATH: ${{ inputs.path }} MEC_COMPOSER_REPOSITORIES: ${{ inputs.composer-repositories }} MEC_PHPCS_SEVERITY: '' MEC_PHPCS_SCOPE: changed MEC_PHPCS_CONFIG: '' MEC_PHPSTAN_LEVEL: ${{ inputs.level }} MEC_PHPSTAN_CONFIG: ${{ inputs.config }} MEC_PHPSTAN_BASELINE: ${{ inputs.baseline }} MEC_ANNOTATIONS: ${{ inputs.annotations }} MEC_WORK_DIR: ${{ runner.temp }}/magento-extension-check run: node "$GITHUB_ACTION_PATH/../src/cli.js" run