Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move ci testing to dev_tools #12371

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/bevy_dev_tools/Cargo.toml
Expand Up @@ -16,6 +16,9 @@ bevy_ci_testing = ["serde", "ron"]
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
bevy_render = { path = "../bevy_render", version = "0.14.0-dev" }
bevy_time = { path = "../bevy_time", version = "0.14.0-dev" }
bevy_window = { path = "../bevy_window", version = "0.14.0-dev" }

# other
serde = { version = "1.0", features = ["derive"], optional = true }
Expand Down
41 changes: 37 additions & 4 deletions crates/bevy_dev_tools/src/ci_testing.rs
@@ -1,11 +1,18 @@
//! Utilities for testing in CI environments.

use bevy_app::{App, AppExit, Update};
use bevy_ecs::{
entity::Entity,
prelude::Resource,
query::With,
system::{Local, Query, Res, ResMut},
};
use bevy_render::view::screenshot::ScreenshotManager;
use bevy_time::TimeUpdateStrategy;
use bevy_utils::{tracing::info, Duration};
use bevy_window::PrimaryWindow;
use serde::Deserialize;

use bevy_ecs::prelude::Resource;
use bevy_utils::tracing::info;

/// A configuration struct for automated CI testing.
///
/// It gets used when the `bevy_ci_testing` feature is enabled to automatically
Expand Down Expand Up @@ -53,8 +60,34 @@ pub(crate) fn setup_app(app: &mut App) -> &mut App {
ron::from_str(config).expect("error deserializing CI testing configuration file")
};

if let Some(frame_time) = config.frame_time {
app.world
.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_secs_f32(
frame_time,
)));
}

app.insert_resource(config)
.add_systems(Update, ci_testing_exit_after);
.add_systems(Update, (ci_testing_exit_after, ci_testing_screenshot_at));

app
}

fn ci_testing_screenshot_at(
mut current_frame: Local<u32>,
ci_testing_config: Res<CiTestingConfig>,
mut screenshot_manager: ResMut<ScreenshotManager>,
main_window: Query<Entity, With<PrimaryWindow>>,
) {
if ci_testing_config
.screenshot_frames
.contains(&*current_frame)
{
info!("Taking a screenshot at frame {}.", *current_frame);
let path = format!("./screenshot-{}.png", *current_frame);
screenshot_manager
.save_screenshot_to_disk(main_window.single(), path)
.unwrap();
}
*current_frame += 1;
}
7 changes: 1 addition & 6 deletions crates/bevy_internal/Cargo.toml
Expand Up @@ -113,12 +113,7 @@ webgpu = [
]

# enable systems that allow for automated testing on CI
bevy_ci_testing = [
"bevy_dev_tools/bevy_ci_testing",
"bevy_time/bevy_ci_testing",
"bevy_render?/bevy_ci_testing",
"bevy_render?/ci_limits",
]
bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing", "bevy_render?/ci_limits"]

# Enable animation support, and glTF animation loading
animation = ["bevy_animation", "bevy_gltf?/bevy_animation"]
Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_render/Cargo.toml
Expand Up @@ -19,7 +19,6 @@ webp = ["image/webp"]
dds = ["ddsfile"]
pnm = ["image/pnm"]
multi-threaded = ["bevy_tasks/multi-threaded"]
bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing"]

shader_format_glsl = ["naga/glsl-in", "naga/wgsl-out", "naga_oil/glsl"]
shader_format_spirv = ["wgpu/spirv", "naga/spv-in", "naga/spv-out"]
Expand Down Expand Up @@ -57,7 +56,6 @@ bevy_transform = { path = "../bevy_transform", version = "0.14.0-dev" }
bevy_window = { path = "../bevy_window", version = "0.14.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" }
bevy_dev_tools = { path = "../bevy_dev_tools", version = "0.14.0-dev", optional = true }

# rendering
image = { version = "0.24", default-features = false }
Expand Down
28 changes: 0 additions & 28 deletions crates/bevy_render/src/view/window/screenshot.rs
Expand Up @@ -140,35 +140,7 @@ impl Plugin for ScreenshotPlugin {
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
render_app.init_resource::<SpecializedRenderPipelines<ScreenshotToScreenPipeline>>();
}

#[cfg(feature = "bevy_ci_testing")]
if app
.world
.contains_resource::<bevy_dev_tools::ci_testing::CiTestingConfig>()
{
app.add_systems(bevy_app::Update, ci_testing_screenshot_at);
}
}
}

#[cfg(feature = "bevy_ci_testing")]
fn ci_testing_screenshot_at(
mut current_frame: Local<u32>,
ci_testing_config: Res<bevy_dev_tools::ci_testing::CiTestingConfig>,
mut screenshot_manager: ResMut<ScreenshotManager>,
main_window: Query<Entity, With<bevy_window::PrimaryWindow>>,
) {
if ci_testing_config
.screenshot_frames
.contains(&*current_frame)
{
info!("Taking a screenshot at frame {}.", *current_frame);
let path = format!("./screenshot-{}.png", *current_frame);
screenshot_manager
.save_screenshot_to_disk(main_window.single(), path)
.unwrap();
}
*current_frame += 1;
}

pub(crate) fn align_byte_size(value: u32) -> u32 {
Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_time/Cargo.toml
Expand Up @@ -11,7 +11,6 @@ keywords = ["bevy"]
[features]
default = []
serialize = ["serde"]
bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing"]

[dependencies]
# bevy
Expand All @@ -23,7 +22,6 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
"bevy",
] }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
bevy_dev_tools = { path = "../bevy_dev_tools", version = "0.14.0-dev", optional = true }

# other
crossbeam-channel = "0.5.0"
Expand Down
13 changes: 0 additions & 13 deletions crates/bevy_time/src/lib.rs
Expand Up @@ -64,19 +64,6 @@ impl Plugin for TimePlugin {
bevy_ecs::event::reset_event_update_signal_system.after(EventUpdates),
)
.add_systems(FixedPostUpdate, signal_event_update_system);

#[cfg(feature = "bevy_ci_testing")]
if let Some(ci_testing_config) = app
.world
.get_resource::<bevy_dev_tools::ci_testing::CiTestingConfig>()
{
if let Some(frame_time) = ci_testing_config.frame_time {
app.world
.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_secs_f32(
frame_time,
)));
}
}
}
}

Expand Down