|
| 1 | +name: Rust bindings |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + release: |
| 8 | + types: [published] |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - "**" |
| 12 | + |
| 13 | +permissions: |
| 14 | + id-token: write |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + fuzz_targets: |
| 19 | + name: Run fuzzers |
| 20 | + runs-on: ubuntu-latest |
| 21 | + env: |
| 22 | + CARGO_PROFILE_RELEASE_LTO: false |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + - uses: dtolnay/rust-toolchain@nightly |
| 26 | + |
| 27 | + - name: Install cargo-fuzz |
| 28 | + run: cargo +nightly install cargo-fuzz |
| 29 | + |
| 30 | + - name: Cargo fuzz |
| 31 | + run: | |
| 32 | + cd rust-bindings |
| 33 | + cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=600 || exit 255" |
| 34 | +
|
| 35 | + build_crate: |
| 36 | + name: Build crate |
| 37 | + runs-on: ubuntu-latest |
| 38 | + strategy: |
| 39 | + fail-fast: false |
| 40 | + |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + fetch-depth: 0 |
| 45 | + |
| 46 | + - name: Set up Rust |
| 47 | + uses: dtolnay/rust-toolchain@stable |
| 48 | + with: |
| 49 | + components: rustfmt, clippy |
| 50 | + |
| 51 | + - name: Rustfmt |
| 52 | + run: cargo fmt -- --files-with-diff --check |
| 53 | + |
| 54 | + - name: Clippy |
| 55 | + run: cargo clippy |
| 56 | + |
| 57 | + - name: Tests |
| 58 | + run: cargo test && cargo test --release |
| 59 | + |
| 60 | + - name: Build |
| 61 | + run: cargo build --release |
| 62 | + |
| 63 | + - name: Prepare for publish |
| 64 | + run: | |
| 65 | + mkdir rust-bindings/cpp |
| 66 | + cp -r src lib tests uint128_t python-bindings c-bindings CMakeLists.txt rust-bindings/cpp |
| 67 | +
|
| 68 | + - name: Publish to crates.io (dry run) |
| 69 | + # We use `--allow-dirty` because the `cpp` folder is copied into the working directory. |
| 70 | + # This is necessary because the `cpp` folder is not part of the crate otherwise. |
| 71 | + run: cargo publish --dry-run -p chiapos --allow-dirty |
| 72 | + |
| 73 | + - name: Upload crate artifacts |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + with: |
| 76 | + name: crate |
| 77 | + path: ./target/package/*-*.crate |
| 78 | + |
| 79 | + - name: Set Env |
| 80 | + uses: Chia-Network/actions/setjobenv@main |
| 81 | + env: |
| 82 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + |
| 84 | + - name: Publish to crates.io |
| 85 | + if: env.RELEASE == 'true' |
| 86 | + env: |
| 87 | + CARGO_REGISTRY_TOKEN: ${{ secrets.cargo_registry_token }} |
| 88 | + # See comment above for why `--allow-dirty` is used. |
| 89 | + run: cargo publish -p chiapos --allow-dirty |
0 commit comments