|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + RUST_BACKTRACE: 1 |
| 12 | + |
| 13 | +jobs: |
| 14 | + test: |
| 15 | + name: Test |
| 16 | + runs-on: ${{ matrix.os }} |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 20 | + rust: [stable, nightly] |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Install Rust |
| 25 | + uses: dtolnay/rust-toolchain@master |
| 26 | + with: |
| 27 | + toolchain: ${{ matrix.rust }} |
| 28 | + |
| 29 | + - name: Cache cargo registry |
| 30 | + uses: actions/cache@v4 |
| 31 | + with: |
| 32 | + path: ~/.cargo/registry |
| 33 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 34 | + |
| 35 | + - name: Cache cargo index |
| 36 | + uses: actions/cache@v4 |
| 37 | + with: |
| 38 | + path: ~/.cargo/git |
| 39 | + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} |
| 40 | + |
| 41 | + - name: Cache cargo build |
| 42 | + uses: actions/cache@v4 |
| 43 | + with: |
| 44 | + path: target |
| 45 | + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} |
| 46 | + |
| 47 | + - name: Run tests |
| 48 | + run: cargo test --verbose |
| 49 | + |
| 50 | + - name: Run doc tests |
| 51 | + run: cargo test --doc |
| 52 | + |
| 53 | + fmt: |
| 54 | + name: Rustfmt |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Install Rust |
| 60 | + uses: dtolnay/rust-toolchain@stable |
| 61 | + with: |
| 62 | + components: rustfmt |
| 63 | + |
| 64 | + - name: Check formatting |
| 65 | + run: cargo fmt --all -- --check |
| 66 | + |
| 67 | + clippy: |
| 68 | + name: Clippy |
| 69 | + runs-on: ubuntu-latest |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Install Rust |
| 74 | + uses: dtolnay/rust-toolchain@stable |
| 75 | + with: |
| 76 | + components: clippy |
| 77 | + |
| 78 | + - name: Run clippy |
| 79 | + run: cargo clippy --all-targets --all-features -- -D warnings |
| 80 | + |
| 81 | + coverage: |
| 82 | + name: Code Coverage |
| 83 | + runs-on: ubuntu-latest |
| 84 | + steps: |
| 85 | + - uses: actions/checkout@v4 |
| 86 | + |
| 87 | + - name: Install Rust |
| 88 | + uses: dtolnay/rust-toolchain@stable |
| 89 | + |
| 90 | + - name: Install tarpaulin |
| 91 | + run: cargo install cargo-tarpaulin |
| 92 | + |
| 93 | + - name: Generate coverage |
| 94 | + run: cargo tarpaulin --verbose --all-features --workspace --timeout 120 --out Xml |
| 95 | + |
| 96 | + - name: Upload coverage to Codecov |
| 97 | + uses: codecov/codecov-action@v4 |
| 98 | + with: |
| 99 | + files: ./cobertura.xml |
| 100 | + fail_ci_if_error: false |
| 101 | + |
| 102 | + benchmark: |
| 103 | + name: Benchmark |
| 104 | + runs-on: ubuntu-latest |
| 105 | + steps: |
| 106 | + - uses: actions/checkout@v4 |
| 107 | + |
| 108 | + - name: Install Rust |
| 109 | + uses: dtolnay/rust-toolchain@stable |
| 110 | + |
| 111 | + - name: Create benchmark directory |
| 112 | + run: mkdir -p benches |
| 113 | + |
| 114 | + - name: Create placeholder benchmark |
| 115 | + run: | |
| 116 | + cat > benches/graph_benchmarks.rs << 'EOF' |
| 117 | + use criterion::{criterion_group, criterion_main, Criterion}; |
| 118 | + use codegraph::{CodeGraph, Node, NodeType, Edge, EdgeType}; |
| 119 | +
|
| 120 | + fn node_operations(c: &mut Criterion) { |
| 121 | + c.bench_function("node_creation", |b| { |
| 122 | + b.iter(|| { |
| 123 | + Node::new(NodeType::Function) |
| 124 | + }) |
| 125 | + }); |
| 126 | + } |
| 127 | +
|
| 128 | + fn graph_operations(c: &mut Criterion) { |
| 129 | + c.bench_function("add_node", |b| { |
| 130 | + b.iter(|| { |
| 131 | + let mut graph = CodeGraph::in_memory().unwrap(); |
| 132 | + let node = Node::new(NodeType::Function); |
| 133 | + graph.add_node(node).unwrap(); |
| 134 | + }) |
| 135 | + }); |
| 136 | + } |
| 137 | +
|
| 138 | + criterion_group!(benches, node_operations, graph_operations); |
| 139 | + criterion_main!(benches); |
| 140 | + EOF |
| 141 | + |
| 142 | + - name: Update Cargo.toml |
| 143 | + run: | |
| 144 | + cat >> Cargo.toml << 'EOF' |
| 145 | +
|
| 146 | + [[bench]] |
| 147 | + name = "graph_benchmarks" |
| 148 | + harness = false |
| 149 | + EOF |
| 150 | + |
| 151 | + - name: Run benchmarks |
| 152 | + run: cargo bench --no-fail-fast |
| 153 | + |
| 154 | + - name: Archive benchmark results |
| 155 | + uses: actions/upload-artifact@v4 |
| 156 | + with: |
| 157 | + name: benchmark-results |
| 158 | + path: target/criterion/ |
| 159 | + |
| 160 | + docs: |
| 161 | + name: Documentation |
| 162 | + runs-on: ubuntu-latest |
| 163 | + steps: |
| 164 | + - uses: actions/checkout@v4 |
| 165 | + |
| 166 | + - name: Install Rust |
| 167 | + uses: dtolnay/rust-toolchain@stable |
| 168 | + |
| 169 | + - name: Check documentation |
| 170 | + run: cargo doc --no-deps --all-features |
| 171 | + env: |
| 172 | + RUSTDOCFLAGS: -D warnings |
0 commit comments