From 592686d3ab8dc611e6a41ad12a626c482b801ecc Mon Sep 17 00:00:00 2001 From: Keita Urashima Date: Mon, 26 Aug 2024 20:56:43 +0900 Subject: [PATCH] Use cargo-component --- .cargo/config.toml | 2 -- .github/workflows/ci.yml | 27 +++++++++++++++++++++++++++ .github/workflows/release.yml | 9 ++++++--- Cargo.toml | 4 +++- src/main.rs | 25 +++++++++++++++++++++---- 5 files changed, 57 insertions(+), 10 deletions(-) delete mode 100644 .cargo/config.toml create mode 100644 .github/workflows/ci.yml diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 6b77899..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5a7ba64 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +on: + push: + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - run: cargo test + + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - run: cargo clippy + + format: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - run: cargo fmt --check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 275a18a..a745982 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,6 +2,9 @@ on: release: types: [published] +env: + CARGO_TERM_COLOR: always + jobs: release: runs-on: ubuntu-latest @@ -9,10 +12,10 @@ jobs: steps: - uses: actions/checkout@v4 - - run: rustup target add wasm32-wasi - - run: cargo build --release + - run: cargo install cargo-component + - run: cargo component build --release - uses: softprops/action-gh-release@v2 with: - files: target/wasm32-wasi/release/zellij-foreman.wasm + files: target/wasm32-wasip1/release/zellij-foreman.wasm fail_on_unmatched_files: true diff --git a/Cargo.toml b/Cargo.toml index 680bb51..56816df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,5 +9,7 @@ zellij-tile = "0.40.1" [profile.release] codegen-units = 1 +opt-level = "s" +debug = false +strip = true lto = true -strip = "symbols" diff --git a/src/main.rs b/src/main.rs index 0659efa..339f929 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,9 +65,26 @@ impl ZellijPlugin for ZellijForeman { fn parse_procfile(procfile: &str) -> Vec<(&str, &str)> { let re = Regex::new(r"(?m)^([\w-]+):\s*(.+)$").unwrap(); - re.captures_iter(procfile).map(|c| { - let (_, [name, command]) = c.extract(); + re.captures_iter(procfile) + .map(|c| { + let (_, [name, command]) = c.extract(); - (name, command) - }).collect() + (name, command) + }) + .collect() +} + +#[test] +fn test_parse_procfile() { + let procfile = r#" +web: npm start + +api: npm run api +# comment one +comment two + "#; + + let entries = parse_procfile(procfile); + + assert_eq!(entries, vec![("web", "npm start"), ("api", "npm run api"),]); }