| name | github-workflows |
| description | Diagnose, fix, and optimize GitHub Actions workflows for Rust projects. Use when setting up CI/CD, troubleshooting workflow failures, optimizing build times with caching, or ensuring best practices for testing, linting, and releases. |
GitHub Workflows
Diagnose, fix, and optimize GitHub Actions workflows for Rust projects.
Purpose
Set up robust CI/CD pipelines for Rust projects with proper caching, testing, linting, and release automation.
Before Making Changes: Verify Current State
ALWAYS start by checking the current workflow configuration before making any changes:
1. Get Repository Information
gh repo view --json nameWithOwner,owner,name
2. List Existing Workflows
gh workflow list
gh workflow view <workflow-name>
3. Check Recent Workflow Runs
gh run list --limit 10
gh run view <run-id>
gh run view <run-id> --log
4. Check Existing Workflow Files
ls -la .github/workflows/
cat .github/workflows/*.yml
5. Check for Existing Issues
gh issue list --label ci --label github-actions --label workflow
Only after understanding the current state should you suggest changes or additions.
Quick Reference
- Caching Strategies - Manual cache, rust-cache, sccache, cache keys
- Troubleshooting - Common issues, debugging, fixes
- Advanced Features - Coverage, security, benchmarking, quality gates, docs deployment
- Release Management - Automated releases, versioning, changelog generation, crates.io publishing
Complete Rust CI Workflow (2025)
name: Rust CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Run cargo check
run: cargo check --all --verbose
fmt:
name: Format
runs-on: ubuntu-latest
steps:
- uses:
[, , ]
[]
Quick Start Workflows
Minimal CI (Quick Feedback)
name: Quick CI
on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo check --all
- run: cargo fmt -- --check
- run: cargo clippy -- -D warnings
- run: cargo test --all
Project-Specific: Self-Learning Memory CI
name: Self-Learning Memory CI
on:
push:
branches: [main]
pull_request:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo check --all --verbose
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt -- --check
clippy:
runs-on: ubuntu-latest
[, ]
Common Tasks
Setup Rust Toolchain
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.75.0
Cache Dependencies
- uses: Swatinem/rust-cache@v2
with:
shared-key: "stable"
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
save-always: true
See caching-strategies.md for detailed caching options.
Run Tests
- run: cargo test --all
- run: cargo test --all --verbose
- run: cargo test --all-features
- run: RUST_BACKTRACE=1 cargo test --all
- run: cargo test --all -- --test-threads=1
Build Project
- run: cargo build --all
- run: cargo build --release --all
- run: cargo build --release --timings
Lint and Format
Using cargo-llvm-cov (Recommended)
- name: Install llvm-cov
run: cargo install cargo-llvm-cov
- name: Generate coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
- name: Upload to Codecov
uses: codecov/codecov-action@v4
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
Alternative: Generate multiple formats
- name: Install llvm-cov
run: cargo install cargo-llvm-cov
- name: Generate coverage (HTML + LCOV)
run: |
cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
cargo llvm-cov --all-features --workspace --html --output-dir coverage
- run: cargo clippy --fix
Best Practices (2025)
DO:
✓ Use actions/cache@v4 with save-always: true
✓ Use hashFiles('**/Cargo.lock') for cache keys
✓ Implement restore-keys for cache fallback
✓ Use dtolnay/rust-toolchain (not deprecated actions-rs)
✓ Split large caches to avoid 2GB limit
✓ Test on multiple platforms (matrix)
✓ Use Swatinem/rust-cache@v2 for simplicity
✓ Cache both registry and target directory
✓ Set CARGO_TERM_COLOR: always for readable logs
✓ Use continue-on-error for experimental builds
DON'T:
✗ Use deprecated actions-rs/* actions
✗ Create monolithic cache entries >2GB
✗ Cache without restore-keys
✗ Forget save-always: true for partial builds
✗ Cache target/ across different jobs without unique keys
✗ Run expensive operations on every PR
✗ Use actions/cache@v3 and @v4 inconsistently
✗ Hardcode Rust version (use rust-toolchain file)
Common Issues
Quick reference - see troubleshooting.md for full details:
- Cache not saved on failure → Use
save-always: true
- Cache key mismatch → Use
hashFiles() and restore-keys
- Deprecated actions-rs → Use
dtolnay/rust-toolchain
- tar creation errors → Use
rust-cache or exclude problematic paths
- Files >2GB → Split into smaller caches
- Workflow permissions → Set
permissions: in workflow
- Flaky tests → Add retries with
nick-fields/retry@v2
Detailed Documentation
Integration with Project
Before suggesting workflow changes:
- Run
gh repo view --json nameWithOwner,owner,name to get actual repo info
- Use the actual owner/repo names in all workflow examples
- Check existing workflows with
gh workflow list
- Review current workflow files in
.github/workflows/
For this project (d-o-hub/rust-self-learning-memory):
- The workflows ensure all
memory-core, memory-storage-turso, and memory-storage-redb crates are tested across platforms
- Quality gates enforce 90% code coverage threshold
- Benchmarks track performance regressions
- Supply chain security with cargo-deny and cargo-audit
Quick Checklist
Before committing workflow changes: