name: Pre-commit Quality Gate
on:
push:
branches-ignore: [ 'gh-pages' ] pull_request:
env:
CARGO_TERM_COLOR: always
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
quality-gate:
name: Quality Gate (Format โ Lint โ Test)
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: ๐จ Format code automatically
run: |
echo "::group::Formatting code"
cargo fmt --all
echo "::endgroup::"
- name: Check for formatting changes
id: format-changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
echo "Code was formatted automatically"
else
echo "changes=false" >> $GITHUB_OUTPUT
echo "Code was already properly formatted"
fi
- name: ๐ Run Clippy linting (strict)
run: |
echo "::group::Running Clippy"
cargo clippy --all-targets --all-features -- -D warnings
echo "::endgroup::"
- name: ๐งช Run all tests
run: |
echo "::group::Running test suite"
cargo test --verbose --all-features
echo "::endgroup::"
- name: ๐๏ธ Build in release mode
run: |
echo "::group::Building release"
cargo build --release --verbose
echo "::endgroup::"
- name: ๐ Check documentation
run: |
echo "::group::Checking documentation"
cargo doc --no-deps --all-features --document-private-items
echo "::endgroup::"
env:
RUSTDOCFLAGS: "-D warnings"
- name: ๐ Auto-commit formatting changes
if: steps.format-changes.outputs.changes == 'true' && github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
git commit -m "style: automatic code formatting [skip ci]
๐ค Generated with GitHub Actions
- cargo fmt applied automatically
- all tests passing โ
" || exit 0
- name: ๐ Push formatting changes
if: steps.format-changes.outputs.changes == 'true' && github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: โ
Quality Gate Summary
run: |
echo "::notice title=Quality Gate Passed::All quality checks passed successfully!"
echo "โ
Code formatting: OK"
echo "โ
Clippy linting: OK"
echo "โ
Test suite: OK"
echo "โ
Release build: OK"
echo "โ
Documentation: OK"
- name: โ Quality Gate Failed
if: failure()
run: |
echo "::error title=Quality Gate Failed::One or more quality checks failed!"
echo "โ Please fix the issues above before committing"
echo "๐ก Run locally: cargo fmt && cargo clippy -- -D warnings && cargo test"
exit 1
performance-check:
name: Performance Regression Check
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-bench-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-bench-
- name: ๐ Run benchmarks
run: |
echo "::group::Performance benchmarks"
cargo bench --verbose || echo "::warning::Benchmarks completed with warnings"
echo "::endgroup::"
continue-on-error: true