release-action 是 Go 程序,runner 镜像里没有 Go 工具链, 装工具链不如十几行 curl,还少一个第三方依赖。
This commit is contained in:
@@ -36,13 +36,27 @@ jobs:
|
||||
tar -czf patchbay.tar.gz -C dist patchbay
|
||||
|
||||
# version.txt 单独作为 asset 再传一份,install.sh check 用它比对版本,
|
||||
# 不用把整个 tarball 拉下来
|
||||
# 不用把整个 tarball 拉下来。
|
||||
# 直接 curl Gitea 的 API 而不用现成 action:gitea.com/actions/release-action
|
||||
# 是 Go 程序,runner 镜像里没有 Go 工具链,跑不起来
|
||||
- name: 发布 Release
|
||||
uses: https://gitea.com/actions/release-action@main
|
||||
with:
|
||||
env:
|
||||
# 默认令牌建不了 Release 时(老版本 Gitea 的权限限制),
|
||||
# 在仓库 Settings → Actions → Secrets 里加一个 RELEASE_TOKEN
|
||||
api_key: '${{ secrets.RELEASE_TOKEN || github.token }}'
|
||||
files: |-
|
||||
patchbay.tar.gz
|
||||
version.txt
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user