-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (175 loc) · 5.98 KB
/
plugin-maintain-main.yml
File metadata and controls
201 lines (175 loc) · 5.98 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Plugin main maintenance
on:
workflow_call:
inputs:
php-version:
type: string
default: '8.3'
timeout-minutes:
type: number
default: 20
composer-install:
type: boolean
default: true
bun-install:
type: boolean
default: false
build-command:
type: string
default: ''
i18n-command:
type: string
default: ''
commit-message:
type: string
default: 'chore(i18n): update generated translation files'
commit-paths:
type: string
default: |
languages/
version-bump:
type: boolean
default: false
plugin-file:
type: string
default: ''
version-constant:
type: string
default: ''
package-file:
type: string
default: ''
pot-file:
type: string
default: ''
pot-project:
type: string
default: ''
block-json-glob:
type: string
default: ''
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
maintain:
name: Generate files
if: ${{ github.ref == 'refs/heads/main' && github.actor != 'github-actions[bot]' && ( inputs.i18n-command != '' || ( github.event_name == 'push' && inputs.version-bump ) ) }}
runs-on: ubuntu-latest
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- name: Check out repository
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
coverage: none
- name: Set up Bun
if: ${{ inputs.bun-install }}
uses: oven-sh/setup-bun@v2
- name: Set up WP CLI
run: |
curl -fsSL -o wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
- name: Install gettext
run: sudo apt-get update && sudo apt-get install -y gettext
- name: Install Composer dependencies
if: ${{ inputs.composer-install }}
run: composer install --no-interaction --prefer-dist
- name: Install Bun dependencies
if: ${{ inputs.bun-install }}
run: bun install --frozen-lockfile
- name: Determine version bump
if: ${{ github.event_name == 'push' && inputs.version-bump }}
id: version_bump
env:
BEFORE_SHA: ${{ github.event.before }}
AFTER_SHA: ${{ github.sha }}
run: |
base="$BEFORE_SHA"
after="$AFTER_SHA"
bump_type=''
if [ -z "$base" ] || [[ "$base" =~ ^0+$ ]] || ! git cat-file -e "$base^{commit}" 2>/dev/null; then
messages="$(git log --format=%B "$after")"
else
messages="$(git log --format=%B "$base..$after")"
fi
if grep -Eq '(^[a-z]+(\([^)]+\))?!:|^BREAKING CHANGE:)' <<< "$messages"; then
bump_type='major'
elif grep -Eq '^feat(\([^)]+\))?:' <<< "$messages"; then
bump_type='minor'
elif grep -Eq '^(fix|perf|refactor)(\([^)]+\))?:' <<< "$messages"; then
bump_type='patch'
fi
echo "type=$bump_type" >> "$GITHUB_OUTPUT"
- name: Bump plugin version
if: ${{ inputs.version-bump && steps.version_bump.outputs.type != '' }}
id: bump_plugin_version
uses: Automattic/wpvdb-scripts/.github/actions/bump-plugin-version@main
with:
bump-type: ${{ steps.version_bump.outputs.type }}
plugin-file: ${{ inputs.plugin-file }}
version-constant: ${{ inputs.version-constant }}
package-file: ${{ inputs.package-file }}
pot-file: ${{ inputs.pot-file }}
pot-project: ${{ inputs.pot-project }}
block-json-glob: ${{ inputs.block-json-glob }}
- name: Build assets
if: ${{ inputs.build-command != '' }}
env:
BUILD_COMMAND: ${{ inputs.build-command }}
run: eval "$BUILD_COMMAND"
- name: Generate translation files
if: ${{ inputs.i18n-command != '' }}
env:
I18N_COMMAND: ${{ inputs.i18n-command }}
run: eval "$I18N_COMMAND"
- name: Commit generated changes
env:
COMMIT_MESSAGE: ${{ inputs.commit-message }}
COMMIT_PATHS: ${{ inputs.commit-paths }}
I18N_COMMAND: ${{ inputs.i18n-command }}
VERSION_BUMP_ENABLED: ${{ inputs.version-bump }}
VERSION_BUMP_TYPE: ${{ steps.version_bump.outputs.type }}
NEW_VERSION: ${{ steps.bump_plugin_version.outputs.new-version }}
run: |
changed=false
while IFS= read -r path; do
if [ -z "$path" ]; then
continue
fi
if [ -n "$(git status --short -- "$path")" ]; then
changed=true
fi
done <<< "$COMMIT_PATHS"
if [ "$changed" != "true" ]; then
echo "No generated changes to commit."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
while IFS= read -r path; do
if [ -z "$path" ]; then
continue
fi
git add -- "$path"
done <<< "$COMMIT_PATHS"
subject="$COMMIT_MESSAGE"
if [ "$VERSION_BUMP_ENABLED" = "true" ] && [ -n "$VERSION_BUMP_TYPE" ]; then
subject="chore(release): bump plugin version to $NEW_VERSION"
if [ -n "$I18N_COMMAND" ]; then
subject="chore(release): bump to $NEW_VERSION and update generated files"
fi
fi
git commit -m "$subject"
git push origin HEAD:main || {
echo "Push rejected because main moved during this run."
exit 0
}