workflows

This commit is contained in:
Yakumo Hokori
2025-11-03 14:51:18 +08:00
parent 1beb64374d
commit 4cec61031e
3 changed files with 163 additions and 0 deletions

70
.github/workflows/gitea.yml vendored Normal file
View 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 }}

92
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,92 @@
name: Release
on:
push:
tags:
- "v*.*.*"
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
arch: [x86_64, aarch64]
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.arch }}-${{ matrix.os == 'windows-latest' && 'pc-windows-msvc' || matrix.os == 'macos-latest' && 'apple-darwin' || 'unknown-linux-gnu' }}
- name: Install cross-compilation dependencies
if: matrix.os == 'ubuntu-latest' && matrix.arch == 'aarch64'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross
- name: Build
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++
run: cargo build --release --target ${{ matrix.arch }}-${{ matrix.os == 'windows-latest' && 'pc-windows-msvc' || matrix.os == 'macos-latest' && 'apple-darwin' || 'unknown-linux-gnu' }}
- name: Prepare artifacts
shell: bash
run: |
mkdir -p artifacts
if [ "${{ matrix.os }}" == "windows-latest" ]; then
cp target/${{ matrix.arch }}-pc-windows-msvc/release/ccmk.exe artifacts/
else
cp target/${{ matrix.arch }}-${{ matrix.os == 'macos-latest' && 'apple-darwin' || 'unknown-linux-gnu' }}/release/ccmk artifacts/
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4.6.2
with:
name: ccmk-${{ matrix.os }}-${{ matrix.arch }}
path: artifacts/
release:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4.3.0
with:
path: artifacts
- name: Prepare release assets
shell: bash
run: |
mkdir -p release-assets
find artifacts -type f -name "ccmk*" | while read file; do
platform=$(echo $file | cut -d/ -f2 | sed 's/ccmk-//g')
if [[ $file == *".exe" ]]; then
cp "$file" "release-assets/ccmk-$platform.exe"
else
cp "$file" "release-assets/ccmk-$platform"
fi
done
- name: Create release
uses: softprops/action-gh-release@v1
with:
files: release-assets/*
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: |
CCMK Release ${{ github.ref_name }}
Automated release for CCMK project.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}