Merge pull request #462 from wpengine/wpgraphql-logging-e2e-tests #475
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This does the following: | |
| # 1. Detects modified plugins that have phpcs.xml configuration | |
| # 2. Runs PHP Code Quality checks on those plugins using the custom action | |
| # 3. Creates a matrix job for each plugin that has a quality configuration | |
| # Bonus: This means you can have plugin specific badges e.g. | |
| # [](https://github.com/wpengine/hwptoolkit/actions) | |
| name: Code Quality | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'plugins/*/**.php' | |
| pull_request: | |
| paths: | |
| - 'plugins/*/**.php' | |
| jobs: | |
| detect-plugins: | |
| runs-on: ubuntu-latest | |
| name: Detect plugins has php code quality configuration | |
| outputs: | |
| plugins: ${{ steps.detect-plugin-slug.outputs.plugins }} | |
| has-plugins: ${{ steps.detect-plugin-slug.outputs.has-plugins }} | |
| php-version: ${{ steps.detect-php-version.outputs.php-version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Get changed plugin directory | |
| id: plugin | |
| run: | | |
| if [ "${{ github.event_name }}" = "push" ]; then | |
| bash .github/scripts/get_plugin_slug.sh main | |
| else | |
| bash .github/scripts/get_plugin_slug.sh \ | |
| ${{ github.event.pull_request.base.sha }} \ | |
| ${{ github.event.pull_request.head.sha }} | |
| fi | |
| - name: Detect changed plugins with quality config | |
| id: detect-plugin-slug | |
| run: | | |
| if [ -z "${{ steps.plugin.outputs.slug }}" ]; then | |
| echo "No plugin slug detected" | |
| echo "plugins=[]" >> $GITHUB_OUTPUT | |
| echo "has-plugins=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| PLUGIN="${{ steps.plugin.outputs.slug }}" | |
| if [ -f "plugins/$PLUGIN/phpcs.xml" ]; then | |
| echo "plugins=[\"$PLUGIN\"]" >> $GITHUB_OUTPUT | |
| echo "has-plugins=true" >> $GITHUB_OUTPUT | |
| echo "✅ Found phpcs.xml for plugin: $PLUGIN" | |
| else | |
| echo "plugins=[]" >> $GITHUB_OUTPUT | |
| echo "has-plugins=false" >> $GITHUB_OUTPUT | |
| echo "ℹ️ No phpcs.xml found for plugin: $PLUGIN, skipping quality checks" | |
| fi | |
| - name: Detect PHP version from composer.json | |
| id: detect-php-version | |
| run: | | |
| PLUGIN="${{ steps.plugin.outputs.slug }}" | |
| PHP_VERSION="7.4" | |
| if [ -f "plugins/$PLUGIN/composer.json" ]; then | |
| DETECTED_VERSION=$(jq -r '.require["php"] // empty' plugins/$PLUGIN/composer.json | grep -oE '[0-9]+\.[0-9]+' | head -1) | |
| if [ -n "$DETECTED_VERSION" ]; then | |
| PHP_VERSION="$DETECTED_VERSION" | |
| echo "Detected PHP version $PHP_VERSION from composer.json" | |
| else | |
| echo "No PHP version found in composer.json, using default $PHP_VERSION" | |
| fi | |
| else | |
| echo "No composer.json found, using default PHP version $PHP_VERSION" | |
| fi | |
| echo "php-version=$PHP_VERSION" >> $GITHUB_OUTPUT | |
| quality-checks: | |
| needs: detect-plugins | |
| if: needs.detect-plugins.outputs.has-plugins == 'true' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| plugin: ${{ fromJson(needs.detect-plugins.outputs.plugins) }} | |
| fail-fast: false | |
| name: ${{ matrix.plugin }} php code quality checks | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: PHP Code Quality for ${{ matrix.plugin }} | |
| uses: ./.github/actions/code-quality | |
| with: | |
| working-directory: plugins/${{ matrix.plugin }} | |
| php-version: ${{ needs.detect-plugins.outputs.php-version }} | |
| composer-options: '--no-progress --no-suggest' |