Skip to content

chore: update ci

chore: update ci #9

Workflow file for this run

name: CI
on:
push:
branches: [ "main" ]
tags:
- 'v*' # 当推送版本标签时触发,如 v1.0.0
pull_request:
branches: [ "main" ]
permissions:
contents: write # 这给予了创建 release 的权限
packages: write
pull-requests: write
env:
CARGO_TERM_COLOR: always
BINARY_NAME: sys-overseer
jobs:
build:
name: Build ${{ matrix.target }}
strategy:
matrix:
include:
# Linux x86_64 构建
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
# Linux ARM64 构建
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
# Linux ARM v7 构建
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-latest
# macOS Intel 构建
- target: x86_64-apple-darwin
os: macos-latest
# macOS ARM (M1/M2) 构建
- 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
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
# 为 Linux ARM 目标安装必要的依赖
- name: Install ARM dependencies
if: contains(matrix.target, 'arm')
run: |
sudo apt-get update
sudo apt-get install -y gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu
- name: Build Binary
run: |
cargo build --verbose --release --target ${{ matrix.target }}
# 创建发布包
- 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