use super::models::GitHubStep;
use serde_yaml::Value;
use std::collections::BTreeMap;
impl GitHubStep {
pub fn checkout() -> Self {
Self {
name: Some("Checkout code".to_string()),
uses: Some("actions/checkout@v4".to_string()),
run: None,
with: None,
env: None,
}
}
pub fn action(name: impl Into<String>, uses: impl Into<String>) -> Self {
Self {
name: Some(name.into()),
uses: Some(uses.into()),
run: None,
with: None,
env: None,
}
}
pub fn action_with_config(
name: impl Into<String>,
uses: impl Into<String>,
with: BTreeMap<String, Value>,
) -> Self {
Self {
name: Some(name.into()),
uses: Some(uses.into()),
run: None,
with: Some(with),
env: None,
}
}
pub fn run(name: impl Into<String>, command: impl Into<String>) -> Self {
Self {
name: Some(name.into()),
uses: None,
run: Some(command.into()),
with: None,
env: None,
}
}
pub fn setup_rust(version: impl Into<String>) -> Self {
Self::action_with_config(
"Setup Rust",
"actions-rust-lang/setup-rust-toolchain@v1",
BTreeMap::from([(
"toolchain".to_string(),
Value::String(version.into()),
)]),
)
}
pub fn setup_python(version: impl Into<String>) -> Self {
Self::action_with_config(
"Setup Python",
"actions/setup-python@v5",
BTreeMap::from([(
"python-version".to_string(),
Value::String(version.into()),
)]),
)
}
pub fn setup_go(version: impl Into<String>) -> Self {
Self::action_with_config(
"Setup Go",
"actions/setup-go@v5",
BTreeMap::from([(
"go-version".to_string(),
Value::String(version.into()),
)]),
)
}
}