From a07ad85444daf9e761068fe8cdea8609ea2367c6 Mon Sep 17 00:00:00 2001 From: Adam Obuchowicz Date: Mon, 25 Nov 2019 11:52:51 +0100 Subject: [PATCH] Add wasm-pack test to github workflows (https://github.com/enso-org/ide/pull/49) To the test workflow added a step where wasm-pack test is run for each crate in workspace. A script was added, which runs wasm-pack test for each workspace members, because The wasm-pack itself cannot read workspaces. The script was written in rust, therefore a special crate for build-and-utility-scripts in rust was created. Original commit: https://github.com/enso-org/ide/commit/51d3eaec7e05b3e21b98d4719c6dba701ca96478 --- gui/.github/workflows/build.yml | 48 ++++++++++++++++++++--------- gui/.gitignore | 2 +- gui/lib/system/web/Cargo.toml | 4 +++ gui/script/rust/Cargo.toml | 10 ++++++ gui/script/rust/src/bin/test-all.rs | 39 +++++++++++++++++++++++ gui/script/test.sh | 3 ++ 6 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 gui/script/rust/Cargo.toml create mode 100644 gui/script/rust/src/bin/test-all.rs create mode 100755 gui/script/test.sh diff --git a/gui/.github/workflows/build.yml b/gui/.github/workflows/build.yml index d62b31d490c..25ae33d0db2 100644 --- a/gui/.github/workflows/build.yml +++ b/gui/.github/workflows/build.yml @@ -33,24 +33,42 @@ jobs: with: toolchain: nightly-2019-11-04 override: true - - uses: actions-rs/cargo@v1 + - uses: nanasess/setup-chromedriver@master + with: + chromedriver-version: '78.0.3904.105' + - name: Install wasm-pack + uses: actions-rs/cargo@v1 + with: + command: install + args: wasm-pack + - name: Run tests + uses: actions-rs/cargo@v1 with: command: test + - name: Run wasm-pack tests + uses: actions-rs/cargo@v1 + with: + command: run + args: > + --manifest-path=script/rust/Cargo.toml + --bin test-all + -- --node --chrome --headless -# fmt: -# name: Formatter -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v1 -# - uses: actions-rs/toolchain@v1 -# with: -# toolchain: nightly-2019-11-04 -# override: true -# - run: rustup component add rustfmt -# - uses: actions-rs/cargo@v1 -# with: -# command: fmt -# args: --all -- --check +# TODO[AO] formatter does not work +# fmt: +# name: Formatter +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v1 +# - uses: actions-rs/toolchain@v1 +# with: +# toolchain: nightly-2019-11-04 +# override: true +# - run: rustup component add rustfmt +# - uses: actions-rs/cargo@v1 +# with: +# command: fmt +# args: --all -- --check clippy: name: Linter diff --git a/gui/.gitignore b/gui/.gitignore index 8ad0d33ac2a..ccc4b5a3e88 100644 --- a/gui/.gitignore +++ b/gui/.gitignore @@ -1,8 +1,8 @@ # Rust /target +/script/rust/target/ **/*.rs.bk Cargo.lock -bin/ pkg/ wasm-pack.log diff --git a/gui/lib/system/web/Cargo.toml b/gui/lib/system/web/Cargo.toml index c0185210ece..ea5ca42158c 100644 --- a/gui/lib/system/web/Cargo.toml +++ b/gui/lib/system/web/Cargo.toml @@ -21,7 +21,11 @@ console_error_panic_hook = { version = "0.1.1", optional = true } version = "0.3.4" features = [ 'Document', + 'Node', 'Element', + 'HtmlElement', + 'HtmlCollection', + 'CssStyleDeclaration', 'HtmlCanvasElement', 'WebGlBuffer', 'WebGlRenderingContext', diff --git a/gui/script/rust/Cargo.toml b/gui/script/rust/Cargo.toml new file mode 100644 index 00000000000..1d517a7121c --- /dev/null +++ b/gui/script/rust/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "build-scripts" +version = "0.1.0" +authors = ["Adam Obuchowicz "] +edition = "2018" + +[workspace] + +[dependencies] +toml="0.5.5" \ No newline at end of file diff --git a/gui/script/rust/src/bin/test-all.rs b/gui/script/rust/src/bin/test-all.rs new file mode 100644 index 00000000000..d7c95a46a20 --- /dev/null +++ b/gui/script/rust/src/bin/test-all.rs @@ -0,0 +1,39 @@ + +fn get_workspace_members(cargo_toml_root : toml::Value) -> Vec { + match &cargo_toml_root["workspace"]["members"] { + toml::Value::Array(list) => list.iter().map(|val| { + match val { + toml::Value::String(s) => s.clone(), + _ => panic!("Workspace member is not a string"), + } + }).collect(), + _ => panic!("Invalid workspace element") + } +} + +/// Call wasm-pack test for each workspace member +/// +/// This function reads workspace members list from `Cargo.toml` in current +/// directory, and call `wasm-pack test` each member. All script arguments +/// are passed to `wasm-pack` process. +fn main() { + let wasm_pack_args : Vec = std::env::args().skip(1).collect(); + let cargo_toml_root = std::fs::read_to_string("Cargo.toml").unwrap() + .parse::().unwrap(); + + for member in get_workspace_members(cargo_toml_root) { + println!("Running tests for {}:", member); + let status = std::process::Command::new("wasm-pack") + .arg("test") + .arg(&member) + .args(&wasm_pack_args) + .status() + .unwrap(); + if !status.success() { + panic!("Process for {} failed!{}", member, match status.code() { + Some(code) => format!(" Code: {}", code), + None => String::new() + }); + } + } +} diff --git a/gui/script/test.sh b/gui/script/test.sh new file mode 100755 index 00000000000..0cbee3f6985 --- /dev/null +++ b/gui/script/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cargo run --manifest-path=script/rust/Cargo.toml --bin test-all -- \ + --node --firefox --chrome --headless