Skip to content

feature/cli optimize #166

feature/cli optimize

feature/cli optimize #166

Workflow file for this run

#!#
# Copyright (c) 2025 Hangzhou Guanwaii Technology Co,.Ltd.
#
# This source code is licensed under the MIT License,
# which is located in the LICENSE file in the source tree's root directory.
#
# File: rust.yml
# Author: mingcheng <[email protected]>
# File Created: 2025-03-05 11:10:40
#
# Modified By: mingcheng <[email protected]>
# Last Modified: 2025-10-16 16:37:42
##
name: Cargo Build & Test
on:
push:
branches:
- main
- master
- develop
- "feature/**"
pull_request:
branches:
- main
- master
- develop
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
# Code quality checks (clippy and rustfmt)
lint:
name: Lint (clippy & rustfmt)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Cache target directory
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-target-lint-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-target-lint-
- name: Run cargo fmt check
run: cargo fmt --all -- --check
- name: Run cargo clippy
run: cargo clippy --all-targets --all-features -- -D warnings
# Security audit
security_audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-audit
run: cargo install cargo-audit --locked
- name: Run cargo audit
run: cargo audit
# Build and test on stable/beta/nightly
build_and_test:
name: Build & Test (${{ matrix.toolchain }})
runs-on: ubuntu-latest
needs: [lint]
strategy:
fail-fast: false
matrix:
toolchain:
- stable
- beta
- nightly
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust toolchain (${{ matrix.toolchain }})
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Cache target directory
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-target-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-target-${{ matrix.toolchain }}-
- name: Show Rust version
run: |
rustc --version
cargo --version
- name: Build project
run: cargo build --verbose --all-features
- name: Run tests
run: cargo test --verbose --all-features
- name: Build release
run: cargo build --release --verbose
# Check documentation builds
doc:
name: Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build documentation
run: cargo doc --no-deps --all-features
env:
RUSTDOCFLAGS: -D warnings