85 lines
3.4 KiB
YAML
85 lines
3.4 KiB
YAML
name: Rust Cross-Compile and Release
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
tags:
|
|
- 'v*.*.*' # 当有形如 v1.0.0 的标签被推送到仓库时触发此工作流
|
|
|
|
|
|
jobs:
|
|
build_and_release:
|
|
runs-on: ubuntu-latest # 在最新的 Ubuntu 环境中运行
|
|
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 安装 Rust 工具链
|
|
uses: dtolnay/rust-toolchain@stable # 使用 dtolnay/rust-toolchain 动作安装稳定版 Rust
|
|
with:
|
|
toolchain: stable
|
|
target: |
|
|
x86_64-unknown-linux-gnu
|
|
x86_64-pc-windows-gnu
|
|
|
|
- name: 换源
|
|
run: |
|
|
tee /etc/apt/sources.list << EOF
|
|
deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
|
|
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
|
|
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
|
|
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
|
|
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
|
|
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
|
|
#deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
|
|
#deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
|
|
EOF
|
|
|
|
- name: 安装 Windows 交叉编译所需的 MinGW-w64 工具链 (GCC for Windows)
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y mingw-w64
|
|
|
|
- name: 为 Linux 编译 (release)
|
|
run: cargo build --release --target x86_64-unknown-linux-gnu
|
|
# 可执行文件会位于 target/x86_64-unknown-linux-gnu/release/ 目录下
|
|
|
|
- name: 为 Windows 编译 (release)
|
|
run: cargo build --release --target x86_64-pc-windows-gnu
|
|
# 可执行文件会位于 target/x86_64-pc-windows-gnu/release/ 目录下
|
|
|
|
- name: 查找编译后的可执行文件名称
|
|
id: get_bin_name
|
|
run: |
|
|
BIN_NAME=$(grep '^name =' Cargo.toml | head -1 | cut -d '=' -f 2 | tr -d '[:space:]"')
|
|
echo "Detected binary name: $BIN_NAME"
|
|
echo "linux_bin=${BIN_NAME}" >> $GITEA_OUTPUT
|
|
echo "windows_bin=${BIN_NAME}.exe" >> $GITEA_OUTPUT
|
|
|
|
- name: 上传 Linux 编译产物为工作流 Artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: linux-build
|
|
path: target/x86_64-unknown-linux-gnu/release/${{ steps.get_bin_name.outputs.linux_bin }}
|
|
|
|
- name: 上传 Windows 编译产物为工作流 Artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: windows-build
|
|
path: target/x86_64-pc-windows-gnu/release/${{ steps.get_bin_name.outputs.windows_bin }}
|
|
|
|
- name: 创建 Gitea Release 并上传产物
|
|
uses: softprops/action-gh-release@v1 # 这是一个通用的 GitHub/Gitea Release 动作
|
|
if: startsWith(github.ref, 'refs/tags/') # 确保只在标签推送时创建 Release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} # 使用 Gitea 提供的 TOKEN 环境变量
|
|
with:
|
|
tag_name: ${{ github.ref_name }} # 使用推送到仓库的标签名作为 Release 标签
|
|
name: Release ${{ github.ref_name }}
|
|
draft: false # 是否为草稿 Release
|
|
prerelease: false # 是否为预发布 Release
|
|
files: |
|
|
target/x86_64-unknown-linux-gnu/release/${{ steps.get_bin_name.outputs.linux_bin }}
|
|
target/x86_64-pc-windows-gnu/release/${{ steps.get_bin_name.outputs.windows_bin }}
|