-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (96 loc) · 3.64 KB
/
Copy pathrelease.yml
File metadata and controls
112 lines (96 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Release
# 两种触发方式:
# 1) 打 tag(v 开头)自动构建并发布 Release;
# 2) 在 Actions 页手动触发(workflow_dispatch),输入版本号 → 构建并创建对应 Release。
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
version:
description: "版本号(如 v0.1.1),将作为 Release tag 与包名"
required: true
type: string
permissions:
contents: write # 发布 Release / 创建 tag 需要
env:
# tag 触发用 tag 名;手动触发用输入的版本号。
VERSION: ${{ github.event.inputs.version || github.ref_name }}
jobs:
package:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-musl
arch: x86_64
- target: aarch64-unknown-linux-musl
arch: arm64
steps:
- uses: actions/checkout@v4
# ---- 前端:admin / portal(与架构无关,每个 target 各构建一次)----
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Build admin frontend
working-directory: frontend/admin
run: npm ci && npm run build
- name: Build portal frontend
working-directory: frontend/portal
run: npm ci && npm run build
# ---- 后端:Rust release 二进制(musl 静态链接,兼容老 glibc 系统)----
# 用 cross(docker)编译:x86_64 与 aarch64 的 musl 工具链 + C 交叉编译(bundled sqlite)全自动处理。
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross --locked
- name: Build backend
run: cross build --release --locked --target ${{ matrix.target }}
- name: Verify static binary
run: file "target/${{ matrix.target }}/release/runapi"
# ---- 组装产物 ----
# 运行时路径(均相对工作目录):
# ./runapi ./config/default.toml ./frontend/{admin,portal}/dist
- name: Assemble package
run: |
PKG="runapi-${VERSION}-linux-${{ matrix.arch }}"
mkdir -p "dist/${PKG}/config" \
"dist/${PKG}/frontend/admin" \
"dist/${PKG}/frontend/portal"
cp "target/${{ matrix.target }}/release/runapi" "dist/${PKG}/"
cp config/default.toml "dist/${PKG}/config/"
cp -r frontend/admin/dist "dist/${PKG}/frontend/admin/dist"
cp -r frontend/portal/dist "dist/${PKG}/frontend/portal/dist"
# 部署脚本 + systemd 模板放到包根目录
install -m 0755 deploy/install.sh "dist/${PKG}/install.sh"
cp deploy/runapi.service "dist/${PKG}/runapi.service"
tar -C dist -czf "${PKG}.tar.gz" "${PKG}"
echo "PKG=${PKG}" >> "$GITHUB_ENV"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PKG }}
path: ${{ env.PKG }}.tar.gz
# ---- 汇总两个架构的包,创建 / 更新 Release ----
release:
needs: package
runs-on: ubuntu-latest
steps:
- name: Download all packages
uses: actions/download-artifact@v4
with:
path: dist
- name: Publish release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.VERSION }} # tag 不存在时按当前提交自动创建
name: ${{ env.VERSION }}
files: dist/**/*.tar.gz