use crate::config::{PackageConfig, PublishConfig};
use crate::error::ReleaseError;
pub mod cargo;
pub mod custom;
pub mod docker;
pub mod go;
pub mod npm;
pub mod pypi;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PublishState {
Completed,
Needed,
Unknown(String),
}
pub struct PublishCtx<'a> {
pub package: &'a PackageConfig,
pub version: &'a str,
pub tag: &'a str,
pub dry_run: bool,
pub env: &'a [(&'a str, &'a str)],
}
pub trait Publisher {
fn name(&self) -> &'static str;
fn check(&self, ctx: &PublishCtx<'_>) -> Result<PublishState, ReleaseError>;
fn run(&self, ctx: &PublishCtx<'_>) -> Result<(), ReleaseError>;
}
pub fn publisher_for(cfg: &PublishConfig) -> Box<dyn Publisher> {
match cfg {
PublishConfig::Cargo {
features,
registry,
workspace,
} => Box::new(cargo::CargoPublisher {
features: features.clone(),
registry: registry.clone(),
workspace: *workspace,
}),
PublishConfig::Npm {
registry,
access,
workspace,
} => Box::new(npm::NpmPublisher {
registry: registry.clone(),
access: access.clone(),
workspace: *workspace,
}),
PublishConfig::Docker {
image,
platforms,
dockerfile,
} => Box::new(docker::DockerPublisher {
image: image.clone(),
platforms: platforms.clone(),
dockerfile: dockerfile.clone(),
}),
PublishConfig::Pypi {
repository,
workspace,
} => Box::new(pypi::PypiPublisher {
repository: repository.clone(),
workspace: *workspace,
}),
PublishConfig::Go => Box::new(go::GoPublisher),
PublishConfig::Custom {
command,
check,
cwd,
} => Box::new(custom::CustomPublisher {
command: command.clone(),
check: check.clone(),
cwd: cwd.clone(),
}),
}
}