This repository's aim is to provide a set of open sourced GitHub actions to write better tested Magento 2 Project.
Provides an action that can be used in your GitHub workflow to execute the latest Magento Coding Standard.
To speed up the action, an additional cache component is used. This component caches Composer dependencies.
In your GitHub repository add the below as
.github/workflows/coding-standard.yml
name: Coding Standard
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
coding-standard:
name: Coding Standard
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
path-to-code: [ /app/code, /app/design ]
steps:
- uses: 121eCommerceLLC/github-actions-magento-2/coding-standard@v2
with:
path-to-code: ${{ matrix.path-to-code }}
Detailed information about common arguments is available in a Common Arguments section.
Argument | Default Value |
---|---|
php-version |
8.2 |
php-extensions |
gd, bcmath, soap, pdo_mysql, ctype, curl, dom, hash, iconv, intl, mbstring, openssl, simplexml, xsl, sockets, zip |
composer-version |
v2 - latest stable Composer 2 version. |
magento-coding-standard-version |
* - latest stable version. |
path-to-code |
/ |
phpcs-extensions |
php,phtml,graphqls/GraphQL,less/CSS,xml,js/PHP |
phpcs-ruleset |
There is no default value, the basic ruleset will be used. |
skip-cache |
false |
-
Default:
*
latest stable version.The argument is used to provide an opportunity to specify a custom version of the Magento Coding Standard. By default, the most up-to-date version will be installed.
This may be necessary in cases where an outdated version of Magento is used, and an outdated version of the standard must be used for it, since new versions may add new sniffers that are incompatible with outdated versions of Magento.
A list of available versions can be found on the releases page of the standard.
Example:
magento-coding-standard-version: v31
-
Default:
php,phtml,graphqls/GraphQL,less/CSS,xml,js/PHP
The argument is used to provide an opportunity to specify a custom list of extensions for the
--extensions
argument for thephpcs
tool.By default, the list of extensions has already been prepared according to the Magento Coding Standard.
Example:
phpcs-extensions: php,phtml,graphqls/GraphQL,less/CSS,html/PHP,xml,js/PHP
-
Default:
There is no default value, the basic ruleset will be used.
The argument is used to provide an opportunity to specify a custom ruleset. By default, a basic ruleset based on the Magento Coding Standard is used, with the exception of some annoying, but not mandatory rules.
In order to use your own ruleset, you need to create your own ruleset file according to the instructions and add it to the repository file. Then you need to provide the absolute path to this file relative to the repository starting with the slash
/
character.Example:
phpcs-ruleset: /path/to/your/ruleset.xml
Provides an action that can be used in your GitHub workflow to execute the PHP Mess Detector rules included in Magento 2.
To speed up the action, an additional cache component is used. This component caches Composer dependencies.
In your GitHub repository add the below as
.github/workflows/mess-detector.yml
name: Mess Detector
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
mess-detector:
name: Mess Detector
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
path-to-code: [ /app/code, /app/design ]
steps:
- uses: 121eCommerceLLC/github-actions-magento-2/mess-detector@v2
with:
path-to-code: ${{ matrix.path-to-code }}
Detailed information about common arguments is available in a Common Arguments section.
Argument | Default Value |
---|---|
php-version |
8.2 |
php-extensions |
gd, bcmath, soap, pdo_mysql, ctype, curl, dom, hash, iconv, intl, mbstring, openssl, simplexml, xsl, sockets, zip |
composer-version |
v2 - latest stable Composer 2 |
phpmd-version |
* - latest stable version |
path-to-code |
/ |
phpmd-ruleset |
There is no default value, the basic ruleset will be used. |
skip-cache |
false |
-
Default:
*
latest stable version.The argument is used to provide an opportunity to specify a custom version of the PHP Mess Detector. By default, the most up-to-date version will be installed.
This may be necessary in cases where an outdated version of Magento is used, and an outdated version of the detector must be used for it, since new versions may add new rules that are incompatible with outdated versions of Magento.
A list of available versions can be found on the releases page of the tool.
Example:
phpmd-version: 2.13.0
-
Default:
There is no default value, the basic ruleset will be used.
The argument is used to provide an opportunity to specify a custom ruleset. By default, a basic ruleset based on the Magento 2 is used.
In order to use your own ruleset, you need to create your own ruleset file according to the instructions and add it to the repository file. Then you need to provide the absolute path to this file relative to the repository starting with the slash
/
character.Example:
phpmd-ruleset: /path/to/your/ruleset.xml
- AllPurposeAction - Actions must process a defined list of HTTP methods.
- CookieAndSessionMisuse - Session and Cookies must be used only in HTML Presentation layer.
In order for these rules to also be included in the check, use the following action.
In your GitHub repository add the below as
.github/workflows/mess-detector.yml
name: Mess Detector
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
mess-detector:
name: Mess Detector
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
path-to-code: [ /app/code, /app/design ]
steps:
- uses: 121eCommerceLLC/github-actions-magento-2/mess-detector-full@v2
with:
path-to-code: ${{ matrix.path-to-code }}
Detailed information about common arguments is available in a Common Arguments section.
Argument | Default Value |
---|---|
php-version |
8.2 |
php-extensions |
gd, bcmath, soap, pdo_mysql, ctype, curl, dom, hash, iconv, intl, mbstring, openssl, simplexml, xsl, sockets, zip |
composer-version |
v2 - latest stable Composer 2 |
path-to-code |
/ |
phpmd-ruleset |
./dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml |
skip-cache |
false |
phpmd-version
argument is missing, since the version from thecomposer.lock
file in the project will be installed.
-
Default:
./dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml
The argument is used to provide an opportunity to specify a custom ruleset. By default, a basic ruleset based on the Magento 2 is used.
In order to use your own ruleset, you need to create your own ruleset file according to the instructions and add it to the repository file. Then you need to provide the absolute path to this file relative to the repository starting with the slash
/
character.Example:
phpmd-ruleset: /path/to/your/ruleset.xml
During the operation of this action, the composer install
command is executed, which leads to an increase in execution time. It is also possible to use a mixed workflow: check the app/code
folder with a full action, and the app/design
folder with a stripped-down one, since specific rules do not affect files in the app/design
folder.
name: Mess Detector
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
mess-detector-code:
name: Mess Detector - Code
runs-on: ubuntu-latest
steps:
- uses: 121eCommerceLLC/github-actions-magento-2/mess-detector-full@v2
with:
path-to-code: /app/code
mess-detector-design:
name: Mess Detector - Design
runs-on: ubuntu-latest
steps:
- uses: 121eCommerceLLC/github-actions-magento-2/mess-detector@v2
with:
path-to-code: /app/design
Provides an action that can be used in your GitHub workflow to execute the PHP Compatibility rules for specific PHP version.
To speed up the action, an additional cache component is used. This component caches Composer dependencies.
In your GitHub repository add the below as
.github/workflows/php-compatibility.yml
name: PHP Compatibility
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
php-compatibility:
name: PHP Compatibility
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
path-to-code: [ /app/code, /app/design ]
steps:
- uses: 121eCommerceLLC/github-actions-magento-2/php-compatibility@v2
with:
path-to-code: ${{ matrix.path-to-code }}
Detailed information about common arguments is available in a Common Arguments section.
Argument | Default Value |
---|---|
php-version |
8.2 |
php-extensions |
gd, bcmath, soap, pdo_mysql, ctype, curl, dom, hash, iconv, intl, mbstring, openssl, simplexml, xsl, sockets, zip |
composer-version |
v2 - latest stable Composer 2 |
php-compatibility-version |
10.x-dev |
path-to-code |
/ |
php-compatibility-ruleset |
There is no default value, the basic ruleset will be used. |
php-compatibility-test-versions |
8.2- |
skip-cache |
false |
-
Default:
10.x-dev
.The argument is used to provide an opportunity to specify a custom version of the PHP Compatibility. By default, the version
10.x-dev
is used, since it supports the current versions of PHP8+, but it has not been released yet.This may be necessary in cases where an outdated version of Magento is used, and an outdated version of the tool must be used for it, since new versions may add new rules that are incompatible with outdated versions of Magento.
A list of available versions can be found on the releases page of the tool.
Example:
php-compatibility-version: 9.3.5
-
Default:
There is no default value, the basic ruleset will be used.
The argument is used to provide an opportunity to specify a custom ruleset. By default, a basic ruleset based on the PHP Compatibility is used, with the exception of some annoying, but not mandatory rules.
In order to use your own ruleset, you need to create your own ruleset file according to the instructions and add it to the repository file. Then you need to provide the absolute path to this file relative to the repository starting with the slash
/
character.Example:
php-compatibility-ruleset: /path/to/your/ruleset.xml
-
Default:
8.2-
The argument is used to provide an opportunity to specify a custom test versions range.
To get the most out of the PHPCompatibility standard, you should specify a
php-compatibility-test-versions
to check against. That will enable the checks for both deprecated/removed PHP features as well as the detection of code using new PHP features.Examples:
- You can run the checks for just one specific PHP version by adding
php-compatibility-test-versions: 8.2
to step arguments. - You can also specify a range of PHP versions that your code needs to support. In this situation, compatibility issues that affect any of the PHP versions in that range will be reported:
php-compatibility-test-versions: 7.4-8.2
. - You can omit one part of the range if you want to support everything above or below a particular version, i.e. use
php-compatibility-test-versions: 7.4-
to run all the checks for PHP 7.4 and above.
- You can run the checks for just one specific PHP version by adding
Provides an action that can be used in your GitHub workflow to execute the PHPStan rules included in Magento 2.
To speed up the action, an additional cache component is used. This component caches Composer dependencies.
In your GitHub repository add the below as
.github/workflows/phpstan.yml
name: PHPStan
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
path-to-code: [ /app/code, /app/design ]
steps:
- uses: 121eCommerceLLC/github-actions-magento-2/phpstan@v2
with:
path-to-code: ${{ matrix.path-to-code }}
Detailed information about common arguments is available in a Common Arguments section.
Argument | Default Value |
---|---|
php-version |
8.2 |
php-extensions |
gd, bcmath, soap, pdo_mysql, ctype, curl, dom, hash, iconv, intl, mbstring, openssl, simplexml, xsl, sockets, zip |
composer-version |
v2 - latest stable Composer 2 |
path-to-code |
/ |
phpstan-configuration |
./dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon |
phpstan-level |
1 |
setup-di-compile |
true |
skip-cache |
false |
-
Default:
./dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon
The argument is used to provide an opportunity to specify a custom configuration. By default, a basic configuration is used.
In order to use your own configuration, you need to create your own configuration file according to the instructions and add it to the repository file. Then you need to provide the absolute path to this file relative to the repository starting with the slash
/
character.Example:
phpstan-configuration: /path/to/your/configuration.neon
-
Default:
1
The argument is used to provide an opportunity to specify a custom check level.
If you want to use PHPStan but your codebase isn’t up to speed with strong typing and PHPStan’s strict checks, you can currently choose from 10 levels (
0
is the loosest and9
is the strictest).You can also use
max
as an alias for the highest level. This will ensure that you will always use the highest level when upgrading to new versions of PHPStan.Please note that this can create a significant obstacle when upgrading to a newer version because you might have to fix a lot of code to bring the number of errors down to zero.
Example:
phpstan-level: 5
-
Default:
true
The argument is used to provide an opportunity to disable dependency compilation during check. Since part of the code is generated automatically in magento and this code is not in the repository, false positive errors may appear during static analysis due to the fact that some auto-generated classes are missing.
To disable dependency compilation, pass
false
value .Example:
setup-di-compile: false
Provides an action that can be used in your GitHub workflow to detect inline styles.
In your GitHub repository add the below as
.github/workflows/inline-styles.yml
name: Inline Styles
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
inline-styles:
name: Inline Styles
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
path-to-code: [ /app/code, /app/design ]
steps:
- uses: 121eCommerceLLC/github-actions-magento-2/inline-styles@v2
with:
path-to-code: ${{ matrix.path-to-code }}
Detailed information about common arguments is available in a Common Arguments section.
Argument | Default Value |
---|---|
path-to-code |
/ |
file-extensions |
php phtml html |
-
Default:
php phtml html
The argument is used to provide an opportunity to specify a custom list of the file extensions.
To add a file type for checking, you need to add it to the
file-extensions
parameter. For example, if we need to add.js
extension, then addjs
to the existing file types separated by space.Example:
file-extensions: php phtml html js
Provides an action that can be used in your GitHub workflow to detect unnecessary files.
In your GitHub repository add the below as
.github/workflows/unnecessary-files.yml
name: Unnecessary Files
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
unnecessary-files:
name: Unnecessary Files
runs-on: ubuntu-latest
steps:
- uses: 121eCommerceLLC/github-actions-magento-2/unnecessary-files@v2
Detailed information about common arguments is available in a Common Arguments section.
Argument | Default Value |
---|---|
path-to-code |
/ |
unnecessary-file-extensions |
7z asp back bak bz2 exe gz iso jar lz lz4 lzma lzo pass rar s7z shar sql sz tar tbz2 tgz tlz xz z zip zst DS_Store |
excluded-paths |
dev lib |
-
Default:
7z asp back bak bz2 exe gz iso jar lz lz4 lzma lzo pass rar s7z shar sql sz tar tbz2 tgz tlz xz z zip zst DS_Store
The argument is used to provide an opportunity to specify a custom list of the unnecessary file extensions.
To add a file type for checking, you need to add it to the
unnecessary-file-extensions
parameter. For example, if we need to add.secret
extension, then addsecret
to the existing file types separated by space.Example:
unnecessary-file-extensions: 7z asp back bak bz2 exe gz iso jar lz lz4 lzma lzo pass rar s7z shar sql sz tar tbz2 tgz tlz xz z zip zst DS_Store secret
-
The argument is used to provide an opportunity to specify a custom list of excluded paths.
Example:
excluded-paths: dev lib
The following arguments are common to many of the actions described above.
-
Default:
8.2
The argument is used to provide an opportunity to specify a custom PHP version.
To configure PHP, a third party action
shivammathur/setup-php
is used.In order to specify the desired version, you need to select the supported version from the list. Supported versions are from PHP 5.6 to PHP 8.3.
Example:
php-version: 7.4
-
Default:
8.2
The argument is used to provide an opportunity to specify a custom PHP extension list. At the moment, the list of required extensions for Magento is specified.
This argument has the possibility of flexible configuration, you can find out about all the possibilities in the documentation.
To add an extension, you need to add it to the
php-extensions
parameter. For example, if we need to addswoole
extension, then add, swoole
to the existing file types separated by comma.Example:
php-extensions: gd, bcmath, soap, pdo_mysql, ctype, curl, dom, hash, iconv, intl, mbstring, openssl, simplexml, xsl, sockets, zip, swoole
-
Default:
v2
The argument is used to provide an opportunity to specify a custom Composer Version.
You can set up the required
composer
version by specifying the major versionv1
orv2
, or the version inmajor.minor
orsemver
format. Additionally, for composersnapshot
andpreview
can also be specified to set up the respective releases.Example:
composer-version: 1.10.26
-
Default:
/
The argument is used to provide an opportunity to specify a custom path to code.
In our examples, almost all actions are run for the
/app/code
and/app/design
folders, but in some situations we may need to run a check on some subfolders, for example, third-party modules were installed in the/app/code
folder, and now when running checks there are errors unrelated to our code because of which we cannot make a merge of pull request, as this may be restricted in the repository settings. For such cases, we can simply specify the folder/app/code/Ecommerce121
and thereby circumvent this restriction.The same situation is with the
/app/desing
folder, if we have several themes installed, but we only want to check a certain one, then we can simply specify the path to our theme.Example:
path-to-code: /app/code/Ecommerce121
-
Default:
false
The argument is used to provide an opportunity to disable caching of composer dependencies. During the execution of actions that use
composer
to install dependencies, an additional step of caching dependencies is performed in order to reduce the execution time of the action. When launching actions, the cache is checked and previously loaded dependencies are used.To disable caching, pass
true
value.Example:
skip-cache: true
./vendor/bin/phpcs -p --colors --extensions=php,phtml,graphqls/GraphQL,less/CSS,xml,js/PHP --standard=Magento2 --exclude=Magento2.Annotation.MethodAnnotationStructure ./app/code/Ecommerce121/Module/
./vendor/bin/phpmd ./app/code/Ecommerce121/Module/ ansi ./dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml --suffixes php,phtml
./vendor/bin/phpcs -p --colors --extensions=php,phtml --standard=PHPCompatibility --runtime-set testVersion 7.4- ./app/code/Ecommerce121/Module/
To run phpstan
, the preparation commands must be executed:
composer require --dev phpstan/phpstan --no-install
composer require --dev bitexpert/phpstan-magento --no-install
composer require --dev phpstan/extension-installer --no-install
composer config --no-plugins allow-plugins.phpstan/extension-installer true
composer install
Then the following command can be executed:
./vendor/bin/phpstan analyze ./app/code/Ecommerce121/Module/ --level 1 --configuration ./dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon