Skip to content

Commit

Permalink
Add more checks to CI (#244)
Browse files Browse the repository at this point in the history
* Add more checks to CI

* Renamed from "Validate PR" to "CI" since it isn't run exclusively on PRs
* Added a `features` job to test that the crates build with each feature
* Added a test for WASM builds (commented out for now)

* gadget-common: Fix feature conflicts caught by CI

* gadget-core: Fix feature conflicts caught by CI

* gadget-core: Fix feature conflicts caught by CI

* gadget-sdk: Fix feature conflicts caught by CI

* Update Cargo.lock

* sdk: Update tangle-subxt to 0.2.0

* sdk: Fixup no_std for latest changes

* common: Add missing feature

* Fix compilation

* Fix nightly rust lint

* Update tangle-subxt
  • Loading branch information
Serial-ATA authored Sep 9, 2024
1 parent e910dc3 commit 3d71b29
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 135 deletions.
102 changes: 54 additions & 48 deletions .github/workflows/validate_pr.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Validate PR
name: CI

on:
pull_request:
branches: [main]
branches: [ main ]
push:
branches: [main]
branches: [ main ]
workflow_dispatch:

concurrency:
group: rust-validation-${{ github.head_ref }}
Expand Down Expand Up @@ -32,17 +33,54 @@ jobs:
- name: Check Formatting
run: cargo fmt -- --check

features:
timeout-minutes: 90
name: Test building with each feature
runs-on: ubuntu-latest
strategy:
matrix:
package: [
gadget-core,
gadget-common,
gadget-sdk,
]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install rust
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: stable

- uses: swatinem/rust-cache@v2
with:
cache-on-failure: "true"

- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack

- name: Ensure wasm32-unknown-unknown is installed
run: rustup target add wasm32-unknown-unknown

- name: Test each feature
run: cargo hack test --each-feature --exclude-features wasm --package=${{ matrix.package }}

# TODO
# - name: Test wasm build
# run: cargo hack build --target wasm32-unknown-unknown --package=${{ matrix.package }} --no-default-features --features wasm --ignore-unknown-features

linting:
timeout-minutes: 120
name: cargo clippy
runs-on: macos-latest
strategy:
matrix:
package: [
gadget-core,
gadget-common,
blueprint-manager
]
matrix:
package: [
gadget-core,
gadget-common,
blueprint-manager
]
steps:
- name: checkout code
uses: actions/checkout@v2
Expand All @@ -67,12 +105,12 @@ jobs:
name: cargo test
runs-on: macos-14
strategy:
matrix:
package: [
gadget-core,
gadget-common,
blueprint-manager,
]
matrix:
package: [
gadget-core,
gadget-common,
blueprint-manager,
]
steps:
- name: checkout code
uses: actions/checkout@v2
Expand All @@ -98,36 +136,4 @@ jobs:
run: cargo install cargo-nextest --locked

- name: tests
run: cargo nextest run --release --nocapture --package ${{ matrix.package }}

wasm_checks:
timeout-minutes: 90
name: WASM checks
if: false # Disabled for now
runs-on: macos-14
steps:
- name: checkout code
uses: actions/checkout@v2

- name: install rust
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: stable

- uses: swatinem/rust-cache@v2
with:
cache-on-failure: "true"

- name: install protobuf
run: brew install protobuf gmp

- name: Set Relevant M1 env vars
run: |
export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/lib
export INCLUDE_PATH=$INCLUDE_PATH:/opt/homebrew/include
- name: Ensure wasm32-unknown-unknown is installed
run: rustup target add wasm32-unknown-unknown

- name: Run wasm checks
run: cargo test --target wasm32-unknown-unknown --package=gadget-core --package=gadget-common --no-default-features --features wasm
run: cargo nextest run --nocapture --package ${{ matrix.package }}
11 changes: 5 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ cargo_metadata = { version = "0.18.1" }
pallet-services = { git = "https://github.com/webb-tools/tangle.git" }
pallet-services-rpc = { git = "https://github.com/webb-tools/tangle.git" }
tangle-primitives = { git = "https://github.com/webb-tools/tangle.git" }
tangle-subxt = { version = "0.1.5", default-features = false }
tangle-subxt = { version = "0.3.0", default-features = false }

subxt-signer = { version = "0.37.0", default-features = false }
subxt = { version = "0.37.0", default-features = false }
Expand Down Expand Up @@ -157,14 +157,14 @@ ark-ed25519 = { version = "0.4", default-features = false }
aes-gcm = { version = "0.10", default-features = false, features = ["aes", "alloc", "getrandom", "zeroize"] }
anyhow = "1.0.86"
async-recursion2 = "1.0.5"
async-trait = "0.1.81"
async-trait = "0.1.82"
auto_impl = "1.2.0"
aws-config = "1.5.5"
aws-types = "1.3.3"
aws-sdk-kms = "1.40.0"
aws-sdk-s3 = "1.45.0"
aws-sdk-secretsmanager = "1.43.0"
backoff = { version = "0.4.0", features = ["tokio"] }
backoff = { version = "0.4.0", default-features = false }
base64 = "0.22.1"
bincode = "1.3.3"
bincode2 = { version = "2" }
Expand Down
2 changes: 1 addition & 1 deletion blueprint-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ default = ["std"]
std = [
"gadget-common/std",
"gadget-io/std",
"gadget-sdk/std",
"gadget-sdk/default",
]
11 changes: 10 additions & 1 deletion blueprint-test-utils/src/test_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use gadget_common::prelude::{
PrometheusConfig, UnboundedReceiver, UnboundedSender,
};
use gadget_common::tangle_runtime::api;
use gadget_common::tangle_runtime::api::runtime_types::tangle_primitives::services::ApprovalPrefrence;
use gadget_common::tangle_runtime::api::runtime_types::tangle_primitives::services::{
ApprovalPrefrence, PriceTargets,
};
use gadget_common::tangle_runtime::api::services::calls::types::register::{
Preferences, RegistrationArgs,
};
Expand Down Expand Up @@ -255,6 +257,13 @@ pub async fn new_test_ext_blueprint_manager<
let preferences = Preferences {
key,
approval: ApprovalPrefrence::None,
price_targets: PriceTargets {
cpu: 0,
mem: 0,
storage_hdd: 0,
storage_ssd: 0,
storage_nvme: 0,
},
};

super::register_blueprint(
Expand Down
8 changes: 3 additions & 5 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,22 @@ sp-core = { workspace = true, features = ["full_crypto"] }
sp-io = { workspace = true, features = ["disable_allocator", "disable_panic_handler", "disable_oom"] }
sp-runtime = { workspace = true, features = ["serde"] }
substrate-prometheus-endpoint = { workspace = true, optional = true }
subxt = { workspace = true, optional = true }
subxt-signer = { workspace = true, features = ["subxt", "sr25519"], optional = true }
tangle-subxt = { workspace = true, optional = true }

[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dependencies]
getrandom = { workspace = true, features = ["js"] }

[features]
default = ["substrate", "std", "tangle-testnet", "subxt/native"]
default = ["substrate", "std", "tangle-testnet"]
tangle-testnet = []
tangle-mainnet = []
substrate = [
"dep:parity-scale-codec",
"dep:tangle-subxt",
"dep:substrate-prometheus-endpoint",
"dep:subxt-signer",
"dep:subxt",
"gadget-core/substrate",
"subxt/jsonrpsee",
]
std = [
"dep:sqlx",
Expand All @@ -58,6 +55,7 @@ std = [
"serde/std",
"sp-io/std",
"sp-runtime/std",
"tangle-subxt?/std",
]
wasm = ["subxt-signer?/web", "subxt?/web", "subxt?/jsonrpsee"]
wasm = ["subxt-signer?/web", "tangle-subxt?/web"]
testing = []
14 changes: 10 additions & 4 deletions common/src/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ use alloc::vec::Vec;
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
use crate::environments::GadgetEnvironment;
#[cfg(feature = "substrate")]
use crate::module::network::Network;
use crate::prelude::DebugLogger;
#[cfg(feature = "substrate")]
use crate::utils::deserialize;
#[cfg(feature = "substrate")]
use futures::StreamExt;
#[cfg(feature = "substrate")]
use gadget_core::job::protocol::ProtocolMessageMetadata;
#[cfg(feature = "substrate")]
use gadget_io::tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use sp_core::ecdsa;

use std::collections::HashMap;
#[cfg(feature = "substrate")]
use std::sync::Arc;
}
}
Expand Down Expand Up @@ -55,7 +61,7 @@ impl<B> Msg<B> {
}

#[allow(clippy::too_many_arguments)]
#[cfg(feature = "std")]
#[cfg(all(feature = "std", feature = "substrate"))]
pub fn create_job_manager_to_async_protocol_channel_split<
Env: GadgetEnvironment,
N: Network<Env>,
Expand Down Expand Up @@ -492,7 +498,7 @@ pub type DuplexedChannel<O, I, C2> = (
);

#[allow(clippy::too_many_arguments)]
#[cfg(feature = "std")]
#[cfg(all(feature = "std", feature = "substrate"))]
pub fn create_job_manager_to_async_protocol_channel_split_io<
Env: GadgetEnvironment,
N: Network<Env>,
Expand Down Expand Up @@ -678,7 +684,7 @@ pub type TriplexedChannel<O1, I1, O2, I2, C2> = (
);

#[allow(clippy::too_many_arguments)]
#[cfg(feature = "std")]
#[cfg(all(feature = "std", feature = "substrate"))]
pub fn create_job_manager_to_async_protocol_channel_split_io_triplex<
Env: GadgetEnvironment,
N: Network<Env> + 'static,
Expand Down Expand Up @@ -872,7 +878,7 @@ pub fn create_job_manager_to_async_protocol_channel_split_io_triplex<
}

#[allow(clippy::too_many_arguments)]
#[cfg(feature = "std")]
#[cfg(all(feature = "std", feature = "substrate"))]
async fn wrap_message_and_forward_to_network<
Env: GadgetEnvironment,
N: Network<Env>,
Expand Down
1 change: 0 additions & 1 deletion common/src/debug_logger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(not(feature = "std"))]
use alloc::string::String;
use core::fmt::Display;

Expand Down
4 changes: 2 additions & 2 deletions common/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ fn key_to_string(key: &[u8; 32]) -> String {
}

#[cfg(test)]
#[cfg(not(target_family = "wasm"))]
#[cfg(feature = "std")]
mod tests {
use crate::keystore::KeystoreBackend;
use gadget_io::tokio;

#[gadget_io::tokio::test]
#[tokio::test]
#[cfg(feature = "std")]
async fn test_in_memory_kv_store() {
let store = super::SqliteBackend::in_memory().await.unwrap();
Expand Down
Loading

0 comments on commit 3d71b29

Please sign in to comment.