Files
mihomo-patchbay/.gitea/workflows/release.yml
T
im0o fbb2a824dc
release / release (push) Successful in 31s
发布步骤改成直接 curl Gitea API
release-action 是 Go 程序,runner 镜像里没有 Go 工具链,
装工具链不如十几行 curl,还少一个第三方依赖。
2026-08-12 15:45:29 +08:00

63 lines
2.8 KiB
YAML
Raw 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.
# 发布流程:推送 v* 标签 → 测试 → 构建 → 把产物挂到 Gitea Release 上。
#
# 产物 patchbay.tar.gz 与 CPU 架构无关(纯 JS + 静态文件),
# 架构差异由目标机器上的 bun 运行时吸收,安装侧见仓库根目录的 install.sh。
name: release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# 构建用的 bun 版本和 install.sh 里的 BUN_VERSION 保持一致,升级时两处一起改
- uses: oven-sh/setup-bun@v2
with:
bun-version: '1.3.14'
- run: bun install --frozen-lockfile
- run: bun test
- run: bun run typecheck
# 布局必须保持 server/ 与 web-dist/ 平级:
# server/routes.ts 里 WEB_DIST 用 import.meta.url 相对定位 ../web-dist/
- name: 构建并打包
run: |
bun run build
bun build --target=bun --minify server/index.ts --outfile dist/patchbay/server/index.js
cp -r web-dist dist/patchbay/web-dist
echo "${GITHUB_REF_NAME}" > dist/patchbay/version.txt
cp dist/patchbay/version.txt version.txt
tar -czf patchbay.tar.gz -C dist patchbay
# version.txt 单独作为 asset 再传一份,install.sh check 用它比对版本,
# 不用把整个 tarball 拉下来。
# 直接 curl Gitea 的 API 而不用现成 action:gitea.com/actions/release-action
# 是 Go 程序,runner 镜像里没有 Go 工具链,跑不起来
- name: 发布 Release
env:
# 默认令牌建不了 Release 时(老版本 Gitea 的权限限制),
# 在仓库 Settings → Actions → Secrets 里加一个 RELEASE_TOKEN
TOKEN: ${{ secrets.RELEASE_TOKEN || github.token }}
run: |
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
auth="Authorization: token ${TOKEN}"
# 建 Release;已存在(同一个 tag 重跑)就查回它的 id
resp="$(curl -fsS -X POST -H "$auth" -H 'Content-Type: application/json' \
-d "{\"tag_name\":\"${GITHUB_REF_NAME}\",\"name\":\"${GITHUB_REF_NAME}\"}" \
"$api/releases" \
|| curl -fsS -H "$auth" "$api/releases/tags/${GITHUB_REF_NAME}")"
# 响应里第一个 "id" 就是 release 自己的(嵌套对象如 author 排在它后面)
id="$(printf '%s' "$resp" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)"
[ -n "$id" ] || { echo "没拿到 release id,响应: $resp"; exit 1; }
for f in patchbay.tar.gz version.txt; do
curl -fsS -X POST -H "$auth" -F "attachment=@${f}" \
"$api/releases/${id}/assets?name=${f}" >/dev/null
echo "已上传 $f"
done