Skip to content

[CI] Use GitHub matrix for PHPStan jobs #6310

[CI] Use GitHub matrix for PHPStan jobs

[CI] Use GitHub matrix for PHPStan jobs #6310

Workflow file for this run

name: Code Quality
on:
push:
paths-ignore:
- 'src/*/doc/**'
- 'src/**/*.md'
pull_request:
paths-ignore:
- 'src/*/doc/**'
- 'src/**/*.md'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
phpstan-matrix:
name: PHPStan / Matrix
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.set-matrix.outputs.packages }}
bridges: ${{ steps.set-matrix.outputs.bridges }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set matrix
id: set-matrix
run: |
# Helper function to convert "ai-bundle" to "AI Bundle"
to_title() {
echo "$1" | sed 's/-/ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)}1'
}
# Packages (components and bundles)
PACKAGES="[]"
for pkg in $(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*" -not -path "*/Bridge/*" -printf '%h\n' | sed 's|^src/||' | grep -Ev "examples" | sort); do
if [[ "$pkg" == *-bundle ]]; then
type="Bundle"
else
type="Component"
fi
name=$(to_title "$pkg" | sed 's/ Bundle$//')
PACKAGES=$(echo "$PACKAGES" | jq -c --arg path "$pkg" --arg type "$type" --arg name "$name" '. + [{path: $path, type: $type, name: $name}]')
done
echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
# Bridges (store and tool)
STORE_BRIDGES=$(find src/store/src/Bridge/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort \
| jq -R -s -c 'split("\n") | map(select(length > 0)) | map({component: "store", type: "Store", bridge: .})')
TOOL_BRIDGES=$(find src/agent/src/Bridge/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort \
| jq -R -s -c 'split("\n") | map(select(length > 0)) | map({component: "agent", type: "Tool", bridge: .})')
BRIDGES=$(jq -n -c --argjson store "$STORE_BRIDGES" --argjson tool "$TOOL_BRIDGES" '$store + $tool')
echo "bridges=$BRIDGES" >> $GITHUB_OUTPUT
phpstan-demo:
name: PHPStan / Demo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
- name: Install root dependencies
uses: ramsey/composer-install@v3
- name: Build root packages
run: php .github/build-packages.php
- name: Install dependencies
uses: ramsey/composer-install@v3
with:
working-directory: demo
composer-options: --ignore-platform-req=ext-mongodb
- name: Link packages
run: cd demo && ../link
- name: Run PHPStan
run: cd demo && vendor/bin/phpstan
phpstan-examples:
name: PHPStan / Examples
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
- name: Install root dependencies
uses: ramsey/composer-install@v3
- name: Build root packages
run: php .github/build-packages.php
- name: Install dependencies
uses: ramsey/composer-install@v3
with:
working-directory: examples
composer-options: --ignore-platform-req=ext-mongodb
- name: Link packages
run: cd examples && ../link
- name: Run PHPStan
run: cd examples && vendor/bin/phpstan
phpstan-package:
name: PHPStan / ${{ matrix.package.type }} / ${{ matrix.package.name }}
needs: phpstan-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.phpstan-matrix.outputs.packages) }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
- name: Install dependencies
uses: ramsey/composer-install@v3
with:
working-directory: src/${{ matrix.package.path }}
composer-options: --ignore-platform-req=ext-mongodb
- name: Run PHPStan
run: cd src/${{ matrix.package.path }} && vendor/bin/phpstan
phpstan-bridge:
name: PHPStan / ${{ matrix.bridge.type }} / ${{ matrix.bridge.bridge }}
needs: phpstan-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
bridge: ${{ fromJson(needs.phpstan-matrix.outputs.bridges) }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
- name: Install dependencies
uses: ramsey/composer-install@v3
with:
working-directory: src/${{ matrix.bridge.component }}/src/Bridge/${{ matrix.bridge.bridge }}
composer-options: --ignore-platform-req=ext-mongodb
- name: Run PHPStan
run: cd src/${{ matrix.bridge.component }}/src/Bridge/${{ matrix.bridge.bridge }} && vendor/bin/phpstan