2022-06-06 20:22:51 +00:00
|
|
|
use std::{fs::File, io::Write};
|
|
|
|
|
|
|
|
use clap::Parser;
|
2022-05-17 19:04:08 +00:00
|
|
|
use xshell::{cmd, Shell};
|
|
|
|
|
2022-06-06 20:22:51 +00:00
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
struct Args {
|
|
|
|
/// Examples to build
|
|
|
|
examples: Vec<String>,
|
|
|
|
|
2022-10-19 18:54:37 +00:00
|
|
|
#[arg(short, long)]
|
2022-06-06 20:22:51 +00:00
|
|
|
/// Run tests
|
|
|
|
test: bool,
|
|
|
|
|
2022-10-19 18:54:37 +00:00
|
|
|
#[arg(short, long)]
|
2022-06-06 20:22:51 +00:00
|
|
|
/// Run on the given browsers. By default, chromium, firefox, webkit
|
|
|
|
browsers: Vec<String>,
|
|
|
|
|
2022-10-19 18:54:37 +00:00
|
|
|
#[arg(short, long)]
|
2022-06-06 20:22:51 +00:00
|
|
|
/// Stop after this number of frames
|
|
|
|
frames: Option<usize>,
|
|
|
|
}
|
|
|
|
|
2022-05-17 19:04:08 +00:00
|
|
|
fn main() {
|
2022-06-06 20:22:51 +00:00
|
|
|
let cli = Args::parse();
|
2022-10-28 21:03:01 +00:00
|
|
|
eprintln!("{cli:?}");
|
2022-06-06 20:22:51 +00:00
|
|
|
|
|
|
|
assert!(!cli.examples.is_empty(), "must have at least one example");
|
|
|
|
|
|
|
|
let mut bevy_ci_testing = vec![];
|
|
|
|
if let Some(frames) = cli.frames {
|
|
|
|
let mut file = File::create("ci_testing_config.ron").unwrap();
|
2022-10-28 21:03:01 +00:00
|
|
|
file.write_fmt(format_args!("(exit_after: Some({frames}))"))
|
2022-06-06 20:22:51 +00:00
|
|
|
.unwrap();
|
|
|
|
bevy_ci_testing = vec!["--features", "bevy_ci_testing"];
|
|
|
|
}
|
|
|
|
|
|
|
|
for example in cli.examples {
|
|
|
|
let sh = Shell::new().unwrap();
|
|
|
|
let bevy_ci_testing = bevy_ci_testing.clone();
|
|
|
|
cmd!(
|
|
|
|
sh,
|
|
|
|
"cargo build {bevy_ci_testing...} --release --target wasm32-unknown-unknown --example {example}"
|
|
|
|
)
|
|
|
|
.run()
|
|
|
|
.expect("Error building example");
|
|
|
|
cmd!(
|
|
|
|
sh,
|
|
|
|
"wasm-bindgen --out-dir examples/wasm/target --out-name wasm_example --target web target/wasm32-unknown-unknown/release/examples/{example}.wasm"
|
|
|
|
)
|
|
|
|
.run()
|
|
|
|
.expect("Error creating wasm binding");
|
|
|
|
|
|
|
|
if cli.test {
|
|
|
|
let _dir = sh.push_dir(".github/start-wasm-example");
|
|
|
|
let mut browsers = cli.browsers.clone();
|
|
|
|
if !browsers.is_empty() {
|
|
|
|
browsers.insert(0, "--project".to_string());
|
|
|
|
}
|
|
|
|
cmd!(sh, "npx playwright test --headed {browsers...}")
|
|
|
|
.env("SCREENSHOT_PREFIX", format!("screenshot-{example}"))
|
|
|
|
.run()
|
|
|
|
.expect("Error running playwright test");
|
|
|
|
}
|
|
|
|
}
|
2022-05-17 19:04:08 +00:00
|
|
|
}
|