Files
github-actions-magento2/.github/workflows/check-extension.yaml
T
2025-12-14 17:11:21 -05:00

191 lines
7.0 KiB
YAML

name: MageCheck Extension
on:
workflow_call:
inputs:
path:
type: string
required: false
default: "."
description: "The folder of the Magento store or extension that you are testing."
magento_repository:
type: string
required: false
default: "https://mirror.mage-os.org/"
description: "Where to install Magento from"
matrix:
type: string
required: true
description: "The matrix of Magento versions to test against"
fail-fast:
type: boolean
required: false
default: true
composer_cache_key:
type: string
required: false
default: "_mageos"
description: A key to version the composer cache. Can be incremented if you need to bust the cache.
secrets:
composer_auth:
required: false
description: "Your composer credentials (typically a stringified json object of the contents of your auth.json)"
jobs:
unit-test-extension:
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{ fromJSON(inputs.matrix) }}
fail-fast: ${{ inputs.fail-fast }}
steps:
- uses: actions/checkout@v6
- uses: graycoreio/github-actions-magento2/setup-magento@main
id: setup-magento
with:
php-version: ${{ matrix.php }}
tools: composer:v${{ matrix.composer }}
mode: extension
magento_version: ${{ matrix.magento }}
magento_repository: ${{ inputs.magento_repository }}
composer_auth: ${{ secrets.composer_auth }}
- uses: graycoreio/github-actions-magento2/cache-magento@main
with:
mode: extension
composer_cache_key: ${{ inputs.composer_cache_key }}
- name: Add extension repository
working-directory: ${{ steps.setup-magento.outputs.path }}
run: composer config repositories.local path ${{ github.workspace }}/${{ inputs.path }}
- name: Get package name
id: package
run: echo "name=$(jq -r .name ${{ github.workspace }}/${{ inputs.path }}/composer.json)" >> $GITHUB_OUTPUT
- name: Require extension
working-directory: ${{ steps.setup-magento.outputs.path }}
run: composer require "${{ steps.package.outputs.name }}:@dev" --no-install
- name: Composer install
working-directory: ${{ steps.setup-magento.outputs.path }}
run: composer install
env:
COMPOSER_AUTH: ${{ secrets.composer_auth }}
- name: Configure phpunit.xml.dist
working-directory: ${{ steps.setup-magento.outputs.path }}
run: |
## Add the testsuite
cat > /tmp/testsuite.xml << 'EOF'
<testsuite name="Extension_Unit_Tests">
<directory>../../../vendor/${{ steps.package.outputs.name }}/Test/Unit</directory>
</testsuite>
EOF
sed -i '/<testsuites>/r /tmp/testsuite.xml' dev/tests/unit/phpunit.xml.dist
## Disable allure (See https://github.com/magento/magento2/issues/36702 )
## (╯°□°)╯︵ ┻━┻
sed -i '/<extensions>/,/<\/extensions>/d' dev/tests/unit/phpunit.xml.dist
- name: Run extension unit tests
working-directory: ${{ steps.setup-magento.outputs.path }}
run: vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist --testsuite Extension_Unit_Tests
compile-extension:
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{ fromJSON(inputs.matrix) }}
fail-fast: ${{ inputs.fail-fast }}
steps:
- uses: actions/checkout@v6
- uses: graycoreio/github-actions-magento2/setup-magento@main
id: setup-magento
with:
php-version: ${{ matrix.php }}
tools: composer:v${{ matrix.composer }}
mode: extension
magento_version: ${{ matrix.magento }}
magento_repository: ${{ inputs.magento_repository }}
composer_auth: ${{ secrets.composer_auth }}
- uses: graycoreio/github-actions-magento2/cache-magento@main
with:
mode: extension
composer_cache_key: ${{ inputs.composer_cache_key }}
- name: Add extension repository
working-directory: ${{ steps.setup-magento.outputs.path }}
run: composer config repositories.local path ${{ github.workspace }}/${{ inputs.path }}
- name: Get package name
id: package
run: echo "name=$(jq -r .name ${{ github.workspace }}/${{ inputs.path }}/composer.json)" >> $GITHUB_OUTPUT
- name: Require extension
working-directory: ${{ steps.setup-magento.outputs.path }}
run: composer require "${{ steps.package.outputs.name }}:@dev" --no-install
env:
COMPOSER_AUTH: ${{ secrets.composer_auth }}
- name: Composer install
working-directory: ${{ steps.setup-magento.outputs.path }}
run: composer install
env:
COMPOSER_AUTH: ${{ secrets.composer_auth }}
- name: Enable all modules
working-directory: ${{ steps.setup-magento.outputs.path }}
run: php bin/magento module:enable --all
- name: Compile
working-directory: ${{ steps.setup-magento.outputs.path }}
run: php bin/magento setup:di:compile
coding-standard:
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{ fromJSON(inputs.matrix) }}
fail-fast: ${{ inputs.fail-fast }}
steps:
- uses: actions/checkout@v6
- name: Get Composer Version
uses: graycoreio/github-actions-magento2/get-composer-version@main
id: get-composer-version
- name: Check if allow-plugins option is available for this version of composer
uses: graycoreio/github-actions-magento2/semver-compare@main
with:
version: 2.2
compare_against: ${{ steps.get-composer-version.outputs.version }}
id: is-allow-plugins-available
- name: Enable dealerdirect/phpcodesniffer-composer-installer plugin
shell: bash
working-directory: ${{ inputs.path }}
run: composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true --global
if: steps.is-allow-plugins-available.outputs.result < 1
- name: Install Coding Standard
shell: bash
working-directory: ${{ inputs.path }}
run: composer require "magento/magento-coding-standard" "magento/php-compatibility-fork"
env:
COMPOSER_AUTH: ${{ secrets.composer_auth }}
- name: Register Coding Standard
shell: bash
working-directory: ${{ inputs.path }}
run: vendor/bin/phpcs --config-set installed_paths vendor/magento/magento-coding-standard,vendor/magento/php-compatibility-fork
- name: Coding Standard Check
shell: bash
run: |
./vendor/bin/phpcs --standard=Magento2 --ignore=*vendor/* .
working-directory: ${{ inputs.path }}