Release #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |