Files
GarfieldandCopilot 38670b74b3
Release / release (push) Successful in 10s
🐛 工作流签出和 API 改走公网地址
Co-authored-by: Copilot <[email protected]>
2026-11-18 22:36:02 +08:00

87 lines
3.8 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Release
# 推送 vX.Y.Z(或 vX.Y.Z-rc.1 等预发布)标签:打包本仓库的插件为 zip → 建 Release 并上传。
# 更新日志取自 CHANGELOG.md 里 "## <版本号>" 这一节,作为 Release 说明(月读的更新弹窗也会显示)。
# 令牌默认用内置 GITHUB_TOKEN;需要时可在仓库密钥里配 RELEASE_TOKEN 覆盖。
on:
push:
tags:
- "v*"
jobs:
release:
runs-on: gitea
container:
image: node:22-bookworm
steps:
# 实例内网地址在任务容器里解析不了,签出和 API 都走公网地址
- name: Checkout
uses: actions/checkout@v4
with:
github-server-url: https://git.garfieldho.me
- name: Resolve version
id: ver
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.+-].*)?$ ]]; then
echo "标签不合法:${TAG}(应为 vMAJOR.MINOR.PATCH)"
exit 1
fi
PRERELEASE=false
[[ "$VERSION" == *-* ]] && PRERELEASE=true
{
echo "tag=${TAG}"
echo "version=${VERSION}"
echo "prerelease=${PRERELEASE}"
} >> "$GITHUB_OUTPUT"
shell: bash
- name: Install packaging tools
run: apt-get update && apt-get install -y -o Acquire::Retries=3 rsync zip
- name: Package plugin
run: tools/package.sh "${{ steps.ver.outputs.version }}" dist
- name: Create release and upload assets
env:
TOKEN: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
TAG: ${{ steps.ver.outputs.tag }}
PRERELEASE: ${{ steps.ver.outputs.prerelease }}
VERSION: ${{ steps.ver.outputs.version }}
run: |
set -euo pipefail
: "${TOKEN:?没有可用令牌:没有内置令牌,也没有配置 RELEASE_TOKEN}"
API="https://git.garfieldho.me/api/v1/repos/${GITHUB_REPOSITORY}"
AUTH="Authorization: token ${TOKEN}"
# 同一标签重跑:删掉旧 Release 再建,附件不会重复
OLD=$(curl -fsS -H "$AUTH" "${API}/releases/tags/${TAG}" 2>/dev/null | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{console.log(JSON.parse(s).id||"")}catch(e){}})' || true)
[ -n "$OLD" ] && curl -fsS -X DELETE -H "$AUTH" "${API}/releases/${OLD}"
BODY=$(node -e '
const fs = require("fs");
let notes = "";
try {
const lines = fs.readFileSync("CHANGELOG.md", "utf8").split(/\r?\n/);
const start = lines.findIndex(l => l.trim() === "## " + process.env.VERSION);
if (start >= 0) {
let end = lines.findIndex((l, i) => i > start && /^## /.test(l));
if (end < 0) end = lines.length;
notes = lines.slice(start + 1, end).join("\n").trim();
}
} catch (e) {}
const tail = "给月读增加在线平台书源的 KOReader 插件。把 zip 解压到 KOReader 的 plugins/ 目录即可,附件 SHA256SUMS 用于校验。与各平台官方无关,使用风险自行承担。";
console.log(JSON.stringify({tag_name:process.env.TAG,name:process.env.TAG,prerelease:process.env.PRERELEASE==="true",body:notes?notes+"\n\n---\n"+tail:tail}));
')
ID=$(curl -fsS -X POST -H "$AUTH" -H "Content-Type: application/json" -d "$BODY" "${API}/releases" \
| node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>console.log(JSON.parse(s).id))')
for f in dist/*; do
echo "upload $(basename "$f")"
curl -fsS -X POST -H "$AUTH" -F "attachment=@${f}" "${API}/releases/${ID}/assets?name=$(basename "$f")" >/dev/null
done
shell: bash