Repository navigation
392 lines (355 loc) · 15.8 KB
/
Copy pathrelease.yml
File metadata and controls
392 lines (355 loc) · 15.8 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
name: Release
# Джерело версії — Init/module.json, а не теги. Саме його читає ядро:
# Installer пише версію в БД, і від неї залежить, які update_* спрацюють при
# оновленні. Тег і реліз — похідні: версію піднімають у PR разом із кодом, а
# після мерджу CI лише ставить тег на те, що вже у файлі. Тому CI нічого не
# пише в захищену гілку.
#
# Модель тегів:
# v<X.Y.Z> — базовий реліз. Мусить працювати на обох рушіях.
# v<X.Y.Z>-fork — збирається лише тоді, коли в репозиторії є гілка `fork`,
# тобто коли справді з'явилися форк-специфічні зміни.
#
# Рушії неможливо розрізнити за номером версії: і форк, і сток звуть себе
# 4.5.3 (Okay\Core\Config::$version). Тому кожна ціль нижче описана явно —
# своїм репозиторієм, своїм ref і своєю версією PHP.
on:
# PR у main — лише перевірки. Мердж у main — перевірки й реліз, якщо версія
# у module.json ще не має тега. workflow_dispatch лишено для ручного повтору.
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
env:
VENDOR: Sviat
MODULE: OrderManagerControl
permissions:
contents: write
jobs:
lint:
name: PHP ${{ matrix.php }} syntax
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Модулі вимагають PHP 8.5+ — версії, на якій стоять сток 4.5.3 і форк і
# на якій модуль перевіряють.
php: ['8.5']
steps:
- uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
- run: |
set -euo pipefail
# tests/ не лінтуються: в архів вони не їдуть і написані під PHP 8.
# Будь-який рядок, крім «No syntax errors», — помилка: php -l повертає 0
# і на Deprecated, а PHPStan у модулів немає.
find . -path ./.git -prune -o -path ./tests -prune -o -name '*.php' -print0 \
| xargs -0 -r -n1 -P4 php -d error_reporting=-1 -d display_errors=1 -d log_errors=0 -l 2>&1 \
| { grep -v '^No syntax errors detected in ' || true; } | tee lint.txt
test ! -s lint.txt
verify:
name: ${{ matrix.target }} (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: stock
repo: OkayCMS/OkayCMS
ref: '4.5.3'
# composer.lock стоку 4.5.3 зібраний під PHP 8.5. Тести написані під
# PHP 8.5, як і форк.
php: '8.5'
- target: fork
repo: devSviat/OkayCMS-Fork
ref: main
php: '8.5'
steps:
- name: Check out the module
uses: actions/checkout@v7
with:
path: module
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
# redis: без нього тести кеш-модуля мовчки скіпаються, решті не заважає
extensions: simplexml, xmlreader, pdo, json, curl, mbstring, zip, gd, redis
coverage: none
tools: composer:v2
- name: Detect tests
id: tests
working-directory: module
run: |
set -euo pipefail
if [ -n "$(find tests -name '*Test.php' -print -quit 2>/dev/null)" ]; then
echo 'present=true' >> "$GITHUB_OUTPUT"
else
echo 'present=false' >> "$GITHUB_OUTPUT"
echo 'The module has no tests — skipping the run.'
fi
# Тести модуля посилаються на класи ядра, тож виконуються всередині
# справжнього рушія. Розкладка — та сама, що у верстаку okay-lab.
- name: Check out the ${{ matrix.target }} engine
if: steps.tests.outputs.present == 'true'
uses: actions/checkout@v7
with:
repository: ${{ matrix.repo }}
ref: ${{ matrix.ref }}
path: engine
- name: Install engine dependencies
if: steps.tests.outputs.present == 'true'
working-directory: engine
run: composer install --no-interaction --prefer-dist --no-progress
- name: Place the module into the engine
if: steps.tests.outputs.present == 'true'
run: |
set -euo pipefail
mkdir -p "engine/Okay/Modules/$VENDOR/$MODULE" "engine/tests/Modules/$VENDOR/$MODULE"
rsync -a --exclude=.git --exclude=.github --exclude=tests \
module/ "engine/Okay/Modules/$VENDOR/$MODULE/"
rsync -a module/tests/ "engine/tests/Modules/$VENDOR/$MODULE/"
- name: PHPUnit on ${{ matrix.target }}
if: steps.tests.outputs.present == 'true'
working-directory: engine
run: vendor/bin/phpunit "tests/Modules/$VENDOR/$MODULE"
release:
needs: [lint, verify]
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.ver.outputs.version }}
tag: ${{ steps.ver.outputs.tag }}
needed: ${{ steps.ver.outputs.needed }}
commit: ${{ steps.tag.outputs.commit }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
# workflow_dispatch запускається з будь-якої гілки, а тег нижче ставиться
# на ту, з якої запущено. Без цієї перевірки реліз із випадкової гілки
# виглядав би як звичайний.
- name: Release from the default branch only
run: |
set -euo pipefail
default='${{ github.event.repository.default_branch }}'
if [ '${{ github.ref_name }}' != "$default" ]; then
echo "Releases run from $default only, not from ${{ github.ref_name }}."
exit 1
fi
- name: Read the version to release
id: ver
run: |
set -euo pipefail
v=$(python3 -c 'import json; print(json.load(open("Init/module.json"))["version"])')
echo "$v" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'
{
echo "version=$v"
echo "tag=v$v"
} >> "$GITHUB_OUTPUT"
# Тег на цю версію вже є — виходимо зеленими: PR без підняття версії
# не має фарбувати main у червоне.
if git rev-parse -q --verify "refs/tags/v$v" >/dev/null; then
echo 'needed=false' >> "$GITHUB_OUTPUT"
echo "v$v is already tagged — nothing to release."
else
echo 'needed=true' >> "$GITHUB_OUTPUT"
fi
- name: Create the tag
id: tag
if: steps.ver.outputs.needed == 'true'
run: |
set -euo pipefail
git tag '${{ steps.ver.outputs.tag }}'
git push origin '${{ steps.ver.outputs.tag }}'
echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Build the archive
if: steps.ver.outputs.needed == 'true'
run: |
set -euo pipefail
mkdir -p dist "build/$VENDOR/$MODULE"
rsync -a --exclude=.git --exclude=.github --exclude=.gitignore \
--exclude=README.md --exclude=tests --exclude=dist --exclude=build \
./ "build/$VENDOR/$MODULE/"
(cd build && zip -rq "../dist/$MODULE-${{ steps.ver.outputs.tag }}.zip" "$VENDOR")
- name: Publish the release
if: steps.ver.outputs.needed == 'true'
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.ver.outputs.tag }}
name: ${{ steps.ver.outputs.tag }}
generate_release_notes: true
files: dist/*.zip
# Чи є взагалі форк-специфічні зміни. Окремим job'ом, бо результат потрібен
# у job-рівневих `if` наступних двох.
detect-fork:
needs: release
if: needs.release.outputs.needed == 'true'
runs-on: ubuntu-latest
outputs:
present: ${{ steps.check.outputs.present }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Detect the fork branch
id: check
run: |
set -euo pipefail
if git ls-remote --exit-code --heads origin fork >/dev/null 2>&1; then
echo 'present=true' >> "$GITHUB_OUTPUT"
else
echo 'present=false' >> "$GITHUB_OUTPUT"
echo 'No fork branch, so no fork-specific changes — the variant is not built.'
fi
# Явна відмова замість тихого злиття: якщо fork не містить щойно
# випущеного коміту, його архів був би старішим за базовий і мовчки
# роз'їхався б з ним.
- name: Ensure the fork branch contains the base release
if: steps.check.outputs.present == 'true'
run: |
set -euo pipefail
base='${{ needs.release.outputs.commit }}'
git fetch origin fork
if ! git merge-base --is-ancestor "$base" origin/fork; then
echo "The fork branch does not contain release commit $base."
echo 'Merge the default branch into it and run the release again.'
exit 1
fi
# Дзеркало job'а lint для гілки fork: її код так само їде в архів.
lint-fork:
needs: detect-fork
if: needs.detect-fork.outputs.present == 'true'
name: fork branch / PHP ${{ matrix.php }} syntax
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.5']
steps:
- uses: actions/checkout@v7
with:
ref: fork
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
- run: |
set -euo pipefail
# tests/ не лінтуються: в архів вони не їдуть і написані під PHP 8.
# Будь-який рядок, крім «No syntax errors», — помилка: php -l повертає 0
# і на Deprecated, а PHPStan у модулів немає.
find . -path ./.git -prune -o -path ./tests -prune -o -name '*.php' -print0 \
| xargs -0 -r -n1 -P4 php -d error_reporting=-1 -d display_errors=1 -d log_errors=0 -l 2>&1 \
| { grep -v '^No syntax errors detected in ' || true; } | tee lint.txt
test ! -s lint.txt
# Той самий набір перевірок, що й для базового релізу, але на гілці fork.
# Без цього job'а рушій-специфічний код — єдиний, де різниця рушіїв взагалі
# може зламатися, — виходив би в реліз узагалі неперевіреним.
verify-fork:
needs: detect-fork
if: needs.detect-fork.outputs.present == 'true'
name: fork branch / ${{ matrix.target }} (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: stock
repo: OkayCMS/OkayCMS
ref: '4.5.3'
# composer.lock стоку 4.5.3 зібраний під PHP 8.5. Тести написані під
# PHP 8.5, як і форк.
php: '8.5'
- target: fork
repo: devSviat/OkayCMS-Fork
ref: main
php: '8.5'
steps:
- name: Check out the fork branch
uses: actions/checkout@v7
with:
ref: fork
path: module
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
# redis: без нього тести кеш-модуля мовчки скіпаються, решті не заважає
extensions: simplexml, xmlreader, pdo, json, curl, mbstring, zip, gd, redis
coverage: none
tools: composer:v2
- name: Detect tests
id: tests
working-directory: module
run: |
set -euo pipefail
if [ -n "$(find tests -name '*Test.php' -print -quit 2>/dev/null)" ]; then
echo 'present=true' >> "$GITHUB_OUTPUT"
else
echo 'present=false' >> "$GITHUB_OUTPUT"
echo 'The module has no tests — skipping the run.'
fi
- name: Check out the ${{ matrix.target }} engine
if: steps.tests.outputs.present == 'true'
uses: actions/checkout@v7
with:
repository: ${{ matrix.repo }}
ref: ${{ matrix.ref }}
path: engine
- name: Install engine dependencies
if: steps.tests.outputs.present == 'true'
working-directory: engine
run: composer install --no-interaction --prefer-dist --no-progress
- name: Place the module into the engine
if: steps.tests.outputs.present == 'true'
run: |
set -euo pipefail
mkdir -p "engine/Okay/Modules/$VENDOR/$MODULE" "engine/tests/Modules/$VENDOR/$MODULE"
rsync -a --exclude=.git --exclude=.github --exclude=tests \
module/ "engine/Okay/Modules/$VENDOR/$MODULE/"
rsync -a module/tests/ "engine/tests/Modules/$VENDOR/$MODULE/"
- name: PHPUnit on ${{ matrix.target }}
if: steps.tests.outputs.present == 'true'
working-directory: engine
run: vendor/bin/phpunit "tests/Modules/$VENDOR/$MODULE"
release-fork:
needs: [release, detect-fork, lint-fork, verify-fork]
if: needs.detect-fork.outputs.present == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: fork
fetch-depth: 0
- name: Align the version and create the tag
run: |
set -euo pipefail
v='${{ needs.release.outputs.version }}'
sed -i -E 's/("version"[[:space:]]*:[[:space:]]*")[^"]*"/\1'"$v"'"/' Init/module.json
python3 -c 'import json; json.load(open("Init/module.json"))'
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git diff --quiet || git commit -am "Version $v"
git push origin HEAD:fork
git tag '${{ needs.release.outputs.tag }}-fork'
git push origin '${{ needs.release.outputs.tag }}-fork'
- name: Build the archive
run: |
set -euo pipefail
mkdir -p dist "build/$VENDOR/$MODULE"
rsync -a --exclude=.git --exclude=.github --exclude=.gitignore \
--exclude=README.md --exclude=tests --exclude=dist --exclude=build \
./ "build/$VENDOR/$MODULE/"
(cd build && zip -rq "../dist/$MODULE-${{ needs.release.outputs.tag }}-fork.zip" "$VENDOR")
- name: Publish the release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.release.outputs.tag }}-fork
name: ${{ needs.release.outputs.tag }}-fork
body: "Variant for the OkayCMS fork (PHP 8.5, Smarty 5). Base release — ${{ needs.release.outputs.tag }}."
files: dist/*.zip