diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0268c4c..bc5bf9a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -48,12 +48,29 @@ jobs: - name: Run tests run: cargo test --package gotcha --features "${{ matrix.features }}" + define-cf-matrix: + runs-on: ubuntu-latest + + outputs: + features: ${{ steps.features.outputs.features }} + + steps: + - uses: actions/checkout@v3 + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Define Features + id: features + run: | + python3 test-feature-matrix.py echo-cf-worker >> "$GITHUB_OUTPUT" gotcha-cf-worker-test: runs-on: ubuntu-latest - needs: define-matrix + needs: define-cf-matrix strategy: matrix: - features: ${{ fromJSON(needs.define-matrix.outputs.features) }} + features: ${{ fromJSON(needs.define-cf-matrix.outputs.features) }} steps: - uses: actions/checkout@v3 @@ -64,7 +81,7 @@ jobs: uses: Swatinem/rust-cache@v2 - name: Run tests - run: cargo test --package gotcha --no-default-features --features "cloudflare_worker ${{ matrix.features }}" + run: cargo test --package gotcha --no-default-features --features "${{ matrix.features }}" test: name: Test diff --git a/gotcha/Cargo.toml b/gotcha/Cargo.toml index 3dccde4..91716ae 100644 --- a/gotcha/Cargo.toml +++ b/gotcha/Cargo.toml @@ -18,6 +18,7 @@ openapi = ["dep:oas"] cors = ["dep:tower-http"] static_files = ["dep:tower-http", "tower-http/fs"] task = ["dep:cron", "tokio/time"] +message = ["tokio/rt"] cloudflare_worker = ["dep:worker"] diff --git a/gotcha/src/lib.rs b/gotcha/src/lib.rs index bf1bb90..3fce775 100644 --- a/gotcha/src/lib.rs +++ b/gotcha/src/lib.rs @@ -84,13 +84,18 @@ use tracing_subscriber::{fmt, EnvFilter}; pub use {axum, inventory, tracing}; pub use crate::config::GotchaConfigLoader; + +#[cfg(feature = "message")] +pub mod message; +#[cfg(feature = "message")] pub use crate::message::{Message, Messager}; + #[cfg(feature = "openapi")] pub use crate::openapi::Operable; #[cfg(feature = "openapi")] pub use oas; mod config; -pub mod message; + #[cfg(feature = "openapi")] pub mod openapi; pub mod router; @@ -222,7 +227,11 @@ pub trait GotchaApp: Sized + Send + Sync { let router = self.build_router(context.clone()).await?; - Ok(GotchaRouter { operations: Default::default(), router }) + Ok(GotchaRouter { + #[cfg(feature = "openapi")] + operations: Default::default(), + router + }) } } diff --git a/test-feature-matrix.py b/test-feature-matrix.py index 90d6c9e..88846ec 100755 --- a/test-feature-matrix.py +++ b/test-feature-matrix.py @@ -46,6 +46,10 @@ def generate_combinations(features): if len(sys.argv) > 1 and sys.argv[1] == "echo": combinations = generate_combinations(features) print(f"features={json.dumps(combinations)}") + elif len(sys.argv) > 1 and sys.argv[1] == "echo-cf-worker": + features = ["cors", "openapi", "cloudflare_worker"] + combinations = generate_combinations(features) + print(f"features={json.dumps(combinations)}") else: # Get combinations combinations = generate_combinations(features)