Skip to content

Automatically assign plugin-specific milestones #932

Automatically assign plugin-specific milestones

Automatically assign plugin-specific milestones #932

Workflow file for this run

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'
timeout-minutes: 20
permissions:
contents: read # Required to clone the repo.
pull-requests: read # Required by dorny/paths-filter to read PR file changes.
outputs:
changed-plugins: ${{ steps.filter-plugins.outputs.changed-plugins }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- 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@7b450fff21473bca461d4b92ce414b9d0420d706 # v4.0.2
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')
timeout-minutes: 20
permissions:
contents: read # Required to clone the repo.
outputs:
plugins: ${{ steps.set-matrix.outputs.plugins }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2
with:
php-version: '8.3'
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.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@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
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: {}
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@98a1788320d0add90df2d8183934ecccbc4e05d2 # main
with:
build-dir: ./build/${{ matrix.plugin }}
slug: ${{ matrix.plugin }}
ignore-codes: 'readme_reserved_contributors,WordPress.WP.I18n.TextDomainMismatch'