Skip to content

Commit

Permalink
fix: conform to new layout
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-way committed Nov 3, 2024
1 parent 662ad8f commit f177eb2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
2 changes: 0 additions & 2 deletions .cargo/config.toml

This file was deleted.

5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: wasm32-wasip1
- run: cargo test --all-features

formatting:
Expand All @@ -30,7 +28,6 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
target: wasm32-wasip1
- name: Rustfmt Check
uses: actions-rust-lang/rustfmt@v1

Expand All @@ -42,4 +39,4 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: wasm32-wasip1
- run: cargo build --all-features
- run: cargo build --all-features --target wasm32-wasip1
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
target: wasm32-wasip1

- name: Build
run: cargo build --release
run: cargo build --release --target wasm32-wasip1

- name: Create SHA256 checksum
run: sha256sum target/wasm32-wasip1/release/plugin.wasm > target/wasm32-wasip1/release/plugin.wasm.sha256
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
build:
cargo build --release
cargo build --release --target wasm32-wasip1
27 changes: 14 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ use serde::Deserialize;
use std::fs;
use toml_edit::{value, DocumentMut};

const CARGO_TOML_PATH: &str = "Cargo.toml";

#[derive(Debug, Deserialize)]
struct SetVersionRequest {
version: String,
}

#[plugin_fn]
pub fn get_version(path: String) -> FnResult<String> {
let version = get_toml_value(path);
pub fn get_version(_: String) -> FnResult<String> {
let version = get_toml_value(CARGO_TOML_PATH);
match version {
Ok(contents) => Ok(contents),
Err(e) => Ok(e.to_string()),
}
}

fn get_toml_value(path: String) -> Result<String, Error> {
fn get_toml_value(path: &str) -> Result<String, Error> {
let file_contents = std::fs::read_to_string(path)?;
let document = file_contents.parse::<DocumentMut>().unwrap();
let version = document["package"]["version"].as_str().unwrap().to_string();
Ok(version)
}

#[derive(Debug, Deserialize)]
struct SetVersionRequest {
version: String,
path: String,
}

#[plugin_fn]
pub fn set_version(input: Json<SetVersionRequest>) -> FnResult<()> {
update_package_section(&input.0.path, &input.0.version)?;
update_package_section(CARGO_TOML_PATH, &input.0.version)?;

Ok(())
}
Expand Down Expand Up @@ -66,12 +67,12 @@ mod tests {
fn test_get_version(#[case] input: &str, #[case] expected: &str) {
let dir = tempdir().unwrap();

let temp_file = dir.path().join("cargo.toml");
let temp_file = dir.path().join(CARGO_TOML_PATH);
let mut file = File::create(&temp_file).unwrap();

write!(file, "{}", input).unwrap();

let version = get_toml_value(temp_file.to_str().unwrap().to_string()).unwrap();
let version = get_toml_value(temp_file.to_str().unwrap()).unwrap();

similar_asserts::assert_eq!(version, expected);
}
Expand All @@ -89,7 +90,7 @@ mod tests {
) {
let dir = tempdir().unwrap();

let temp_file = dir.path().join("cargo.toml");
let temp_file = dir.path().join(CARGO_TOML_PATH);
let mut file = File::create(&temp_file).unwrap();

write!(file, "{}", input).unwrap();
Expand Down

0 comments on commit f177eb2

Please sign in to comment.