From d13ab9839f5d8a775396686fdf4773c3799716db Mon Sep 17 00:00:00 2001 From: Marlon Baeten Date: Fri, 1 Mar 2024 11:32:44 +0100 Subject: [PATCH 1/3] Added MEMORY_SERVE_ROOT environment variable --- README.md | 4 ++-- memory-serve-macros/src/lib.rs | 10 +++++++--- memory-serve/Cargo.toml | 3 ++- memory-serve/static | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) create mode 120000 memory-serve/static diff --git a/README.md b/README.md index 4639722..8c39889 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ calling `Router::into_make_service()`. ## Example -```rust +```rust,no_run use axum::{response::Html, routing::get, Router}; use memory_serve::{load_assets, MemoryServe}; use std::net::SocketAddr; @@ -54,7 +54,7 @@ async fn main() { .index_file(Some("/index.html")) .into_router(); - // possible other routes an be added at this point, like API routes + // possible other routes can be added at this point, like API routes let app = Router::new() .merge(memory_router); diff --git a/memory-serve-macros/src/lib.rs b/memory-serve-macros/src/lib.rs index af3ad49..b8ce56a 100644 --- a/memory-serve-macros/src/lib.rs +++ b/memory-serve-macros/src/lib.rs @@ -20,9 +20,13 @@ pub fn load_assets(input: TokenStream) -> TokenStream { .try_init(); if asset_path.is_relative() { - let crate_dir = env::var("CARGO_MANIFEST_DIR") - .expect("CARGO_MANIFEST_DIR environment variable not set"); - asset_path = Path::new(&crate_dir).join(asset_path); + if let Ok(root_dir) = env::var("MEMORY_SERVE_ROOT") { + asset_path = Path::new(&root_dir).join(asset_path); + } else if let Ok(crate_dir) = env::var("CARGO_MANIFEST_DIR") { + asset_path = Path::new(&crate_dir).join(asset_path); + } else { + panic!("Relative path provided but CARGO_MANIFEST_DIR environment variable not set"); + } } asset_path = asset_path diff --git a/memory-serve/Cargo.toml b/memory-serve/Cargo.toml index a48a308..b8de64e 100644 --- a/memory-serve/Cargo.toml +++ b/memory-serve/Cargo.toml @@ -16,5 +16,6 @@ tracing = "0.1" sha256 = "1.4" [dev-dependencies] -tokio = { version = "1", features = ["rt", "macros"] } +tokio = { version = "1", features = ["full"] } tower = "0.4" +axum = { version = "0.7" } diff --git a/memory-serve/static b/memory-serve/static new file mode 120000 index 0000000..4dab164 --- /dev/null +++ b/memory-serve/static @@ -0,0 +1 @@ +../static \ No newline at end of file From 0aefb632f069e943ab240f201bbd609ef2d9b99a Mon Sep 17 00:00:00 2001 From: Marlon Baeten Date: Thu, 7 Mar 2024 09:42:30 +0100 Subject: [PATCH 2/3] Only release on main --- .github/workflows/release.yml | 20 ++++++++++++++++++++ .github/workflows/{ci.yml => test.yml} | 20 +------------------- 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/release.yml rename .github/workflows/{ci.yml => test.yml} (82%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..07264e9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,20 @@ +name: release +on: + workflow_run: + workflows: ["test"] + branches: [main] + types: + - completed + +env: + CARGO_TERM_COLOR: always + +jobs: + publish: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: katyo/publish-crates@v2 + with: + registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/test.yml similarity index 82% rename from .github/workflows/ci.yml rename to .github/workflows/test.yml index 5e32586..1cf3945 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,5 @@ -name: build and test +name: test on: - workflow_dispatch: push: branches: - main @@ -77,20 +76,3 @@ jobs: prefix-key: cargo shared-key: udeps - uses: tweedegolf/ci-standard/.github/actions/cargo-udeps@main - - publish: - needs: - - format - - outdated - - deny - - build - - clippy - - test - - test-release - - udeps - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: katyo/publish-crates@v2 - with: - registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} From 9eec3720d451476797df3dbf609b8113d140c8f6 Mon Sep 17 00:00:00 2001 From: Marlon Baeten Date: Thu, 7 Mar 2024 09:43:30 +0100 Subject: [PATCH 3/3] Bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 348d097..775b6d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ resolver = "2" [workspace.package] -version = "0.4.3" +version = "0.4.4" edition = "2021" license = "Apache-2.0 OR MIT" repository = "https://github.com/tweedegolf/memory-serve"