workflows
This commit is contained in:
70
.github/workflows/gitea.yml
vendored
Normal file
70
.github/workflows/gitea.yml
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
name: Rust Cross-Compile and Release
|
||||
|
||||
on:
|
||||
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 # 默认的 Linux 目标
|
||||
x86_64-pc-windows-gnu # Windows 交叉编译目标
|
||||
|
||||
- name: 安装 Windows 交叉编译所需的 MinGW-w64 工具链 (GCC for Windows)
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo 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@v4
|
||||
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@v4
|
||||
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@v2 # 这是一个通用的 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 }}
|
||||
Reference in New Issue
Block a user