/ .github / workflows / ci.yml
ci.yml
  1  # ADnet Core Continuous Integration
  2  #
  3  # Runs on:
  4  #   - Push to main/develop branches
  5  #   - Pull requests to main/develop
  6  #
  7  # Jobs:
  8  #   - Build: Compile all packages
  9  #   - Test: Run all tests
 10  #   - Lint: Run clippy and rustfmt
 11  
 12  name: CI
 13  
 14  on:
 15    push:
 16      branches: [main, develop]
 17    pull_request:
 18      branches: [main, develop]
 19  
 20  env:
 21    CARGO_TERM_COLOR: always
 22    RUST_BACKTRACE: 1
 23  
 24  jobs:
 25    # ==========================================================================
 26    # Build Job
 27    # ==========================================================================
 28    build:
 29      name: Build
 30      runs-on: ubuntu-latest
 31      timeout-minutes: 30
 32  
 33      steps:
 34        - name: Checkout
 35          uses: actions/checkout@v4
 36  
 37        - name: Install system dependencies
 38          run: |
 39            sudo apt-get update
 40            sudo apt-get install -y \
 41              build-essential \
 42              pkg-config \
 43              libssl-dev
 44  
 45        - name: Setup Rust toolchain
 46          uses: dtolnay/rust-toolchain@stable
 47          with:
 48            components: rustfmt, clippy
 49  
 50        - name: Cache cargo registry
 51          uses: actions/cache@v4
 52          with:
 53            path: |
 54              ~/.cargo/registry
 55              ~/.cargo/git
 56            key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
 57            restore-keys: |
 58              ${{ runner.os }}-cargo-registry-
 59  
 60        - name: Cache cargo build
 61          uses: actions/cache@v4
 62          with:
 63            path: target
 64            key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
 65            restore-keys: |
 66              ${{ runner.os }}-cargo-build-
 67  
 68        - name: Build all packages
 69          run: cargo build --release --workspace
 70  
 71    # ==========================================================================
 72    # Test Job
 73    # ==========================================================================
 74    test:
 75      name: Test
 76      runs-on: ubuntu-latest
 77      timeout-minutes: 20
 78      needs: build
 79  
 80      steps:
 81        - name: Checkout
 82          uses: actions/checkout@v4
 83  
 84        - name: Install system dependencies
 85          run: |
 86            sudo apt-get update
 87            sudo apt-get install -y \
 88              build-essential \
 89              pkg-config \
 90              libssl-dev
 91  
 92        - name: Setup Rust toolchain
 93          uses: dtolnay/rust-toolchain@stable
 94  
 95        - name: Cache cargo
 96          uses: actions/cache@v4
 97          with:
 98            path: |
 99              ~/.cargo/registry
100              ~/.cargo/git
101              target
102            key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
103            restore-keys: |
104              ${{ runner.os }}-cargo-test-
105  
106        - name: Run tests
107          run: cargo test --workspace --release
108  
109    # ==========================================================================
110    # Lint Job
111    # ==========================================================================
112    lint:
113      name: Lint
114      runs-on: ubuntu-latest
115      timeout-minutes: 15
116  
117      steps:
118        - name: Checkout
119          uses: actions/checkout@v4
120  
121        - name: Install system dependencies
122          run: |
123            sudo apt-get update
124            sudo apt-get install -y \
125              build-essential \
126              pkg-config \
127              libssl-dev
128  
129        - name: Setup Rust toolchain
130          uses: dtolnay/rust-toolchain@stable
131          with:
132            components: rustfmt, clippy
133  
134        - name: Cache cargo
135          uses: actions/cache@v4
136          with:
137            path: |
138              ~/.cargo/registry
139              ~/.cargo/git
140              target
141            key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
142            restore-keys: |
143              ${{ runner.os }}-cargo-lint-
144  
145        - name: Install nightly for rustfmt
146          run: rustup toolchain install nightly --component rustfmt
147  
148        - name: Check formatting
149          run: cargo +nightly fmt --all -- --check
150  
151        - name: Run Clippy
152          run: cargo clippy --workspace --all-targets -- -D warnings