Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MEMORY_SERVE_ROOT environment variable #5

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
20 changes: 1 addition & 19 deletions .github/workflows/ci.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: build and test
name: test
on:
workflow_dispatch:
push:
branches:
- main
Expand Down Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
10 changes: 7 additions & 3 deletions memory-serve-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion memory-serve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
1 change: 1 addition & 0 deletions memory-serve/static