diff --git a/.github/workflows/_internal-coding-standard.yaml b/.github/workflows/_internal-coding-standard.yaml new file mode 100644 index 0000000..10eec01 --- /dev/null +++ b/.github/workflows/_internal-coding-standard.yaml @@ -0,0 +1,41 @@ +name: Coding Standard + +on: + push: + branches: + - main + paths: + - "_test/demo-package/**" + - ".github/workflows/_internal-coding-standard.yaml" + - "coding-standard/**" + - "!(**/*.md)" + pull_request: + branches: + - main + paths: + - "_test/demo-package/**" + - ".github/workflows/_internal-coding-standard.yaml" + - "coding-standard/**" + - "!(**/*.md)" + workflow_dispatch: + inputs: + version: + type: string + default: '*' + description: The version of the coding standard to use. + required: false + path: + type: string + default: '_test/demo-package' + description: Path to run the coding standard on. + required: true + +jobs: + coding-standard: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: './coding-standard' + with: + version: ${{ github.event.inputs.version || '*' }} + path: ${{ github.event.inputs.path || '_test/demo-package' }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 40b878d..78f2710 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +node_modules/ +.idea/ diff --git a/coding-standard/README.md b/coding-standard/README.md new file mode 100644 index 0000000..68b789d --- /dev/null +++ b/coding-standard/README.md @@ -0,0 +1,30 @@ +# Magento 2 Coding Standard Action + +A Github Action that runs the Magento Coding Standard. + +## Inputs + +See the [action.yml](./action.yml) + +## Usage + +```yml +name: Coding Standard + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + coding-standard: + runs-on: ubuntu-latest + steps: + - uses: graycoreio/github-actions-magento2/coding-standard@main + with: + version: 25 # Optional, will use the latest if omitted. + path: app/code # Optional, will be used when event is not a pull request. +``` diff --git a/coding-standard/action.yml b/coding-standard/action.yml new file mode 100644 index 0000000..72112cb --- /dev/null +++ b/coding-standard/action.yml @@ -0,0 +1,65 @@ +name: "Coding Standard" +author: "Graycore" +description: "A Github Action that runs the Magento Coding Standard." + +inputs: + php_version: + required: true + default: "8.1" + description: "PHP version used to do the coding standard check." + + 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 the coding standard will be checked. Used when the event is not a pull request." + + version: + required: false + description: "The version of the coding standard to use. If not provided, will use the latest version." + +runs: + using: composite + steps: + - name: Checkout Project + uses: actions/checkout@v3 + 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: Install Coding Standard + shell: bash + working-directory: standard + run: composer require "magento/magento-coding-standard:${{ inputs.version || '*' }}" + + - name: Register Coding Standard + shell: bash + working-directory: standard + run: vendor/bin/phpcs --config-set installed_paths ${{ github.workspace }}/standard/vendor/magento/magento-coding-standard,${{ github.workspace }}/standard/vendor/phpcompatibility/php-compatibility + + - name: Get Changed Files + shell: bash + working-directory: project + id: changed-files + run: echo "::set-output name=files::$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | xargs)" + if: github.event_name == 'pull_request' + + - name: Coding Standard Check + shell: bash + run: ../standard/vendor/bin/phpcs --standard=Magento2 ${{ github.event_name == 'pull_request' && steps.changed-files.outputs.files || inputs.path }} + working-directory: project