/releases/latest/download/<asset> 实测 404,只有带具体 tag 的 下载路径可用。版本号从 /api/v1/.../releases/latest 拿, version.txt 因此不再需要单独作为 asset 上传。
58 lines
2.5 KiB
YAML
58 lines
2.5 KiB
YAML
# 发布流程:推送 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
|
||
tar -czf patchbay.tar.gz -C dist patchbay
|
||
|
||
# 直接 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; }
|
||
curl -fsS -X POST -H "$auth" -F "attachment=@patchbay.tar.gz" \
|
||
"$api/releases/${id}/assets?name=patchbay.tar.gz" >/dev/null
|
||
echo "已上传 patchbay.tar.gz"
|