|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master, ci-integration ] |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + RUST_BACKTRACE: 1 |
| 12 | + |
| 13 | +jobs: |
| 14 | + # Quick checks on Linux |
| 15 | + checks: |
| 16 | + name: Checks (Format, Lint, Security) |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Install Rust nightly |
| 22 | + uses: dtolnay/rust-toolchain@nightly |
| 23 | + with: |
| 24 | + components: rustfmt, clippy |
| 25 | + |
| 26 | + - name: Cache cargo registry |
| 27 | + uses: actions/cache@v4 |
| 28 | + with: |
| 29 | + path: ~/.cargo/registry |
| 30 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 31 | + |
| 32 | + - name: Cache cargo index |
| 33 | + uses: actions/cache@v4 |
| 34 | + with: |
| 35 | + path: ~/.cargo/git |
| 36 | + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} |
| 37 | + |
| 38 | + - name: Cache target directory |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: target |
| 42 | + key: ${{ runner.os }}-target-checks-${{ hashFiles('**/Cargo.lock') }} |
| 43 | + |
| 44 | + - name: Check formatting |
| 45 | + run: cargo fmt --all -- --check |
| 46 | + |
| 47 | + - name: Run clippy |
| 48 | + run: cargo clippy --workspace --all-targets -- -D warnings |
| 49 | + |
| 50 | + - name: Security audit |
| 51 | + run: | |
| 52 | + cargo install cargo-audit --locked || true |
| 53 | + cargo audit |
| 54 | +
|
| 55 | + # Tests on Linux only (most comprehensive) |
| 56 | + test: |
| 57 | + name: Test Suite |
| 58 | + runs-on: ubuntu-latest |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v4 |
| 61 | + |
| 62 | + - name: Install Rust nightly |
| 63 | + uses: dtolnay/rust-toolchain@nightly |
| 64 | + |
| 65 | + - name: Cache cargo registry |
| 66 | + uses: actions/cache@v4 |
| 67 | + with: |
| 68 | + path: ~/.cargo/registry |
| 69 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 70 | + |
| 71 | + - name: Cache cargo index |
| 72 | + uses: actions/cache@v4 |
| 73 | + with: |
| 74 | + path: ~/.cargo/git |
| 75 | + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} |
| 76 | + |
| 77 | + - name: Cache target directory |
| 78 | + uses: actions/cache@v4 |
| 79 | + with: |
| 80 | + path: target |
| 81 | + key: ${{ runner.os }}-target-test-${{ hashFiles('**/Cargo.lock') }} |
| 82 | + |
| 83 | + - name: Run tests |
| 84 | + run: cargo test --workspace |
| 85 | + timeout-minutes: 30 |
| 86 | + |
| 87 | + # Multi-platform builds |
| 88 | + build: |
| 89 | + name: Build - ${{ matrix.target }} |
| 90 | + runs-on: ${{ matrix.os }} |
| 91 | + strategy: |
| 92 | + fail-fast: false |
| 93 | + matrix: |
| 94 | + include: |
| 95 | + # Linux x86_64 |
| 96 | + - os: ubuntu-latest |
| 97 | + target: x86_64-unknown-linux-gnu |
| 98 | + cross: false |
| 99 | + features: simd |
| 100 | + opencl: false |
| 101 | + |
| 102 | + # Linux x86_64 with OpenCL |
| 103 | + - os: ubuntu-latest |
| 104 | + target: x86_64-unknown-linux-gnu |
| 105 | + cross: false |
| 106 | + features: simd,opencl |
| 107 | + opencl: true |
| 108 | + |
| 109 | + # Linux ARM64 |
| 110 | + - os: ubuntu-latest |
| 111 | + target: aarch64-unknown-linux-gnu |
| 112 | + cross: true |
| 113 | + features: "" |
| 114 | + opencl: false |
| 115 | + |
| 116 | + # Windows x86_64 |
| 117 | + - os: windows-latest |
| 118 | + target: x86_64-pc-windows-msvc |
| 119 | + cross: false |
| 120 | + features: simd |
| 121 | + opencl: false |
| 122 | + |
| 123 | + # macOS x86_64 |
| 124 | + - os: macos-13 |
| 125 | + target: x86_64-apple-darwin |
| 126 | + cross: false |
| 127 | + features: simd |
| 128 | + opencl: false |
| 129 | + |
| 130 | + # macOS x86_64 with OpenCL |
| 131 | + - os: macos-13 |
| 132 | + target: x86_64-apple-darwin |
| 133 | + cross: false |
| 134 | + features: simd,opencl |
| 135 | + opencl: true |
| 136 | + |
| 137 | + # macOS ARM64 (Apple Silicon) |
| 138 | + - os: macos-14 |
| 139 | + target: aarch64-apple-darwin |
| 140 | + cross: false |
| 141 | + features: "" |
| 142 | + opencl: false |
| 143 | + |
| 144 | + # macOS ARM64 with OpenCL |
| 145 | + - os: macos-14 |
| 146 | + target: aarch64-apple-darwin |
| 147 | + cross: false |
| 148 | + features: opencl |
| 149 | + opencl: true |
| 150 | + |
| 151 | + steps: |
| 152 | + - uses: actions/checkout@v4 |
| 153 | + |
| 154 | + - name: Install Rust nightly |
| 155 | + uses: dtolnay/rust-toolchain@nightly |
| 156 | + with: |
| 157 | + targets: ${{ matrix.target }} |
| 158 | + |
| 159 | + - name: Cache cargo registry |
| 160 | + uses: actions/cache@v4 |
| 161 | + with: |
| 162 | + path: ~/.cargo/registry |
| 163 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 164 | + |
| 165 | + - name: Cache cargo index |
| 166 | + uses: actions/cache@v4 |
| 167 | + with: |
| 168 | + path: ~/.cargo/git |
| 169 | + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} |
| 170 | + |
| 171 | + - name: Cache target directory |
| 172 | + uses: actions/cache@v4 |
| 173 | + with: |
| 174 | + path: target |
| 175 | + key: ${{ runner.os }}-${{ matrix.target }}-target-build-${{ hashFiles('**/Cargo.lock') }} |
| 176 | + |
| 177 | + - name: Install cross-compilation tools |
| 178 | + if: matrix.cross |
| 179 | + run: | |
| 180 | + cargo install cross --git https://github.com/cross-rs/cross --locked || true |
| 181 | +
|
| 182 | + - name: Install OpenCL headers (Linux) |
| 183 | + if: matrix.opencl && runner.os == 'Linux' |
| 184 | + run: | |
| 185 | + sudo apt-get update |
| 186 | + sudo apt-get install -y ocl-icd-opencl-dev |
| 187 | +
|
| 188 | + - name: Build binaries |
| 189 | + run: | |
| 190 | + FEATURES_FLAG="" |
| 191 | + if [ -n "${{ matrix.features }}" ]; then |
| 192 | + FEATURES_FLAG="--no-default-features --features ${{ matrix.features }}" |
| 193 | + else |
| 194 | + FEATURES_FLAG="--no-default-features" |
| 195 | + fi |
| 196 | +
|
| 197 | + if [ "${{ matrix.cross }}" = "true" ]; then |
| 198 | + cross build --release --target ${{ matrix.target }} \ |
| 199 | + -p pocx_miner \ |
| 200 | + -p pocx_plotter \ |
| 201 | + -p pocx_verifier \ |
| 202 | + -p pocx_mockchain \ |
| 203 | + $FEATURES_FLAG |
| 204 | + else |
| 205 | + cargo build --release --target ${{ matrix.target }} \ |
| 206 | + -p pocx_miner \ |
| 207 | + -p pocx_plotter \ |
| 208 | + -p pocx_verifier \ |
| 209 | + -p pocx_mockchain \ |
| 210 | + $FEATURES_FLAG |
| 211 | + fi |
| 212 | + shell: bash |
| 213 | + timeout-minutes: 60 |
| 214 | + |
| 215 | + - name: Prepare artifacts (Unix) |
| 216 | + if: runner.os != 'Windows' |
| 217 | + run: | |
| 218 | + mkdir -p artifacts |
| 219 | + SUFFIX="" |
| 220 | + if [ "${{ matrix.opencl }}" = "true" ]; then |
| 221 | + SUFFIX="-opencl" |
| 222 | + fi |
| 223 | + cp target/${{ matrix.target }}/release/pocx_miner artifacts/pocx_miner-${{ matrix.target }}${SUFFIX} |
| 224 | + cp target/${{ matrix.target }}/release/pocx_plotter artifacts/pocx_plotter-${{ matrix.target }}${SUFFIX} |
| 225 | + cp target/${{ matrix.target }}/release/pocx_verifier artifacts/pocx_verifier-${{ matrix.target }}${SUFFIX} |
| 226 | + cp target/${{ matrix.target }}/release/pocx_mockchain artifacts/pocx_mockchain-${{ matrix.target }}${SUFFIX} |
| 227 | + chmod +x artifacts/* |
| 228 | +
|
| 229 | + - name: Prepare artifacts (Windows) |
| 230 | + if: runner.os == 'Windows' |
| 231 | + run: | |
| 232 | + mkdir artifacts |
| 233 | + cp target/${{ matrix.target }}/release/pocx_miner.exe artifacts/pocx_miner-${{ matrix.target }}.exe |
| 234 | + cp target/${{ matrix.target }}/release/pocx_plotter.exe artifacts/pocx_plotter-${{ matrix.target }}.exe |
| 235 | + cp target/${{ matrix.target }}/release/pocx_verifier.exe artifacts/pocx_verifier-${{ matrix.target }}.exe |
| 236 | + cp target/${{ matrix.target }}/release/pocx_mockchain.exe artifacts/pocx_mockchain-${{ matrix.target }}.exe |
| 237 | + shell: bash |
| 238 | + |
| 239 | + - name: Upload artifacts |
| 240 | + uses: actions/upload-artifact@v4 |
| 241 | + with: |
| 242 | + name: binaries-${{ matrix.target }}${{ matrix.opencl && '-opencl' || '' }} |
| 243 | + path: artifacts/* |
| 244 | + retention-days: 90 |
| 245 | + |
| 246 | + # Summary job |
| 247 | + ci-success: |
| 248 | + name: CI Success |
| 249 | + needs: [checks, test, build] |
| 250 | + runs-on: ubuntu-latest |
| 251 | + if: always() |
| 252 | + steps: |
| 253 | + - name: Check all jobs |
| 254 | + run: | |
| 255 | + if [ "${{ needs.checks.result }}" != "success" ] || \ |
| 256 | + [ "${{ needs.test.result }}" != "success" ] || \ |
| 257 | + [ "${{ needs.build.result }}" != "success" ]; then |
| 258 | + echo "One or more CI jobs failed" |
| 259 | + exit 1 |
| 260 | + fi |
| 261 | + echo "All CI jobs passed successfully!" |
0 commit comments