feat(system): app update log
This commit is contained in:
@@ -51,6 +51,89 @@ jobs:
|
||||
echo "publish=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# 从 CHANGELOG.md 提取当前版本的说明,落到 release-note.txt
|
||||
# 用文件而不是 step output 传递:note 是多行文本,多行 output 在各版本 runner 上行为不一致
|
||||
- name: Resolve release note
|
||||
env:
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
run: |
|
||||
if [ ! -f CHANGELOG.md ]; then
|
||||
echo "WARN: 缺少 CHANGELOG.md,本次发布不带变更说明"
|
||||
: > release-note.txt
|
||||
exit 0
|
||||
fi
|
||||
node --input-type=module <<'NODE'
|
||||
import fs from "node:fs";
|
||||
|
||||
const version = process.env.VERSION;
|
||||
const heading = "## v" + version;
|
||||
const lines = fs.readFileSync("CHANGELOG.md", "utf8").split(/\r?\n/);
|
||||
const start = lines.findIndex(line => line.trim() === heading);
|
||||
|
||||
if (start < 0) {
|
||||
console.error("WARN: CHANGELOG.md 中没有 " + heading + ",本次发布不带变更说明");
|
||||
fs.writeFileSync("release-note.txt", "");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const LIMIT = 480;
|
||||
const picked = [];
|
||||
let inComment = false;
|
||||
for (let i = start + 1; i < lines.length; i += 1) {
|
||||
const raw = lines[i];
|
||||
if (/^##\s/.test(raw)) {
|
||||
break;
|
||||
}
|
||||
// 跳过 HTML 注释,避免注释内容占掉长度
|
||||
if (inComment) {
|
||||
if (raw.includes("-->")) {
|
||||
inComment = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (raw.includes("<!--")) {
|
||||
if (!raw.includes("-->")) {
|
||||
inComment = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (raw.trim() === "") {
|
||||
// 连续空行压成一个,只用于分隔段落
|
||||
if (picked.length > 0 && picked[picked.length - 1] !== "") {
|
||||
picked.push("");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// 去掉行尾空白,保留行首缩进(嵌套列表)
|
||||
picked.push(raw.replace(/\s+$/, ""));
|
||||
}
|
||||
while (picked.length > 0 && picked[picked.length - 1] === "") {
|
||||
picked.pop();
|
||||
}
|
||||
|
||||
if (picked.length === 0) {
|
||||
console.error("WARN: " + heading + " 下没有内容,本次发布不带变更说明");
|
||||
}
|
||||
|
||||
// 按行累积到上限,不切半行,避免出现断句
|
||||
const kept = [];
|
||||
let total = 0;
|
||||
for (const line of picked) {
|
||||
const length = Array.from(line).length + (kept.length > 0 ? 1 : 0);
|
||||
if (LIMIT < total + length) {
|
||||
console.error("WARN: 内容超过 " + LIMIT + " 字,截断到第 " + kept.length + " 行");
|
||||
break;
|
||||
}
|
||||
kept.push(line);
|
||||
total += length;
|
||||
}
|
||||
|
||||
// 尖括号转义:note 最终走 v-html 渲染,不能让 CHANGELOG 里的 HTML 被执行
|
||||
const note = kept.join("\n").replace(/</g, "<");
|
||||
fs.writeFileSync("release-note.txt", note);
|
||||
console.log("变更说明(" + Array.from(note).length + " 字):\n" + (note === "" ? "(空)" : note));
|
||||
NODE
|
||||
|
||||
- name: Configure nexus auth
|
||||
env:
|
||||
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
|
||||
@@ -149,13 +232,17 @@ jobs:
|
||||
ARTIFACT_SIZE: ${{ steps.bundle.outputs.size }}
|
||||
SHA256: ${{ steps.bundle.outputs.sha256 }}
|
||||
ATTACHMENT_ID: ${{ steps.upload.outputs.attachment_id }}
|
||||
NOTE_FILE: release-note.txt
|
||||
run: |
|
||||
if [ -z "$PRODUCT_ID" ]; then
|
||||
echo "FAIL: 缺少 vars.APP_PRODUCT_ID"
|
||||
exit 1
|
||||
fi
|
||||
payload=$(node -e "
|
||||
const fs = require('fs');
|
||||
const minCode = Number(process.env.MIN_VERSION_CODE || '1');
|
||||
const noteFile = process.env.NOTE_FILE || 'release-note.txt';
|
||||
const note = fs.existsSync(noteFile) ? fs.readFileSync(noteFile, 'utf8') : '';
|
||||
process.stdout.write(JSON.stringify({
|
||||
productId: process.env.PRODUCT_ID,
|
||||
kind: 'BUNDLE',
|
||||
@@ -164,7 +251,7 @@ jobs:
|
||||
attachmentId: process.env.ATTACHMENT_ID,
|
||||
artifactSize: Number(process.env.ARTIFACT_SIZE),
|
||||
sha256: process.env.SHA256,
|
||||
note: 'CI 构建 ${{ github.sha }}'.slice(0, 500)
|
||||
note
|
||||
}));
|
||||
")
|
||||
response=$(curl -sS -X POST "$API_BASE_URL/app/release/create" \
|
||||
@@ -207,6 +294,13 @@ jobs:
|
||||
echo "需要上线时调用 /app/release/publish?releaseId=${{ steps.create.outputs.release_id }}"
|
||||
fi
|
||||
echo "-----"
|
||||
echo "变更说明(写入 App 更新日志):"
|
||||
if [ -s release-note.txt ]; then
|
||||
cat release-note.txt
|
||||
else
|
||||
echo "(空)CHANGELOG.md 中没有 v${{ steps.version.outputs.version }} 一节,本次发布不带更新说明"
|
||||
fi
|
||||
echo "-----"
|
||||
echo "热更兼容最低原生版本:${{ vars.APP_MIN_VERSION_CODE }}"
|
||||
echo "只有原生壳升级(增删原生插件)时才需要提高这个值,纯 JS 改动不用管"
|
||||
echo "本次产物大小:${{ steps.bundle.outputs.size }} 字节"
|
||||
|
||||
Reference in New Issue
Block a user