diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 092e701..b634229 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,8 +13,22 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v4 + - name: Cache + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Snapshot runtime + run: cargo run --release --bin snapshot - name: Build - run: cargo build --verbose + run: cargo build --release --verbose --all --examples - name: Run tests run: cargo test --verbose diff --git a/Cargo.lock b/Cargo.lock index 1388d67..251642c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1664,7 +1664,7 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openworkers-runtime" -version = "0.1.0" +version = "0.1.1" dependencies = [ "actix-web", "bytes", diff --git a/Cargo.toml b/Cargo.toml index dc2c654..c71ee23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openworkers-runtime" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/examples/snapshot.rs b/src/bin/snapshot.rs similarity index 100% rename from examples/snapshot.rs rename to src/bin/snapshot.rs diff --git a/src/runtime.rs b/src/runtime.rs index 28e5d64..57ab8f7 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -17,13 +17,17 @@ use deno_core::Snapshot; use log::debug; -const USER_AGENT: &str = "OpenWorkers/0.1.0"; +const USER_AGENT: &str = concat!("OpenWorkers/", env!("CARGO_PKG_VERSION")); static RUNTIME_SNAPSHOT: &[u8] = include_bytes!(concat!( env!("CARGO_MANIFEST_DIR"), "/target/RUNTIME_SNAPSHOT.bin" )); +pub (crate) fn user_agent() -> String { + USER_AGENT.to_string() +} + pub fn module_url(path_str: &str) -> Url { let current_dir = std::env::current_dir().unwrap(); let current_dir = current_dir.as_path(); @@ -48,7 +52,7 @@ pub(crate) fn extensions(for_snapshot: bool) -> Vec { ), deno_crypto::deno_crypto::init_ops_and_esm(None), deno_fetch::deno_fetch::init_ops_and_esm::(deno_fetch::Options { - user_agent: USER_AGENT.to_string(), + user_agent: user_agent(), ..Default::default() }), // OpenWorkers extensions @@ -109,7 +113,7 @@ impl Worker { // Bootstrap { - let script = format!("globalThis.bootstrap('{}')", USER_AGENT); + let script = format!("globalThis.bootstrap('{}')", user_agent()); let script = deno_core::ModuleCodeString::from(script); match js_runtime.execute_script(deno_core::located_script_name!(), script) {