Repository navigation
606 lines (557 loc) · 25.4 KB
/
Copy pathrelease.yml
File metadata and controls
606 lines (557 loc) · 25.4 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
# =============================================================================
# Snishaper-Droid · Release
#
# 手动触发(workflow_dispatch),需要确认两件事,均由 github-actions bot
# 自动提交推送:
# 1. 主版本号(version):提交到软件内标注版本的所有位置 ——
# gradle app/build.gradle.kts versionName
# 后端 gomobile/mobile/app.go engineVersion
# 前端 frontend-android/package.json version(含 package-lock 同步)
# 留空则沿用当前版本,不产生提交。
# 2. 发布渠道(channel):同样由 bot 提交到 gomobile/mobile/app.go 的
# releaseChannel 常量(release 渠道写入 "stable")。
#
# 版本策略(单一来源:app/build.gradle.kts 的 versionName):
# * 正式渠道(release):tag = v{version}
# * 预发布渠道:tag = v{version}-{suffix}(如 v1.30.0-alpha.1),后缀留空时
# 默认 {channel}.1;构建时把 APK versionName 改写为带后缀的完整版本,
# 保证应用内"关于"页与 GitHub Release 版本一致。
# * versionCode 由 versionName 推导(major*1_000_000 + minor*1_000 + patch),
# bot 只提交 versionName,versionCode 自动单调递增。
#
# 更新日志:不做 AI 总结,直接列提交:
# - <提交标题> by @<GitHub 登录名> in [`<7 位短 sha>`](commit 链接)(短 sha 不会被
# GitHub 自动链接,必须显式链接才能跳转);
# 基线为上一个正式(非 prerelease)Release 的 tag——预发布同样只对比上一个正式版,
# 登录名按 commit 逐个经 GitHub API 解析(git 作者名不是登录名,直接 @ 会提到无关账号)。
# =============================================================================
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "主版本号(如 1.30.0,或与桌面端对齐的四段热修 1.30.3.2)。bot 自动提交到 gradle / 后端 / 前端;留空沿用当前版本"
required: false
type: string
default: ""
channel:
description: "发布渠道(bot 同步提交到后端 releaseChannel)"
required: true
type: choice
default: "release"
options:
- release
- rc
- beta
- alpha
version_suffix:
description: "预发布后缀(如 alpha.2);非 release 渠道留空时默认 {channel}.1"
required: false
type: string
default: ""
permissions:
contents: write
# 串行发布:防止两次 dispatch 的 bot 提交互相冲突。
concurrency:
group: release
cancel-in-progress: false
env:
GOPROXY: https://proxy.golang.org,direct
GOSUMDB: sum.golang.org
COMPILE_SDK: "37"
COMPILE_SDK_MINOR: "2"
BUILD_TOOLS: "37.0.0"
NDK_VERSION: "30.0.16248370"
GOMOBILE_VERSION: "v0.0.0-20260803200217-62cee1672c8e"
ANDROID_SDK_ROOT: /usr/local/lib/android/sdk
jobs:
# ------------------------------------------------------------------
# Bot commit: version (gradle / backend / frontend) + channel, then
# resolve the final tag and skip if the release already exists.
# ------------------------------------------------------------------
bump:
name: Bump version & channel (bot)
runs-on: ubuntu-26.04
outputs:
version: ${{ steps.resolve.outputs.version }}
tag: ${{ steps.resolve.outputs.tag }}
skip: ${{ steps.resolve.outputs.skip }}
sha: ${{ steps.bump.outputs.sha }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup Node (syncs package-lock on version bump)
uses: actions/setup-node@v7
with:
node-version: "20"
- name: Commit version & channel (github-actions[bot])
id: bump
env:
INPUT_VERSION: ${{ inputs.version }}
CHANNEL: ${{ inputs.channel }}
run: |
set -euo pipefail
base="$(sed -nE 's/^[[:space:]]*versionName = "([^"]+)".*/\1/p' app/build.gradle.kts | head -n1)"
if [ -z "$base" ]; then
echo "::error::versionName not found in app/build.gradle.kts"
exit 1
fi
version="$base"
if [ -n "$INPUT_VERSION" ]; then
# A fourth hotfix part (e.g. 1.30.3.2) is accepted for version
# parity with the desktop releases; gradle's versionCode
# derivation ignores it, so it never moves the Play code.
if ! printf '%s' "$INPUT_VERSION" | grep -Eq '^[0-9]+(\.[0-9]+){0,3}$'; then
echo "::error::invalid version '${INPUT_VERSION}' (expected e.g. 1.30.0 or 1.30.3.2)"
exit 1
fi
version="$INPUT_VERSION"
fi
# Channel shown in the app: release dispatches display as "stable".
display_channel="$CHANNEL"
if [ "$CHANNEL" = "release" ]; then
display_channel="stable"
fi
changed=false
if [ "$version" != "$base" ]; then
sed -i -E "s/^([[:space:]]*versionName = )\"[^\"]*\"/\1\"${version}\"/" app/build.gradle.kts
sed -i -E "s/^([[:space:]]*engineVersion = )\"[^\"]*\"/\1\"${version}\"/" gomobile/mobile/app.go
sed -i -E "s/(\"version\": )\"[^\"]*\"/\1\"${version}\"/" frontend-android/package.json
(cd frontend-android && npm install --package-lock-only --no-audit --no-fund >/dev/null)
changed=true
fi
if ! grep -qE "^[[:space:]]*releaseChannel = \"${display_channel}\"$" gomobile/mobile/app.go; then
sed -i -E "s/^([[:space:]]*releaseChannel = )\"[^\"]*\"/\1\"${display_channel}\"/" gomobile/mobile/app.go
changed=true
fi
if [ "$changed" = true ]; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add app/build.gradle.kts gomobile/mobile/app.go \
frontend-android/package.json frontend-android/package-lock.json
git commit -m "chore(release): v${version} (${CHANNEL})"
git push
echo "::notice::bot committed version=${version} channel=${CHANNEL}"
else
echo "::notice::nothing to bump (version=${version}, channel already ${display_channel})"
fi
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: Resolve tag / skip if release exists
id: resolve
env:
VERSION: ${{ steps.bump.outputs.version }}
CHANNEL: ${{ inputs.channel }}
SUFFIX: ${{ inputs.version_suffix }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
version="$VERSION"
if [ "$CHANNEL" != "release" ]; then
version="${VERSION}-${SUFFIX:-${CHANNEL}.1}"
fi
tag="v${version}"
skip=false
if gh release view "$tag" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
echo "::notice::release ${tag} already exists - nothing to do"
skip=true
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
echo "skip=$skip" >> "$GITHUB_OUTPUT"
# ------------------------------------------------------------------
# Full toolchain + multi-ABI release build (APK + AAB + AAR).
# ------------------------------------------------------------------
build:
name: Build release artifacts
needs: bump
if: needs.bump.outputs.skip != 'true'
runs-on: ubuntu-26.04
timeout-minutes: 90
steps:
- name: Checkout (post-bump commit)
uses: actions/checkout@v7
with:
ref: ${{ needs.bump.outputs.sha }}
fetch-depth: 0
- name: Apply prerelease version suffix (gradle versionName)
env:
VERSION: ${{ needs.bump.outputs.version }}
run: |
set -euo pipefail
base="$(sed -nE 's/^[[:space:]]*versionName = "([^"]+)".*/\1/p' app/build.gradle.kts | head -n1)"
if [ "$base" != "$VERSION" ]; then
sed -i "s/^[[:space:]]*versionName = \"${base}\"/versionName = \"${VERSION}\"/" app/build.gradle.kts
echo "::notice::versionName rewritten to ${VERSION} for this build"
fi
grep -n 'versionName' app/build.gradle.kts
- name: Setup JDK 17 (requirement alignment; not used for the build)
id: jdk17
uses: actions/setup-java@v6
with:
distribution: temurin
java-version: "17"
- name: Setup JDK 25 (actual build JDK)
id: jdk25
uses: actions/setup-java@v6
with:
distribution: temurin
java-version: "25"
- name: Use JDK 25 as JAVA_HOME
run: echo "JAVA_HOME=${{ steps.jdk25.outputs.java-home }}" >> "$GITHUB_ENV"
- name: Setup Gradle (dependency + build cache)
uses: gradle/actions/setup-gradle@v6
- name: Cache Android SDK components (NDK / platform / build-tools)
uses: actions/cache@v6
with:
path: |
${{ env.ANDROID_SDK_ROOT }}/ndk/${{ env.NDK_VERSION }}
${{ env.ANDROID_SDK_ROOT }}/platforms/android-${{ env.COMPILE_SDK }}.${{ env.COMPILE_SDK_MINOR }}
${{ env.ANDROID_SDK_ROOT }}/build-tools/${{ env.BUILD_TOOLS }}
# v3 namespace: the v2 cache entries are corrupt ( ar exits with 2 on restore)
key: android-sdk-v3-${{ runner.os }}-api${{ env.COMPILE_SDK }}.${{ env.COMPILE_SDK_MINOR }}-bt${{ env.BUILD_TOOLS }}-ndk${{ env.NDK_VERSION }}
restore-keys: |
android-sdk-v3-${{ runner.os }}-
- name: Cache gomobile toolchain
uses: actions/cache@v6
with:
path: |
~/go/bin/gomobile
~/go/bin/gobind
key: gomobile-${{ runner.os }}-${{ env.GOMOBILE_VERSION }}
restore-keys: |
gomobile-${{ runner.os }}-
- name: Cache Go build cache
uses: actions/cache@v6
with:
path: ~/.cache/go-build
key: go-build-${{ runner.os }}-${{ hashFiles('gomobile/go.sum') }}
restore-keys: |
go-build-${{ runner.os }}-
- name: Install Android SDK components (preinstalled SDK on the runner)
run: |
set -euo pipefail
SDK_ROOT="${ANDROID_SDK_ROOT:-/usr/local/lib/android/sdk}"
echo "ANDROID_SDK_ROOT=${SDK_ROOT}" >> "$GITHUB_ENV"
echo "ANDROID_HOME=${SDK_ROOT}" >> "$GITHUB_ENV"
SDKMANAGER="${SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager"
if [ ! -x "$SDKMANAGER" ]; then
SDKMANAGER="$(command -v sdkmanager)" || {
echo "::error::sdkmanager not found on the runner"; exit 1;
}
fi
yes | "$SDKMANAGER" --licenses > /dev/null 2>&1 || true
"$SDKMANAGER" --install \
"platform-tools" \
"platforms;android-${COMPILE_SDK}.${COMPILE_SDK_MINOR}" \
"build-tools;${BUILD_TOOLS}" \
"ndk;${NDK_VERSION}"
echo "ANDROID_NDK_HOME=${SDK_ROOT}/ndk/${NDK_VERSION}" >> "$GITHUB_ENV"
echo "ANDROID_NDK_ROOT=${SDK_ROOT}/ndk/${NDK_VERSION}" >> "$GITHUB_ENV"
- name: Setup Go 1.27
uses: actions/setup-go@v7
with:
go-version: "1.27.x"
cache-dependency-path: gomobile/go.sum
- name: Check gcc (cgo toolchain)
run: gcc --version
- name: Install gomobile + gobind (pinned version)
run: |
set -euo pipefail
go install "golang.org/x/mobile/cmd/gomobile@${GOMOBILE_VERSION}"
go install "golang.org/x/mobile/cmd/gobind@${GOMOBILE_VERSION}"
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- name: Use official Maven / Gradle repositories in CI
run: |
set -euo pipefail
sed -i '/repo\.huaweicloud\.com/d' settings.gradle.kts
sed -i 's#repo\.huaweicloud\.com/gradle#services.gradle.org/distributions#g' \
gradle/wrapper/gradle-wrapper.properties
- name: Build and verify AAR
run: |
set -euo pipefail
mkdir -p app/libs
cd gomobile
gomobile bind \
-target=android/arm64,android/arm,android/amd64 \
-androidapi 24 \
-tags with_gvisor \
-trimpath \
-ldflags="-s -w" \
-javapkg com.snishaper.core \
-o ../app/libs/snishaper-core.aar \
./mobile
cd ..
python3 scripts/verify_aar.py
- name: Setup Node (frontend build)
uses: actions/setup-node@v7
with:
node-version: "20"
cache: npm
cache-dependency-path: frontend-android/package-lock.json
- name: Build frontend bundle
run: |
set -euo pipefail
cd frontend-android
npm install --no-audit --no-fund
npx vite build
cd ..
test -f app/src/main/assets/frontend/index.html
- name: Import release keystore
env:
KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
run: |
set -euo pipefail
if [ -z "${KEYSTORE_BASE64:-}" ] || [ -z "${KEYSTORE_PASSWORD:-}" ] || [ -z "${KEY_ALIAS:-}" ] || [ -z "${KEY_PASSWORD:-}" ]; then
echo "::warning::release signing secrets are incomplete - the APK/AAB will NOT be signed"
exit 0
fi
mkdir -p "$RUNNER_TEMP/signing"
printf '%s' "$KEYSTORE_BASE64" | base64 -d > "$RUNNER_TEMP/signing/release.jks"
{
echo "SNISHAPER_KEYSTORE=$RUNNER_TEMP/signing/release.jks"
echo "SNISHAPER_KEYSTORE_PASSWORD=$KEYSTORE_PASSWORD"
echo "SNISHAPER_KEY_ALIAS=$KEY_ALIAS"
echo "SNISHAPER_KEY_PASSWORD=$KEY_PASSWORD"
} >> "$GITHUB_ENV"
echo "::notice::release keystore imported"
- name: Build release APK + AAB
run: |
set -euo pipefail
chmod +x gradlew
sed -i '/^org\.gradle\.java\.home=/d' gradle.properties
./gradlew --no-daemon --stacktrace signingInfo lint test assembleRelease bundleRelease
- name: Verify release signature
run: |
set -euo pipefail
apk="$(find app/build/outputs/apk/release -name '*.apk' | head -n1)"
aab="$(find app/build/outputs/bundle/release -name '*.aab' | head -n1)"
test -n "$apk"
if [ ! -s "${RUNNER_TEMP}/signing/release.jks" ]; then
echo "::warning::ANDROID_KEYSTORE_* secrets are missing - this release ships UNSIGNED APK/AAB artifacts"
exit 0
fi
case "$(basename "$apk")" in
*unsigned*)
echo "::error::signing material was provided but the APK is unsigned"
exit 1
;;
esac
apksigner="$(find "${ANDROID_SDK_ROOT}/build-tools" -maxdepth 2 -name apksigner | sort -V | tail -n1)"
"$apksigner" verify --verbose --print-certs "$apk"
jarsigner -verify "$aab" > /dev/null
echo "::notice::signature verified for $(basename "$apk") and $(basename "$aab")"
- name: Stage release artifacts (flat layout for the publish job)
env:
VERSION: ${{ needs.bump.outputs.version }}
run: |
set -euo pipefail
mkdir -p dist
apk="$(find app/build/outputs/apk/release -name '*.apk' | head -n1)"
cp "$apk" "dist/snishaper-droid-${VERSION}.apk"
cp app/build/outputs/bundle/release/*.aab "dist/snishaper-droid-${VERSION}.aab"
cp app/libs/snishaper-core.aar "dist/snishaper-core.aar"
if printf '%s' "$(basename "$apk")" | grep -qi unsigned; then
echo "unsigned" > dist/SIGNING.txt
else
echo "signed" > dist/SIGNING.txt
fi
( cd dist && sha256sum * > SHA256SUMS.txt )
ls -lh dist/
- name: Upload release artifacts
uses: actions/upload-artifact@v7
with:
name: release-artifacts-${{ needs.bump.outputs.version }}
path: dist/*
if-no-files-found: error
retention-days: 14
# ------------------------------------------------------------------
# Publish: commit-list changelog (no AI summary) + GitHub Release
# + release announcement to the SnishaperDroid notice channel.
# ------------------------------------------------------------------
publish:
name: Publish release
needs: [bump, build]
if: needs.bump.outputs.skip != 'true'
runs-on: ubuntu-26.04
timeout-minutes: 30
env:
ANNOUNCEMENT_READY: ${{ secrets.ANNOUNCEMENT_ADMIN_EMAIL != '' && secrets.ANNOUNCEMENT_ADMIN_PASSWORD != '' }}
ANNOUNCEMENT_ADMIN_EMAIL: ${{ secrets.ANNOUNCEMENT_ADMIN_EMAIL }}
ANNOUNCEMENT_ADMIN_PASSWORD: ${{ secrets.ANNOUNCEMENT_ADMIN_PASSWORD }}
steps:
- name: Checkout full history
uses: actions/checkout@v7
with:
ref: ${{ needs.bump.outputs.sha }}
fetch-depth: 0
- name: Download release artifacts
uses: actions/download-artifact@v8
with:
name: release-artifacts-${{ needs.bump.outputs.version }}
path: release-assets
- name: Generate commit-list changelog
env:
VERSION: ${{ needs.bump.outputs.version }}
TAG: ${{ needs.bump.outputs.tag }}
CHANNEL: ${{ inputs.channel }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
# Baseline = previous STABLE release, mirroring the desktop
# _release_pipeline: prerelease changelogs compare against the
# last official release. The old `git describe "$GITHUB_REF_NAME^"`
# was broken twice over: GITHUB_REF_NAME is the branch name which
# does not resolve on the detached HEAD this job checks out, so
# the describe failed and the changelog silently fell back to the
# whole history.
PREV_TAG="$(gh release list --limit 100 --json tagName,isPrerelease \
--jq '[.[] | select(.isPrerelease == false) | .tagName] | first // empty')"
RANGE=""
if [ -n "$PREV_TAG" ]; then
git fetch --tags --force origin
RANGE="${PREV_TAG}..HEAD"
echo "::notice::changelog range: ${RANGE}"
else
echo "::notice::no previous stable release, listing the whole history"
fi
# Resolve the GitHub login per commit so the "by @login" mention
# points at the real account (git author names are not logins:
# "@dongle" mentioned the unrelated github.com/dongle user).
# Fallback: plain author name without @, never a wrong mention.
COMMITS="$(git log -n 200 --pretty=format:'%H%x09%s' ${RANGE} | while IFS=$'\t' read -r sha subject; do
login="$(gh api "repos/${GITHUB_REPOSITORY}/commits/${sha}" --jq '.author.login // empty' 2>/dev/null || true)"
if [ -n "$login" ]; then by="@${login}"; else by="$(git log -1 --pretty=format:%an "${sha}")"; fi
echo "- ${subject} by ${by} in [\`${sha:0:7}\`](https://github.com/${GITHUB_REPOSITORY}/commit/${sha})"
done)"
{
echo "# Snishaper-Droid ${VERSION}(Android)"
echo
echo "> 🔐 **CA 功能已恢复**:支持证书生成 / 重生成 / 导出,规则模式"
echo "> mitm / quic / migration 与规则级 cert_verify 完整可用;系统信任库"
echo "> 安装需要已 root 的设备(su + certutil)。"
echo
if [ "$CHANNEL" != "release" ]; then
echo "> 🚧 **预发布版本(${CHANNEL})**:仅供测试,不建议日常使用。"
echo
fi
echo "## 变更 / Changelog"
echo
echo "$COMMITS"
echo
echo
echo "## 产物 / Assets"
echo
echo "- 界面:直接复用桌面端 React 前端(React 19 + MUI 9),与桌面版 UI 一致"
echo "- 构建:AGP 9.5 / JDK 25 / compileSdk 37 / minSdk 24 / targetSdk 36"
echo "- 内核:snishaper-core(gomobile AAR,arm64-v8a + armeabi-v7a + x86_64)"
if grep -q unsigned release-assets/SIGNING.txt 2>/dev/null; then
echo "> **⚠️ 本次产物未签名**:仓库缺少 \`ANDROID_KEYSTORE_*\` secrets,安装前请自行校验来源。"
echo
else
echo "- 签名:APK / AAB 使用发布密钥签名(v2 + v3 + v4),安装包 SHA-256 见 \`SHA256SUMS.txt\`"
fi
} > RELEASE_NOTES.md
cat RELEASE_NOTES.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.bump.outputs.tag }}
name: Snishaper-Droid ${{ needs.bump.outputs.version }}
body_path: RELEASE_NOTES.md
target_commitish: ${{ needs.bump.outputs.sha }}
draft: false
prerelease: ${{ inputs.channel != 'release' }}
files: |
release-assets/*.apk
release-assets/*.aab
release-assets/snishaper-core.aar
release-assets/SHA256SUMS.txt
release-assets/SIGNING.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish release announcement
if: env.ANNOUNCEMENT_READY == 'true'
continue-on-error: true
env:
VERSION: ${{ needs.bump.outputs.version }}
TAG: ${{ needs.bump.outputs.tag }}
PRERELEASE: ${{ inputs.channel != 'release' }}
run: |
set -euo pipefail
# Announcement body = the commit-list changelog section of
# RELEASE_NOTES.md (no AI summary). Id release-<tag> is idempotent:
# re-running a release replaces the same notice.
python3 - <<'PY'
import json, os, re, urllib.request
from datetime import datetime, timezone
base = 'https://jetcpp.ccwu.cc'
version = os.environ['VERSION']
tag = os.environ['TAG']
prerelease = os.environ['PRERELEASE'] == 'true'
link = f"https://github.com/{os.environ['GITHUB_REPOSITORY']}/releases/tag/{tag}"
changes = ''
try:
notes = open('RELEASE_NOTES.md', encoding='utf-8').read()
match = re.search(r'^## 变更 / Changelog\s*\n(.*?)(?=^## |\Z)', notes, re.S | re.M)
if match:
changes = match.group(1).strip()
if not changes:
changes = notes.strip()
except OSError:
pass
if not changes:
changes = f'Snishaper-Droid {version}'
if len(changes) > 1600:
changes = changes[:1600].rstrip() + '...'
body = f"本次更新内容:\n{changes}\n\n完整更新日志与下载资产见本次发版页面:{link}"
body_en = f"What's new in this release:\n{changes}\n\nFull release notes and downloadable assets: {link}"
body_ru = f"Что нового в этом выпуске:\n{changes}\n\nПолные примечания и файлы выпуска: {link}"
login_payload = json.dumps({
'email': os.environ['ANNOUNCEMENT_ADMIN_EMAIL'],
'password': os.environ['ANNOUNCEMENT_ADMIN_PASSWORD'],
}).encode('utf-8')
login_req = urllib.request.Request(
f'{base}/api/admin/session', data=login_payload,
# Cloudflare blocks the default Python-urllib UA with 403.
headers={
'Content-Type': 'application/json; charset=utf-8',
'User-Agent': 'Mozilla/5.0 (compatible; SnishaperDroid-Release-CI/1.0)',
}, method='POST')
with urllib.request.urlopen(login_req, timeout=30) as response:
login = json.load(response)
if not login.get('admin') or not login.get('token'):
raise RuntimeError('admin login failed')
notice = {
'id': f'release-{tag}',
'title': f'Snishaper-Droid {version} 发布',
'title_en': f'Snishaper-Droid {version} released',
'title_ru': f'Выпущен Snishaper-Droid {version}',
'body': body,
'body_en': body_en,
'body_ru': body_ru,
'level': 'info' if prerelease else 'important',
'published_at': datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ'),
'link': link,
'link_text': '查看本次发行说明',
'pinned': False,
}
notice_payload = json.dumps(notice, ensure_ascii=False).encode('utf-8')
notice_req = urllib.request.Request(
f'{base}/api/notices?product=SnishaperDroid', data=notice_payload,
headers={
'Content-Type': 'application/json; charset=utf-8',
'User-Agent': 'Mozilla/5.0 (compatible; SnishaperDroid-Release-CI/1.0)',
'Authorization': f"Bearer {login['token']}",
}, method='POST')
with urllib.request.urlopen(notice_req, timeout=30) as response:
result = json.load(response)
if not result.get('ok'):
raise RuntimeError('announcement publish failed')
print(f"::notice::announcement published for {tag} (id release-{tag}, link {link})")
PY