-
Notifications
You must be signed in to change notification settings - Fork 14
784 lines (696 loc) · 29.5 KB
/
Copy pathrelease.yml
File metadata and controls
784 lines (696 loc) · 29.5 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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
name: Release Firmware and BinaryKeyboard ISP
on:
push:
branches:
- main
paths:
- "firmware/**"
- "config/**"
- "tools/meowisp/**"
- "tools/studio/**"
- "tools/scripts/**"
- ".github/workflows/release.yml"
workflow_dispatch:
env:
TOOLCHAIN_VERSION: MRS_Toolchain_Linux_x64_V230
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
jobs:
compute-versions:
name: Compute release versions
runs-on: ubuntu-latest
outputs:
ch592_version: ${{ steps.ver.outputs.ch592_version }}
ch592_patch: ${{ steps.ver.outputs.ch592_patch }}
ch552_version: ${{ steps.ver.outputs.ch552_version }}
ch552_patch: ${{ steps.ver.outputs.ch552_patch }}
studio_version: ${{ steps.ver.outputs.studio_version }}
meowisp_version: ${{ steps.ver.outputs.meowisp_version }}
meowisp_changed: ${{ steps.ver.outputs.meowisp_changed }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Compute
id: ver
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
PY="import sys; sys.path.insert(0,'tools/scripts')"
CH592=$(python3 -c "$PY; from versioning import firmware_version; print(firmware_version('CH592F'))")
CH552=$(python3 -c "$PY; from versioning import firmware_version; print(firmware_version('CH552G'))")
STUDIO=$(python3 -c "$PY; from versioning import studio_version; print(studio_version())")
MEOWISP=$(python3 -c "$PY; from versioning import meowisp_version; print(meowisp_version())")
MEOWISP_CHANGED=$(python3 tools/scripts/versioning.py changed --component meowisp)
echo "ch592_version=$CH592" >> "$GITHUB_OUTPUT"
echo "ch592_patch=${CH592##*.}" >> "$GITHUB_OUTPUT"
echo "ch552_version=$CH552" >> "$GITHUB_OUTPUT"
echo "ch552_patch=${CH552##*.}" >> "$GITHUB_OUTPUT"
echo "studio_version=$STUDIO" >> "$GITHUB_OUTPUT"
echo "meowisp_version=$MEOWISP" >> "$GITHUB_OUTPUT"
echo "meowisp_changed=$MEOWISP_CHANGED" >> "$GITHUB_OUTPUT"
build-ch592f:
name: Package CH592F (${{ matrix.keyboard }})
runs-on: ubuntu-latest
needs: [compute-versions]
strategy:
fail-fast: false
matrix:
keyboard:
- 5KEY
- KNOB
container:
image: ghcr.io/meowkj/binarykeyboard-builder:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
submodules: recursive
fetch-depth: 0
- name: Install Python
run: |
apt-get update -q
apt-get install -y --no-install-recommends python3
- name: Fix git ownership
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Build (bootloader + app + merge)
env:
BK_BUILD_NUMBER: ${{ needs.compute-versions.outputs.ch592_patch }}
run: python3 tools/scripts/ch592f.py build-full --keyboard ${{ matrix.keyboard }} --profile release --build-number "$BK_BUILD_NUMBER"
- name: Resolve artifacts
id: artifacts
run: |
echo "bin=$(python3 tools/scripts/ch592f.py artifact --keyboard ${{ matrix.keyboard }} --profile release --type bin)" >> "$GITHUB_OUTPUT"
echo "full_bin=$(python3 tools/scripts/ch592f.py artifact --keyboard ${{ matrix.keyboard }} --profile release --type full_bin)" >> "$GITHUB_OUTPUT"
- name: Upload release artifacts
uses: actions/upload-artifact@v4
with:
name: release-ch592f-${{ matrix.keyboard }}-${{ github.sha }}
path: |
${{ steps.artifacts.outputs.bin }}
${{ steps.artifacts.outputs.full_bin }}
retention-days: 7
- name: Emit size report
run: python3 tools/scripts/ch592f.py size-json --keyboard ${{ matrix.keyboard }} --profile release --out size-ch592f-${{ matrix.keyboard }}.json
- name: Upload size report
uses: actions/upload-artifact@v4
with:
name: size-ch592f-${{ matrix.keyboard }}
path: size-ch592f-${{ matrix.keyboard }}.json
build-ch552g:
name: Package CH552G (${{ matrix.keyboard }})
runs-on: ubuntu-latest
needs: [compute-versions]
strategy:
fail-fast: false
matrix:
keyboard:
- BASIC
- KNOB
- 5KEY
steps:
- name: Checkout
uses: actions/checkout@v6
with:
submodules: recursive
fetch-depth: 0
- name: Install SDCC 4.6.0
run: |
SDCC_VER="4.6.0"
wget -q "https://sourceforge.net/projects/sdcc/files/sdcc-linux-amd64/${SDCC_VER}/sdcc-${SDCC_VER}-amd64-unknown-linux2.5.tar.bz2/download" -O sdcc.tar.bz2
tar xjf sdcc.tar.bz2
echo "${PWD}/sdcc-${SDCC_VER}/bin" >> "$GITHUB_PATH"
sudo apt-get update -q
sudo apt-get install -y ninja-build
- name: Build
env:
BK_BUILD_NUMBER: ${{ needs.compute-versions.outputs.ch552_patch }}
run: python3 tools/scripts/ch552g.py build --keyboard ${{ matrix.keyboard }} --build-number "$BK_BUILD_NUMBER"
- name: Resolve artifacts
id: artifacts
run: |
echo "bin=$(python3 tools/scripts/ch552g.py artifact --keyboard ${{ matrix.keyboard }} --type bin)" >> "$GITHUB_OUTPUT"
- name: Upload release artifacts
uses: actions/upload-artifact@v4
with:
name: release-ch552g-${{ matrix.keyboard }}-${{ github.sha }}
path: |
${{ steps.artifacts.outputs.bin }}
retention-days: 7
- name: Emit size report
run: python3 tools/scripts/ch552g.py size-json --keyboard ${{ matrix.keyboard }} --out size-ch552g-${{ matrix.keyboard }}.json
- name: Upload size report
uses: actions/upload-artifact@v4
with:
name: size-ch552g-${{ matrix.keyboard }}
path: size-ch552g-${{ matrix.keyboard }}.json
build-studio:
name: Build Studio
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 11.9.0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: "pnpm"
cache-dependency-path: tools/studio/pnpm-lock.yaml
- name: Install dependencies
working-directory: tools/studio
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm --dir tools/studio run build
build-meowisp:
name: Package BinaryKeyboard ISP (${{ matrix.label }})
runs-on: ${{ matrix.runner }}
needs: [compute-versions]
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
label: Linux amd64
platform: linux
arch: amd64
artifact_name: BinaryKeyboard-ISP-linux-amd64-*.tar.gz
- runner: ubuntu-24.04-arm
label: Linux arm64
platform: linux
arch: arm64
artifact_name: BinaryKeyboard-ISP-linux-arm64-*.tar.gz
- runner: macos-14
label: macOS Apple Silicon
platform: macos
arch: apple-silicon
artifact_name: BinaryKeyboard-ISP-macos-apple-silicon-*.zip
- runner: macos-15-intel
label: macOS Intel
platform: macos
arch: intel
artifact_name: BinaryKeyboard-ISP-macos-intel-*.zip
- runner: windows-latest
label: Windows amd64
platform: windows
arch: amd64
artifact_name: BinaryKeyboard-ISP-windows-amd64-*.exe
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Reuse previous BinaryKeyboard ISP release asset
id: reuse_meowisp
if: needs.compute-versions.outputs.meowisp_changed != 'true'
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
VERSION: ${{ needs.compute-versions.outputs.meowisp_version }}
PLATFORM: ${{ matrix.platform }}
ARCH: ${{ matrix.arch }}
run: |
set -euo pipefail
mkdir -p dist
case "$PLATFORM-$ARCH" in
linux-amd64) ASSET="BinaryKeyboard-ISP-linux-amd64-${VERSION}-portable.tar.gz" ;;
linux-arm64) ASSET="BinaryKeyboard-ISP-linux-arm64-${VERSION}-portable.tar.gz" ;;
macos-apple-silicon) ASSET="BinaryKeyboard-ISP-macos-apple-silicon-${VERSION}-portable.zip" ;;
macos-intel) ASSET="BinaryKeyboard-ISP-macos-intel-${VERSION}-portable.zip" ;;
windows-amd64) ASSET="BinaryKeyboard-ISP-windows-amd64-${VERSION}.exe" ;;
*) echo "Unsupported BinaryKeyboard ISP target: $PLATFORM-$ARCH" >&2; exit 1 ;;
esac
LATEST_TAG=$(gh release view --repo "$REPO" --json tagName -q .tagName)
if gh release download "$LATEST_TAG" --repo "$REPO" --pattern "$ASSET" --dir dist; then
echo "reused=true" >> "$GITHUB_OUTPUT"
echo "fallback_build=false" >> "$GITHUB_OUTPUT"
else
echo "BinaryKeyboard ISP asset not found in latest release; fallback to local build for $PLATFORM-$ARCH"
echo "reused=false" >> "$GITHUB_OUTPUT"
echo "fallback_build=true" >> "$GITHUB_OUTPUT"
fi
- name: Setup Python
if: needs.compute-versions.outputs.meowisp_changed == 'true' || steps.reuse_meowisp.outputs.fallback_build == 'true'
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Setup Rust
if: needs.compute-versions.outputs.meowisp_changed == 'true' || steps.reuse_meowisp.outputs.fallback_build == 'true'
uses: dtolnay/rust-toolchain@stable
- name: Install Linux dependencies
if: (needs.compute-versions.outputs.meowisp_changed == 'true' || steps.reuse_meowisp.outputs.fallback_build == 'true') && matrix.platform == 'linux'
run: |
sudo apt-get update -q
sudo apt-get install -y \
pkg-config \
libx11-dev \
libxkbcommon-dev \
libwayland-dev \
libasound2-dev \
libudev-dev \
libfontconfig1-dev \
libfreetype6-dev \
libgl1-mesa-dev \
libglu1-mesa-dev
- name: Download CH375 DLL
if: (needs.compute-versions.outputs.meowisp_changed == 'true' || steps.reuse_meowisp.outputs.fallback_build == 'true') && matrix.platform == 'windows'
shell: pwsh
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
python tools/meowisp/scripts/fetch_windows_dll.py `
--repo "${{ github.repository }}" `
--tag toolchain-linux `
--asset CH375DLL64.dll
- name: Build BinaryKeyboard ISP
if: needs.compute-versions.outputs.meowisp_changed == 'true' || steps.reuse_meowisp.outputs.fallback_build == 'true'
env:
BK_MEOWISP_VERSION: ${{ needs.compute-versions.outputs.meowisp_version }}
run: cargo build --release --manifest-path tools/meowisp/Cargo.toml --bin meowisp
- name: Package BinaryKeyboard ISP (Unix)
if: (needs.compute-versions.outputs.meowisp_changed == 'true' || steps.reuse_meowisp.outputs.fallback_build == 'true') && matrix.platform != 'windows'
run: |
python3 tools/meowisp/scripts/package_portable.py \
--platform "${{ matrix.platform }}" \
--arch "${{ matrix.arch }}" \
--version "${{ needs.compute-versions.outputs.meowisp_version }}" \
--binary "tools/meowisp/target/release/meowisp" \
--out-dir dist
- name: Package BinaryKeyboard ISP (Windows)
if: (needs.compute-versions.outputs.meowisp_changed == 'true' || steps.reuse_meowisp.outputs.fallback_build == 'true') && matrix.platform == 'windows'
shell: pwsh
run: |
python tools/meowisp/scripts/package_portable.py `
--platform "${{ matrix.platform }}" `
--arch "${{ matrix.arch }}" `
--version "${{ needs.compute-versions.outputs.meowisp_version }}" `
--binary "tools/meowisp/target/release/meowisp.exe" `
--out-dir dist
- name: Upload BinaryKeyboard ISP package
uses: actions/upload-artifact@v4
with:
name: release-meowisp-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.sha }}
path: dist/${{ matrix.artifact_name }}
retention-days: 7
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs:
- compute-versions
- build-ch592f
- build-ch552g
- build-studio
- build-meowisp
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
submodules: recursive
fetch-depth: 0
- name: Download packaged artifacts
uses: actions/download-artifact@v4
with:
pattern: release-*-${{ github.sha }}
path: dist
merge-multiple: true
- name: Download size reports
uses: actions/download-artifact@v4
with:
pattern: size-*
path: sizes
merge-multiple: true
- name: Generate version tag
id: version
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
DATE=$(date +%Y%m%d)
DATE_DISPLAY=$(date +%F)
SHA=$(git rev-parse --short HEAD)
TAG="binarykeyboard-${DATE}"
PREV_TAG=$(git for-each-ref --sort=-creatordate --format='%(refname:short)' refs/tags \
| grep '^binarykeyboard-' \
| grep -Fvx "$TAG" \
| grep -Ev "^${TAG}-[0-9a-f]+$" \
| head -n 1 || true)
echo "date=${DATE_DISPLAY}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "name=Release ${DATE_DISPLAY}" >> "$GITHUB_OUTPUT"
echo "previous_tag=${PREV_TAG}" >> "$GITHUB_OUTPUT"
echo "sha=${SHA}" >> "$GITHUB_OUTPUT"
echo "studio_version=${{ needs.compute-versions.outputs.studio_version }}" >> "$GITHUB_OUTPUT"
echo "meowisp_version=${{ needs.compute-versions.outputs.meowisp_version }}" >> "$GITHUB_OUTPUT"
echo "ch592_version=${{ needs.compute-versions.outputs.ch592_version }}" >> "$GITHUB_OUTPUT"
echo "ch552_version=${{ needs.compute-versions.outputs.ch552_version }}" >> "$GITHUB_OUTPUT"
- name: Clean same-day releases and tags
env:
REPO: ${{ github.repository }}
TAG: ${{ steps.version.outputs.tag }}
GITHUB_TOKEN: ${{ github.token }}
PREV_TAG: ${{ steps.version.outputs.previous_tag }}
SHA: ${{ steps.version.outputs.sha }}
DATE_DISPLAY: ${{ steps.version.outputs.date }}
STUDIO_VERSION: ${{ steps.version.outputs.studio_version }}
MEOWISP_VERSION: ${{ steps.version.outputs.meowisp_version }}
CH592_VERSION: ${{ steps.version.outputs.ch592_version }}
CH552_VERSION: ${{ steps.version.outputs.ch552_version }}
run: |
git tag -l "${TAG}*" | xargs -r git tag -d
python3 - <<'PYEOF'
import json
import os
from urllib import request, error
repo = os.environ["REPO"]
tag = os.environ["TAG"]
token = os.environ["GITHUB_TOKEN"]
def api(path: str, method: str = "GET", data: dict | None = None):
payload = None if data is None else json.dumps(data).encode()
req = request.Request(
f"https://api.github.com{path}",
data=payload,
headers={
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {token}",
"X-GitHub-Api-Version": "2022-11-28",
"Content-Type": "application/json",
},
method=method,
)
try:
with request.urlopen(req) as resp:
text = resp.read().decode()
return json.loads(text) if text else None
except error.HTTPError as exc:
if exc.code == 404:
return None
raise
releases = api(f"/repos/{repo}/releases?per_page=100") or []
for release in releases:
tag_name = release.get("tag_name", "")
if tag_name == tag or tag_name.startswith(f"{tag}-"):
api(f"/repos/{repo}/releases/{release['id']}", method="DELETE")
refs = api(f"/repos/{repo}/git/matching-refs/tags/{tag}") or []
for ref in refs:
ref_name = ref.get("ref", "")
if ref_name == f"refs/tags/{tag}" or ref_name.startswith(f"refs/tags/{tag}-"):
api(f"/repos/{repo}/git/{ref_name}", method="DELETE")
PYEOF
# Build release notes from size reports + bin files
{
echo "## 🐱 BinaryKeyboard 自动发布 🐱"
echo
echo "---"
echo
echo "### 版本信息"
echo
echo "| 组件 | 版本 | 说明 |"
echo "|:-----|:-----|:-----|"
echo "| 🎹 Studio | \`v${STUDIO_VERSION}\` | 改键工具(Web) |"
echo "| 🐱 BinaryKeyboard ISP | \`v${MEOWISP_VERSION}\` | 首刷工具(Desktop) |"
echo "| 📡 CH592F | \`v${CH592_VERSION}\` | 无线固件(BLE) |"
echo "| 🔌 CH552G | \`v${CH552_VERSION}\` | 有线固件(USB) |"
echo
echo "---"
echo
echo "### 固件文件"
echo
echo "| 文件 | Flash 占用 | RAM 占用 | 说明 |"
echo "|:-----|:----------|:---------|:-----|"
} > release-notes-header.md
# Generate file table rows from size reports + firmware files
python3 - <<'PYEOF' >> release-notes-header.md
import json, os
from pathlib import Path
sizes_dir = Path("sizes")
dist_dir = Path("dist")
chip_labels = {"CH592F": "📡 无线", "CH552G": "🔌 有线"}
kb_labels = {"5KEY": "五键", "KNOB": "旋钮", "BASIC": "基础"}
rows = []
for p in sorted(sizes_dir.glob("*.json")):
data = json.loads(p.read_text())
chip = data.get("chip", "")
keyboard = data.get("keyboard", "")
regions = data.get("regions", {})
flash = regions.get("FLASH") or regions.get("CODE") or {}
flash_used = flash.get("used")
flash_total = flash.get("total")
if flash_used is not None and flash_total:
pct = flash_used * 100 // flash_total
flash_info = f"{flash_used/1024:.1f} / {flash_total/1024:.0f} KB ({pct}%)"
else:
flash_info = "—"
ram = regions.get("RAM") or regions.get("XRAM") or regions.get("DSEG") or {}
ram_used = ram.get("used")
ram_total = ram.get("total")
if ram_used is not None and ram_total:
ram_pct = ram_used * 100 / ram_total
ram_info = f"{ram_used/1024:.1f} / {ram_total/1024:.1f} KB ({ram_pct:.0f}%)"
else:
ram_info = "—"
kb_label = kb_labels.get(keyboard, keyboard)
if chip == "CH592F":
# -full.bin for ISP
full_files = sorted(dist_dir.glob(f"{chip}-{keyboard}-*-full.bin"))
if full_files:
fname = full_files[0].name
desc = f"{chip_labels.get(chip, chip)} · {kb_label}"
order = (1, keyboard, 0)
rows.append((order, f"| `{fname}` | {flash_info} | {ram_info} | {desc} |"))
else:
# CH552G: .bin only
bin_files = sorted(dist_dir.glob(f"{chip}-{keyboard}-*.bin"))
if bin_files:
fname = bin_files[0].name
desc = f"{chip_labels.get(chip, chip)} · {kb_label}"
order = (0, keyboard, 0)
rows.append((order, f"| `{fname}` | {flash_info} | {ram_info} | {desc} |"))
rows.sort(key=lambda x: x[0])
for _, row in rows:
print(row)
print()
print("> [!TIP]")
print("> **CH592F 无线版固件更新方式:**")
print("> - 🔄 **在线更新**:连接 Studio 后点击「一键更新」,Studio 自动从更新站下载并刷写,无需任何文件")
PYEOF
REPO="${{ github.repository }}"
export REPO
{
echo
echo
echo "---"
echo
echo "### 变更范围"
echo
if [ -n "$PREV_TAG" ]; then
COMMIT_RANGE="${PREV_TAG}..HEAD"
COMMIT_COUNT=$(git rev-list --count "${PREV_TAG}..HEAD")
echo "- 自 [\`${PREV_TAG}\`](https://github.com/${REPO}/releases/tag/${PREV_TAG}) 以来共 **${COMMIT_COUNT}** 个提交"
echo "- 完整对比: https://github.com/${REPO}/compare/${PREV_TAG}...${TAG}"
else
# No previous release tag — show only the last 30 commits
COMMIT_RANGE="HEAD~30..HEAD"
COMMIT_COUNT=$(git rev-list --count HEAD)
echo "- 首次自动发布,仅显示最近 30 个提交(共 ${COMMIT_COUNT} 个)"
fi
echo
} >> release-notes-header.md
export COMMIT_RANGE
export SHA
export DATE_DISPLAY
export TAG
export PREV_TAG
export GITHUB_SHA
export GITHUB_TOKEN="${{ github.token }}"
python3 - <<'PYEOF' > release-notes-commits.md
import os
import re
import subprocess
repo = os.environ["REPO"]
commit_range = os.environ["COMMIT_RANGE"]
email_aliases = {
"ijink@qq.com": "MeowKJ",
"ijink@icloud.com": "MeowKJ",
"41898282+github-actions[bot]@users.noreply.github.com": "github-actions[bot]",
}
def github_username_from_email(email: str) -> str | None:
if email in email_aliases:
return email_aliases[email]
m = re.match(r"(?:\d+\+)?([^@]+)@users\.noreply\.github\.com$", email)
if m:
return m.group(1)
return None
def render_author(author: str, email: str) -> str:
username = github_username_from_email(email)
if username:
return f"@{username}"
return author.strip()
log = subprocess.check_output(
[
"git",
"log",
"--reverse",
"--no-merges",
"--pretty=format:%H%x09%h%x09%an%x09%ae%x09%s",
commit_range,
],
text=True,
)
print("### 提交记录")
print()
for line in log.splitlines():
full_sha, short_sha, author, email, subject = line.split("\t", 4)
author_display = render_author(author, email)
print(
f"- {subject} by {author_display} "
f"([`{short_sha}`](https://github.com/{repo}/commit/{full_sha}))"
)
PYEOF
{
echo
echo
echo "---"
echo
echo "<details><summary>构建环境</summary>"
echo
echo "| 属性 | 值 |"
echo "|:-----|:---|"
echo "| 构建日期 | ${DATE_DISPLAY} |"
echo "| Commit | [\`${SHA}\`](https://github.com/${REPO}/commit/${SHA}) |"
echo "| CH592F 工具链 | \`${{ env.TOOLCHAIN_VERSION }}\` (RISC-V GCC 12) |"
echo "| SDCC | \`$(apt-cache show sdcc 2>/dev/null | grep -m1 '^Version:' | awk '{print $2}' || echo N/A)\` |"
echo "| CMake | \`$(cmake --version 2>/dev/null | head -1 | awk '{print $3}' || echo N/A)\` |"
echo "| Python | \`$(python3 --version 2>/dev/null | awk '{print $2}' || echo N/A)\` |"
echo
echo "</details>"
echo
echo "<details><summary>SHA-256 校验值</summary>"
echo
echo '```'
find dist -maxdepth 1 -type f \( -name '*.bin' -o -name '*.zip' -o -name '*.tar.gz' -o -name '*.exe' \) | sort | while read -r f; do
sha256sum "$f" | sed 's|dist/||'
done
echo '```'
echo
echo "</details>"
} > release-notes-footer.md
python3 - <<'PYEOF'
import json
import os
from pathlib import Path
from urllib import request
repo = os.environ["REPO"]
tag = os.environ["TAG"]
prev_tag = os.environ.get("PREV_TAG", "").strip()
target = os.environ["GITHUB_SHA"]
token = os.environ["GITHUB_TOKEN"]
payload = {
"tag_name": tag,
"target_commitish": target,
}
if prev_tag:
payload["previous_tag_name"] = prev_tag
req = request.Request(
f"https://api.github.com/repos/{repo}/releases/generate-notes",
data=json.dumps(payload).encode(),
headers={
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {token}",
"X-GitHub-Api-Version": "2022-11-28",
"Content-Type": "application/json",
},
method="POST",
)
with request.urlopen(req) as resp:
body = json.load(resp)["body"].strip()
Path("release-notes-generated.md").write_text(body + "\n")
PYEOF
python3 - <<'PYEOF'
from pathlib import Path
header = Path("release-notes-header.md").read_text().strip()
generated = Path("release-notes-generated.md").read_text().strip()
commits = Path("release-notes-commits.md").read_text().strip()
footer = Path("release-notes-footer.md").read_text().strip()
generated = generated.replace(
"<!-- Release notes generated using configuration in .github/release.yml at main -->",
"",
).strip()
if "### Pull Requests" not in generated and "### Other Changes" in generated:
generated = generated.replace("### Other Changes", "### Pull Requests", 1)
marker = "**Full Changelog**:"
if marker in generated:
main_notes, tail = generated.rsplit(marker, 1)
generated = main_notes.rstrip()
full_changelog = marker + tail
else:
full_changelog = ""
contributors_marker = "## New Contributors"
if contributors_marker in generated:
main_notes, tail = generated.split(contributors_marker, 1)
generated = main_notes.rstrip()
contributors = contributors_marker + tail
else:
contributors = ""
parts = [header, generated]
if commits:
parts.append(commits)
if contributors:
parts.append(contributors.strip())
if full_changelog:
parts.append(full_changelog.strip())
parts.append(footer)
Path("release-notes.md").write_text("\n\n".join(part for part in parts if part) + "\n")
PYEOF
- name: Generate release manifest
env:
GITHUB_TOKEN: ${{ github.token }}
BK_VERSION_STUDIO: ${{ steps.version.outputs.studio_version }}
BK_VERSION_MEOWISP: ${{ steps.version.outputs.meowisp_version }}
BK_VERSION_CH592: ${{ steps.version.outputs.ch592_version }}
BK_VERSION_CH552: ${{ steps.version.outputs.ch552_version }}
run: |
mkdir -p dist/api
python3 tools/scripts/versioning.py emit-release-manifest \
--out dist/api/release-manifest.json
- name: Organize firmware for Pages
run: |
mkdir -p dist/firmware/ch592f dist/firmware/ch552g
cp dist/CH592F-*-app.bin dist/firmware/ch592f/ 2>/dev/null || true
cp dist/CH592F-*-full.bin dist/firmware/ch592f/ 2>/dev/null || true
cp dist/CH552G-*.hex dist/firmware/ch552g/ 2>/dev/null || true
- name: Upload pages-firmware artifact
uses: actions/upload-artifact@v4
with:
name: pages-firmware
retention-days: 90
path: |
dist/firmware/
dist/api/release-manifest.json
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.name }}
body_path: release-notes.md
prerelease: false
files: |
dist/CH592F-*-full.bin
dist/CH552G-*.bin
dist/BinaryKeyboard-ISP-linux-amd64-*-portable.tar.gz
dist/BinaryKeyboard-ISP-linux-arm64-*-portable.tar.gz
dist/BinaryKeyboard-ISP-macos-apple-silicon-*-portable.zip
dist/BinaryKeyboard-ISP-macos-intel-*-portable.zip
dist/BinaryKeyboard-ISP-windows-amd64-*.exe