|
| 1 | +# This does the following: |
| 2 | +# 1. Detects modified plugins in the plugins/ directory |
| 3 | +# 2. Runs WordPress Plugin Check using the official action |
| 4 | +# 3. Creates a matrix job for each changed plugin |
| 5 | +# 4. Results appear as file annotations directly in PRs |
| 6 | +# Bonus: This means you can have plugin specific badges e.g. |
| 7 | +# [](https://github.com/wpengine/hwptoolkit/actions) |
| 8 | + |
| 9 | +name: WordPress Plugin Check |
| 10 | + |
| 11 | +on: |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - main |
| 15 | + paths: |
| 16 | + - 'plugins/*/**.php' |
| 17 | + pull_request: |
| 18 | + branches: |
| 19 | + - main |
| 20 | + paths: |
| 21 | + - 'plugins/*/**.php' |
| 22 | + |
| 23 | +jobs: |
| 24 | + detect-plugins: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + name: Detect plugins for Plugin Check |
| 27 | + outputs: |
| 28 | + plugins: ${{ steps.detect.outputs.plugins }} |
| 29 | + has-plugins: ${{ steps.detect.outputs.has-plugins }} |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Get changed plugin directories |
| 35 | + id: plugin |
| 36 | + run: | |
| 37 | + if [ "${{ github.event_name }}" = "push" ]; then |
| 38 | + bash .github/scripts/get_plugin_slug.sh main |
| 39 | + else |
| 40 | + bash .github/scripts/get_plugin_slug.sh \ |
| 41 | + ${{ github.event.pull_request.base.sha }} \ |
| 42 | + ${{ github.event.pull_request.head.sha }} |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Detect plugins |
| 46 | + id: detect |
| 47 | + run: | |
| 48 | + if [ -z "${{ steps.plugin.outputs.plugins }}" ] || [ "${{ steps.plugin.outputs.plugins }}" = "[]" ]; then |
| 49 | + echo "No plugins detected" |
| 50 | + echo "plugins=[]" >> $GITHUB_OUTPUT |
| 51 | + echo "has-plugins=false" >> $GITHUB_OUTPUT |
| 52 | + exit 0 |
| 53 | + fi |
| 54 | + echo "plugins=${{ steps.plugin.outputs.plugins }}" >> $GITHUB_OUTPUT |
| 55 | + echo "has-plugins=${{ steps.plugin.outputs.has-plugins }}" >> $GITHUB_OUTPUT |
| 56 | +
|
| 57 | + plugin-check: |
| 58 | + needs: detect-plugins |
| 59 | + if: needs.detect-plugins.outputs.has-plugins == 'true' |
| 60 | + runs-on: ubuntu-latest |
| 61 | + strategy: |
| 62 | + matrix: |
| 63 | + plugin: ${{ fromJson(needs.detect-plugins.outputs.plugins) }} |
| 64 | + fail-fast: false |
| 65 | + name: ${{ matrix.plugin }} Plugin Check |
| 66 | + steps: |
| 67 | + - name: Checkout |
| 68 | + uses: actions/checkout@v4 |
| 69 | + |
| 70 | + - name: Run Plugin Check |
| 71 | + uses: wordpress/plugin-check-action@v1 |
| 72 | + with: |
| 73 | + build-dir: plugins/${{ matrix.plugin }} |
| 74 | + exclude-directories: | |
| 75 | + .git |
| 76 | + vendor |
| 77 | + node_modules |
| 78 | + tests |
0 commit comments