chore: update ci #12
This file contains 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: CI | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
branches: [ "main" ] | ||
permissions: | ||
contents: write | ||
packages: write | ||
pull-requests: write | ||
env: | ||
CARGO_TERM_COLOR: always | ||
BINARY_NAME: sys-overseer | ||
jobs: | ||
build:2 | ||
name: Build ${{ matrix.target }} | ||
strategy: | ||
matrix: | ||
include: | ||
# Linux x86_64 构建 | ||
- target: x86_64-linux-gnu | ||
os: ubuntu-latest | ||
# Linux ARM64 构建 | ||
- target: aarch64-linux-gnu | ||
os: ubuntu-latest | ||
cross: true | ||
# Linux ARM v7 构建 | ||
- target: armv7-linux-gnueabihf | ||
os: ubuntu-latest | ||
cross: true | ||
# macOS Intel 构建 | ||
- target: x86_64-apple-darwin | ||
os: macos-latest | ||
# macOS ARM 构建 | ||
- target: aarch64-apple-darwin | ||
os: macos-latest | ||
# Windows 构建 | ||
- target: x86_64-pc-windows-gnu | ||
os: windows-latest | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
# 使用 cross 工具来处理交叉编译 | ||
- name: Install cross | ||
if: matrix.cross | ||
run: cargo install cross | ||
- name: Install Rust | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
targets: ${{ matrix.target }} | ||
# 根据是否需要交叉编译选择不同的构建命令 | ||
- name: Build Binary | ||
run: | | ||
if [ "${{ matrix.cross }}" = "true" ]; then | ||
cross build --verbose --release --target ${{ matrix.target }} | ||
else | ||
cargo build --verbose --release --target ${{ matrix.target }} | ||
fi | ||
shell: bash | ||
# 创建发布包 | ||
- name: Package Binary | ||
shell: bash | ||
run: | | ||
mkdir -p releases | ||
if [[ "${{ matrix.target }}" == *"windows"* ]]; then | ||
BINARY_SUFFIX=".exe" | ||
else | ||
BINARY_SUFFIX="" | ||
fi | ||
cp "target/${{ matrix.target }}/release/$BINARY_NAME$BINARY_SUFFIX" \ | ||
"releases/$BINARY_NAME-${{ matrix.target }}$BINARY_SUFFIX" | ||
if [[ "${{ matrix.target }}" == *"linux"* ]] || [[ "${{ matrix.target }}" == *"apple-darwin"* ]]; then | ||
chmod +x "releases/$BINARY_NAME-${{ matrix.target }}$BINARY_SUFFIX" | ||
fi | ||
cd releases | ||
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then | ||
7z a "$BINARY_NAME-${{ matrix.target }}.zip" "$BINARY_NAME-${{ matrix.target }}$BINARY_SUFFIX" | ||
else | ||
tar czf "$BINARY_NAME-${{ matrix.target }}.tar.gz" "$BINARY_NAME-${{ matrix.target }}$BINARY_SUFFIX" | ||
fi | ||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ matrix.target }} | ||
path: releases/* | ||
- name: Create Release | ||
if: startsWith(github.ref, 'refs/tags/') | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: releases/* | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
test: | ||
name: Run Tests | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install Rust | ||
uses: dtolnay/rust-toolchain@stable | ||
- name: Run tests | ||
run: cargo test --verbose |