Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 52 additions & 86 deletions .github/workflows/php-quality-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ on:
default: "2"

jobs:
# Validate configuration and detect available tools
prepare:
name: 🔍 Prepare PHP Analysis
# Install Composer dependencies with caching and detect available tools
install:
name: 📦 Install Dependencies
runs-on: ubuntu-latest
outputs:
has-composer: ${{ steps.check-files.outputs.has-composer }}
Expand All @@ -129,8 +129,10 @@ jobs:
has-integration-tests: ${{ steps.check-tests.outputs.has-integration-tests }}
has-rest-api-tests: ${{ steps.check-tests.outputs.has-rest-api-tests }}
has-graphql-tests: ${{ steps.check-tests.outputs.has-graphql-tests }}
env:
COMPOSER_AUTH: ${{ secrets.composer-auth }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Check for required files
id: check-files
Expand Down Expand Up @@ -203,19 +205,8 @@ jobs:
echo "has-graphql-tests=false" >> $GITHUB_OUTPUT
fi


# Install Composer dependencies with caching
install:
name: 📦 Install Dependencies
needs: prepare
if: needs.prepare.outputs.has-composer == 'true'
runs-on: ubuntu-latest
env:
COMPOSER_AUTH: ${{ secrets.composer-auth }}
steps:
- uses: actions/checkout@v4

- name: Setup PHP
if: steps.check-files.outputs.has-composer == 'true'
uses: shivammathur/setup-php@4cba65b8c5a7681c52ce219a59833167d4550fe0
with:
php-version: ${{ inputs.php-version }}
Expand All @@ -224,22 +215,25 @@ jobs:
tools: composer:v2

- name: Get composer cache directory
if: steps.check-files.outputs.has-composer == 'true'
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v3
if: steps.check-files.outputs.has-composer == 'true'
uses: actions/cache@v5
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Validate composer.json and composer.lock
if: ${{ inputs.skip-composer-validate != true }}
if: steps.check-files.outputs.has-composer == 'true' && inputs.skip-composer-validate != true
run: composer validate ${{ inputs.debug && '--verbose' || '' }}

- name: Install Composer Dependencies
if: steps.check-files.outputs.has-composer == 'true'
run: |
composer install \
--dev \
Expand All @@ -249,6 +243,7 @@ jobs:
${{ inputs.debug && '--verbose' || '' }}

- name: Run Magento setup if needed
if: steps.check-files.outputs.has-composer == 'true'
run: |
# Apply patches if ece-patches is available
if [ -f "vendor/bin/ece-patches" ]; then
Expand All @@ -264,6 +259,7 @@ jobs:

# Archive directories for other jobs (matching Bitbucket artifacts)
- name: Archive dependencies and generated files
if: steps.check-files.outputs.has-composer == 'true'
run: |
echo "📦 Preparing archive of dependencies and generated files..."

Expand Down Expand Up @@ -296,7 +292,8 @@ jobs:
tar -czf dependencies.tar.gz --files-from /dev/null
fi

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v6
if: steps.check-files.outputs.has-composer == 'true'
with:
name: vendor-php${{ inputs.php-version }}
path: dependencies.tar.gz
Expand All @@ -305,13 +302,13 @@ jobs:
# PHPStan static analysis
phpstan:
name: 🔍 PHPStan Analysis
needs: [prepare, install]
needs: install
if: |
inputs.skip-phpstan == false &&
needs.prepare.outputs.has-composer == 'true'
needs.install.outputs.has-composer == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@4cba65b8c5a7681c52ce219a59833167d4550fe0
Expand All @@ -321,7 +318,7 @@ jobs:
coverage: none
tools: composer:v2

- uses: actions/download-artifact@v4
- uses: actions/download-artifact@v7
with:
name: vendor-php${{ inputs.php-version }}

Expand Down Expand Up @@ -351,7 +348,7 @@ jobs:
fi

- name: Cache PHPStan results
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: /tmp/phpstan
key: phpstan-php${{ inputs.php-version }}-${{ inputs.phpstan-level }}-${{ hashFiles('**/*.php') }}
Expand Down Expand Up @@ -379,7 +376,7 @@ jobs:
cmd="php -d memory_limit=${{ inputs.memory-limit }} $phpstan_cmd analyse"

# Use existing config or set defaults
if [ "${{ needs.prepare.outputs.has-phpstan-config }}" = "true" ]; then
if [ "${{ needs.install.outputs.has-phpstan-config }}" = "true" ]; then
echo "✅ Using existing PHPStan configuration"
else
echo "ℹ️ Using default PHPStan configuration"
Expand Down Expand Up @@ -414,13 +411,13 @@ jobs:
# PHP CodeSniffer style checks
phpcs:
name: 🎨 Code Style Check
needs: [prepare, install]
needs: install
if: |
inputs.skip-phpcs == false &&
needs.prepare.outputs.has-composer == 'true'
needs.install.outputs.has-composer == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@4cba65b8c5a7681c52ce219a59833167d4550fe0
Expand All @@ -430,7 +427,7 @@ jobs:
coverage: none
tools: composer:v2

- uses: actions/download-artifact@v4
- uses: actions/download-artifact@v7
with:
name: vendor-php${{ inputs.php-version }}

Expand Down Expand Up @@ -467,7 +464,7 @@ jobs:
if composer run-script --list | grep -q "check-style"; then
echo "✅ Using composer check-style script"
composer run-script check-style
elif [ "${{ needs.prepare.outputs.has-phpcs-config }}" = "true" ]; then
elif [ "${{ needs.install.outputs.has-phpcs-config }}" = "true" ]; then
echo "✅ Using existing PHPCS configuration"
if [ -f "vendor/bin/phpcs" ]; then
phpcs_cmd="vendor/bin/phpcs"
Expand Down Expand Up @@ -521,14 +518,14 @@ jobs:
# PHPUnit testing with coverage
test:
name: 🧪 Unit Tests
needs: [prepare, install]
needs: install
if: |
inputs.skip-tests == false &&
needs.prepare.outputs.has-composer == 'true' &&
needs.prepare.outputs.has-unit-tests == 'true'
needs.install.outputs.has-composer == 'true' &&
needs.install.outputs.has-unit-tests == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Setup PHP with Xdebug
uses: shivammathur/setup-php@4cba65b8c5a7681c52ce219a59833167d4550fe0
Expand All @@ -538,7 +535,7 @@ jobs:
coverage: xdebug
tools: composer:v2

- uses: actions/download-artifact@v4
- uses: actions/download-artifact@v7
with:
name: vendor-php${{ inputs.php-version }}

Expand Down Expand Up @@ -625,15 +622,15 @@ jobs:
fi

- name: Upload coverage reports
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
if: always()
with:
name: coverage-php${{ inputs.php-version }}
path: coverage.xml
retention-days: 7

- name: Upload test results
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
if: always()
with:
name: integration-test-results-php${{ inputs.php-version }}
Expand All @@ -643,11 +640,11 @@ jobs:
# Integration Tests
integration-tests:
name: 🔗 Integration Tests
needs: [prepare, install]
needs: install
if: |
inputs.skip-integration-tests == false &&
needs.prepare.outputs.has-composer == 'true' &&
needs.prepare.outputs.has-integration-tests == 'true'
needs.install.outputs.has-composer == 'true' &&
needs.install.outputs.has-integration-tests == 'true'
runs-on: ubuntu-latest
services:
mariadb:
Expand Down Expand Up @@ -682,7 +679,7 @@ jobs:
options: --health-cmd="rabbitmq-diagnostics -q ping" --health-interval=10s --health-timeout=5s --health-retries=5

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@4cba65b8c5a7681c52ce219a59833167d4550fe0
Expand All @@ -692,7 +689,7 @@ jobs:
coverage: none
tools: composer:v2

- uses: actions/download-artifact@v4
- uses: actions/download-artifact@v7
with:
name: vendor-php${{ inputs.php-version }}

Expand Down Expand Up @@ -743,7 +740,7 @@ jobs:
fi

- name: Upload test results
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
if: always()
with:
name: integration-test-results-php${{ inputs.php-version }}
Expand All @@ -753,11 +750,11 @@ jobs:
# REST API Functional Tests
rest-api-tests:
name: 🔌 REST API Tests
needs: [prepare, install]
needs: install
if: |
inputs.skip-rest-api-tests == false &&
needs.prepare.outputs.has-composer == 'true' &&
needs.prepare.outputs.has-rest-api-tests == 'true'
needs.install.outputs.has-composer == 'true' &&
needs.install.outputs.has-rest-api-tests == 'true'
runs-on: ubuntu-latest
services:
mariadb:
Expand Down Expand Up @@ -792,7 +789,7 @@ jobs:
options: --health-cmd="rabbitmq-diagnostics -q ping" --health-interval=10s --health-timeout=5s --health-retries=5

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@4cba65b8c5a7681c52ce219a59833167d4550fe0
Expand All @@ -802,7 +799,7 @@ jobs:
coverage: none
tools: composer:v2

- uses: actions/download-artifact@v4
- uses: actions/download-artifact@v7
with:
name: vendor-php${{ inputs.php-version }}

Expand Down Expand Up @@ -874,7 +871,7 @@ jobs:
fi

- name: Upload test results
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
if: always()
with:
name: rest-api-test-results-php${{ inputs.php-version }}
Expand All @@ -884,11 +881,11 @@ jobs:
# GraphQL API Functional Tests
graphql-tests:
name: 📊 GraphQL API Tests
needs: [prepare, install]
needs: install
if: |
inputs.skip-graphql-tests == false &&
needs.prepare.outputs.has-composer == 'true' &&
needs.prepare.outputs.has-graphql-tests == 'true'
needs.install.outputs.has-composer == 'true' &&
needs.install.outputs.has-graphql-tests == 'true'
runs-on: ubuntu-latest
services:
mariadb:
Expand Down Expand Up @@ -923,7 +920,7 @@ jobs:
options: --health-cmd="rabbitmq-diagnostics -q ping" --health-interval=10s --health-timeout=5s --health-retries=5

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@4cba65b8c5a7681c52ce219a59833167d4550fe0
Expand All @@ -933,7 +930,7 @@ jobs:
coverage: none
tools: composer:v2

- uses: actions/download-artifact@v4
- uses: actions/download-artifact@v7
with:
name: vendor-php${{ inputs.php-version }}

Expand Down Expand Up @@ -1005,40 +1002,9 @@ jobs:
fi

- name: Upload test results
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
if: always()
with:
name: graphql-test-results-php${{ inputs.php-version }}
path: test-results/
retention-days: 7


# Cleanup artifacts
cleanup:
name: 🧹 Cleanup
runs-on: ubuntu-latest
needs: [install, phpstan, phpcs, test, integration-tests, rest-api-tests, graphql-tests]
if: always()
permissions:
actions: write
steps:
- name: Delete temporary artifacts
uses: actions/github-script@v7
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: process.env.GITHUB_RUN_ID,
});

for (const artifact of artifacts.data.artifacts) {
if (artifact.name.startsWith('vendor-php')) {
await github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id
});
core.info(`🗑️ Deleted artifact '${artifact.name}'`);
}
}