vorpal-sdk 0.2.0

Rust SDK for building Vorpal artifacts.
Documentation
use crate::{
    api,
    api::artifact::ArtifactSystem::{Aarch64Darwin, Aarch64Linux, X8664Darwin, X8664Linux},
    artifact::{step, Artifact, ArtifactSource},
    context::ConfigContext,
};
use anyhow::{bail, Result};

pub fn source_tools(name: &str) -> api::artifact::ArtifactSource {
    let version = "0.42.0";

    let path = format!("https://sdk.vorpal.build/source/go-tools-v{version}.tar.gz");

    ArtifactSource::new(name, path.as_str()).build()
}

#[derive(Default)]
pub struct Go {}

impl Go {
    pub fn new() -> Self {
        Self::default()
    }

    pub async fn build(self, context: &mut ConfigContext) -> Result<String> {
        let name = "go";

        let system = context.get_system();

        let source_target = match system {
            Aarch64Darwin => "darwin-arm64",
            Aarch64Linux => "linux-arm64",
            X8664Darwin => "darwin-amd64",
            X8664Linux => "linux-amd64",
            _ => bail!("unsupported {name} system: {}", system.as_str_name()),
        };

        let source_version = "1.26.0";
        let source_path =
            format!("https://sdk.vorpal.build/source/go{source_version}.{source_target}.tar.gz");

        let source = ArtifactSource::new(name, source_path.as_str()).build();

        let step_script = format!("cp -pr \"./source/{name}/go/.\" \"$VORPAL_OUTPUT\"");
        let steps = vec![step::shell(context, vec![], vec![], step_script, vec![]).await?];
        let systems = vec![Aarch64Darwin, Aarch64Linux, X8664Darwin, X8664Linux];

        Artifact::new(name, steps, systems)
            .with_aliases(vec![format!("{name}:{source_version}")])
            .with_sources(vec![source])
            .build(context)
            .await
    }
}