Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ semver = { version = "1", features = ["serde"] }
uuid = { version = "1", features = ["serde", "v4"] }
chrono = { version = "0.4", features = ["serde"] }
thiserror = "2"
derive_more = { version = "1", default-features = false, features = ["deref", "from", "display"] }
derive_more = { version = "1", default-features = false, features = ["full"] }
smart-default = "0.7"
tokio = { version = "1", features = ["full"] }
tokio-util = { version = "0.7", features = ["rt"] }
extism = "1"
Expand Down
4 changes: 2 additions & 2 deletions crates/hm-plugin-docker/src/image_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ pub(crate) fn resolve_image(
parent_snapshot: Option<&SnapshotRef>,
) -> String {
if let Some(tag) = hit_tag {
return tag.0.clone();
return tag.to_string();
}
if let Some(snap) = parent_snapshot {
return snap.0.clone();
return snap.to_string();
}
if let Some(image) = &step.image {
return image.clone();
Expand Down
2 changes: 1 addition & 1 deletion crates/hm-plugin-docker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn run_step(input: ExecutorInput) -> Result<StepResult, PluginError> {
});
match host::commit(DockerCommitArgs {
container_id: cid.clone(),
tag: target_tag.0.clone(),
tag: target_tag.to_string(),
}) {
Ok(_) => Some(target_tag),
Err(e) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/hm-plugin-protocol/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use uuid::Uuid;

use crate::executor::SnapshotRef;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant)]
#[serde(rename_all = "snake_case")]
pub enum StdStream {
Stdout,
Stderr,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum BuildEvent {
BuildStart {
Expand Down
2 changes: 1 addition & 1 deletion crates/hm-plugin-protocol/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct ArtifactRef {

/// Host-decided cache outcome. The executor honours this; it does
/// not re-decide.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum CacheDecision {
/// Boot from `tag`; skip running `cmd`.
Expand Down
6 changes: 3 additions & 3 deletions crates/hm-plugin-protocol/src/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct HookEvent {
pub phase: HookPhase,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant)]
#[serde(rename_all = "snake_case")]
pub enum HookPhase {
/// May return [`HookOutcome::Abort`] to fail the build.
Expand All @@ -23,7 +23,7 @@ pub enum HookPhase {
After,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum HookOutcome {
/// Continue the build.
Expand All @@ -37,7 +37,7 @@ pub enum HookOutcome {
///
/// The manifest declares *what* events the plugin wants, not the per-event
/// payload. Kept in this file so plugin authors only import one module.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant)]
#[serde(rename_all = "snake_case")]
pub enum HookEventKind {
BuildStart,
Expand Down
4 changes: 2 additions & 2 deletions crates/hm-plugin-protocol/src/host_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};

use crate::executor::ArchiveId;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant)]
#[serde(rename_all = "snake_case")]
pub enum Level {
Trace,
Expand All @@ -19,7 +19,7 @@ pub enum Level {
Error,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant)]
#[serde(rename_all = "snake_case")]
pub enum KvScope {
/// Per-plugin, persistent across builds. Stored in
Expand Down
2 changes: 1 addition & 1 deletion crates/hm-plugin-protocol/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Pipeline {
pub steps: Vec<Step>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Step {
Command(Box<CommandStep>),
Expand Down
2 changes: 1 addition & 1 deletion crates/hm-plugin-protocol/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct PluginManifest {
pub allowed_hosts: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum Capability {
Subcommand(SubcommandSpec),
Expand Down
1 change: 1 addition & 0 deletions crates/hm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ hm-plugin-protocol = { workspace = true }
hm-util = { workspace = true }
schemars = { workspace = true }
semver = { workspace = true }
smart-default = { workspace = true }
once_cell = "1"
hex = "0.4"

Expand Down
10 changes: 2 additions & 8 deletions crates/hm/src/cli/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ pub async fn run(cmd: PluginCommand) -> Result<()> {

#[allow(clippy::unused_async)]
async fn list() -> Result<()> {
let reg = PluginRegistry::load(RegistryConfig {
auto_discover: true,
..Default::default()
})?;
let reg = PluginRegistry::load(RegistryConfig::default())?;
if reg.manifests().count() == 0 {
println!("No plugins installed.");
println!();
Expand All @@ -78,10 +75,7 @@ async fn list() -> Result<()> {

#[allow(clippy::unused_async)]
async fn info(name: &str) -> Result<()> {
let reg = PluginRegistry::load(RegistryConfig {
auto_discover: true,
..Default::default()
})?;
let reg = PluginRegistry::load(RegistryConfig::default())?;
let m = reg
.manifests()
.find(|m| m.name == name)
Expand Down
5 changes: 1 addition & 4 deletions crates/hm/src/cli/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use crate::plugin::{PluginRegistry, RegistryConfig};
///
/// Returns an error if the plugin registry cannot be loaded.
pub async fn run() -> Result<()> {
let reg = PluginRegistry::load(RegistryConfig {
auto_discover: true,
..Default::default()
})?;
let reg = PluginRegistry::load(RegistryConfig::default())?;
println!("hm {}", env!("CARGO_PKG_VERSION"));
println!("plugin api version: {HM_PLUGIN_API_VERSION}");
let count = reg.manifests().count();
Expand Down
10 changes: 3 additions & 7 deletions crates/hm/src/orchestrator/docker_host_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub(crate) async fn exec_impl(args: DockerExecArgs) -> Result<i32> {
// Emit StepLog events for each line written; the writer below
// forwards bytes into the event bus tagged with the current
// thread-local step_id set by the scheduler.
let mut writer = StepLogWriter::new();
let mut writer = StepLogWriter::default();

// Future doing the exec; we race it against cancellation.
let cancel = s.cancel.clone();
Expand Down Expand Up @@ -184,17 +184,13 @@ pub(crate) async fn stop_remove_impl(container_id: String) {

/// Streams bytes from a Docker exec into per-line `StepLog` events on
/// the event bus. Buffers partial lines until a `\n` arrives.
#[derive(smart_default::SmartDefault)]
struct StepLogWriter {
#[default(Vec::with_capacity(8192))]
buf: Vec<u8>,
}

impl StepLogWriter {
fn new() -> Self {
Self {
buf: Vec::with_capacity(8192),
}
}

fn flush_line(line: &[u8]) {
let Some(state) = current() else { return };
let Some(step_id) = crate::plugin::host_fns::current_step_id() else {
Expand Down
7 changes: 3 additions & 4 deletions crates/hm/src/orchestrator/output_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use std::sync::Arc;

use anyhow::Result;
use hm_plugin_protocol::BuildEvent;
use tokio::sync::Mutex;
use tokio::sync::broadcast::error::RecvError;

Expand Down Expand Up @@ -63,20 +62,20 @@ pub fn spawn(
let Some(&idx) = reg.output_formatter_index.get(&format_name) else {
// No plugin for this format; CLI parser
// should have caught this. Drain silently.
if matches!(event, BuildEvent::BuildEnd { .. }) {
if event.is_build_end() {
return Ok(());
}
continue;
};
let Some(p) = reg.get(idx) else {
if matches!(event, BuildEvent::BuildEnd { .. }) {
if event.is_build_end() {
return Ok(());
}
continue;
};
p
};
let is_end = matches!(event, BuildEvent::BuildEnd { .. });
let is_end = event.is_build_end();
// Log-and-continue on formatter failures: a broken
// output plugin shouldn't fail the build.
let _: Result<()> = plugin.call_capability("hm_output_on_event", &event).await;
Expand Down
3 changes: 2 additions & 1 deletion crates/hm/src/plugin/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ use super::manifest::{ManifestError, validate_standalone};
use super::paths;
use crate::error::HmError;

#[derive(Debug, Default)]
#[derive(Debug, smart_default::SmartDefault)]
pub struct RegistryConfig {
/// If `false`, skip discovery and only registers explicitly added
/// plugins. Used by integration tests.
#[default = true]
pub auto_discover: bool,
/// Extra plugin paths to load (in addition to discovery). Used by
/// tests to load fixture plugins.
Expand Down
Loading