Repository navigation
164 lines (145 loc) · 5.79 KB
/
Copy pathplugin-check.yml
File metadata and controls
164 lines (145 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- 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@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.3'
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.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@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
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@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: built-plugins
path: build
- name: Run plugin check
uses: wordpress/plugin-check-action@10857da14b6c2246d15402b3e69f777edcf8c12e # main
with:
build-dir: ./build/${{ matrix.plugin }}
slug: ${{ matrix.plugin }}
ignore-codes: 'readme_reserved_contributors,WordPress.WP.I18n.TextDomainMismatch'