Merge pull request #2454 from WordPress/dependabot/github_actions/cra… #477
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
| name: Plugin Check | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - 'release/**' | |
| - trunk | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| - ready_for_review | |
| # Cancels all previous workflow runs for pull requests that have not completed. | |
| concurrency: | |
| # The concurrency group contains the workflow name and the branch name for pull requests | |
| # or the commit hash for any other events. | |
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} | |
| cancel-in-progress: true | |
| # Disable permissions for all available scopes by default. | |
| # Any needed permissions should be configured at the job level. | |
| permissions: {} | |
| jobs: | |
| detect-changes: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request' | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| outputs: | |
| changed-plugins: ${{ steps.filter-plugins.outputs.changed-plugins }} | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Generate filters from plugins.json | |
| id: generate-filters | |
| run: | | |
| FILTERS="" | |
| # Add filters for each plugin | |
| for plugin in $(jq -r '.plugins[]' plugins.json); do | |
| FILTERS="${FILTERS}${plugin}:\n - 'plugins/${plugin}/**'\n" | |
| done | |
| # Add filter for global files that affect all plugins | |
| FILTERS="${FILTERS}global:\n - 'plugins.json'\n - 'package.json'\n - 'package-lock.json'\n - 'composer.json'\n - 'composer.lock'\n - 'webpack.config.js'\n - '.github/workflows/plugin-check.yml'\n" | |
| printf "%b" "$FILTERS" > /tmp/filters.yml | |
| cat /tmp/filters.yml | |
| - uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1 | |
| id: filter | |
| with: | |
| filters: /tmp/filters.yml | |
| - name: Collect changed plugins | |
| id: filter-plugins | |
| env: | |
| CHANGES: ${{ steps.filter.outputs.changes }} | |
| GLOBAL_CHANGED: ${{ steps.filter.outputs.global }} | |
| run: | | |
| # If global files changed, return all plugins | |
| if [ "$GLOBAL_CHANGED" = "true" ]; then | |
| ALL_PLUGINS=$(jq -c '.plugins' plugins.json) | |
| echo "changed-plugins=$ALL_PLUGINS" >> $GITHUB_OUTPUT | |
| else | |
| # Filter out 'global' from changes and return only plugin names | |
| PLUGIN_CHANGES=$(echo "$CHANGES" | jq -c '[.[] | select(. != "global")]') | |
| echo "changed-plugins=$PLUGIN_CHANGES" >> $GITHUB_OUTPUT | |
| fi | |
| prepare-matrix: | |
| needs: [detect-changes] | |
| runs-on: ubuntu-latest | |
| # Always run this job, even if detect-changes was skipped | |
| if: always() && (needs.detect-changes.result == 'success' || needs.detect-changes.result == 'skipped') | |
| permissions: | |
| contents: read | |
| outputs: | |
| plugins: ${{ steps.set-matrix.outputs.plugins }} | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 | |
| with: | |
| php-version: '8.3' | |
| - name: Setup Node.js (.nvmrc) | |
| uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: npm | |
| - name: npm install | |
| run: npm ci | |
| - name: Determine plugins to build | |
| id: determine-plugins | |
| env: | |
| CHANGED_PLUGINS: ${{ needs.detect-changes.outputs.changed-plugins }} | |
| run: | | |
| ALL_PLUGINS=$(jq -c '.plugins' plugins.json) | |
| # For non-PR events (push to trunk/release branches), build all plugins | |
| if [ "${{ github.event_name }}" != "pull_request" ]; then | |
| echo "plugins=$ALL_PLUGINS" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # For PRs, use the changed plugins from detect-changes | |
| echo "plugins=$CHANGED_PLUGINS" >> $GITHUB_OUTPUT | |
| - name: Build plugins | |
| env: | |
| PLUGINS: ${{ steps.determine-plugins.outputs.plugins }} | |
| run: | | |
| # Build each plugin from the JSON array | |
| for plugin in $(echo "$PLUGINS" | jq -r '.[]'); do | |
| echo "Building plugin: $plugin" | |
| npm run "build:plugin:$plugin" | |
| done | |
| - name: Upload built plugins | |
| uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 | |
| with: | |
| name: built-plugins | |
| path: build/ | |
| retention-days: 1 | |
| - name: Set matrix output | |
| id: set-matrix | |
| env: | |
| PLUGINS: ${{ steps.determine-plugins.outputs.plugins }} | |
| run: | | |
| # Output the plugins list for the matrix | |
| echo "plugins=$PLUGINS" >> $GITHUB_OUTPUT | |
| plugin-check: | |
| needs: prepare-matrix | |
| # Only run if prepare-matrix succeeded and has plugins to check | |
| if: needs.prepare-matrix.result == 'success' && needs.prepare-matrix.outputs.plugins != '[]' | |
| name: Check ${{ matrix.plugin }} | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| timeout-minutes: 20 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| plugin: ${{ fromJson(needs.prepare-matrix.outputs.plugins) }} | |
| steps: | |
| - name: Download built plugins | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: built-plugins | |
| path: build | |
| - name: Run plugin check | |
| uses: wordpress/plugin-check-action@6f5a57e173c065a394b78688f75df543e4011902 # main | |
| with: | |
| build-dir: ./build/${{ matrix.plugin }} | |
| slug: ${{ matrix.plugin }} | |
| ignore-codes: 'readme_reserved_contributors,WordPress.WP.I18n.TextDomainMismatch' |