From f3fc95720bb5802306bb9fcdb9321347882b5168 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 13 Oct 2024 12:21:46 +0200 Subject: [PATCH] Let packages be parameterized by version --- src/github.rs | 11 +++++++++++ src/main.rs | 4 +++- src/runner.rs | 8 +++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/github.rs b/src/github.rs index 3fc0f0f..799d804 100644 --- a/src/github.rs +++ b/src/github.rs @@ -41,6 +41,17 @@ fn repo_methods(builder: &mut MethodsBuilder) { tag: last_version, }) } + + fn release( + #[starlark(this)] receiver: Value, + version: String, + ) -> anyhow::Result { + let repo = receiver.downcast_ref::().unwrap(); + Ok(GitHubRelease { + github_repo: repo.clone(), + tag: version, + }) + } } #[starlark_value(type = "github_repo")] diff --git a/src/main.rs b/src/main.rs index 9f60a65..39d6848 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,8 @@ use ubpkg::{repo, runner}; #[derive(Parser)] #[command()] struct Args { + #[arg(short, long)] + version: Option, packages: Vec, } @@ -14,7 +16,7 @@ fn main() -> Result<()> { let args = Args::parse(); for package in &args.packages { let manifest = repo::load_manifest_from_repo(package)?; - runner::run_manifest(manifest)?; + runner::run_manifest(manifest, args.version.clone())?; } Ok(()) } diff --git a/src/runner.rs b/src/runner.rs index 5a25eea..a287af8 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -18,7 +18,7 @@ pub enum ExecutionError { RuntimeError(starlark::Error), } -pub fn run_manifest(manifest: Manifest) -> Result<(), ExecutionError> { +pub fn run_manifest(manifest: Manifest, version: Option) -> Result<(), ExecutionError> { let ast: AstModule = AstModule::parse(&manifest.name, manifest.content, &Dialect::Extended) .map_err(ExecutionError::ParsingError)?; @@ -28,6 +28,12 @@ pub fn run_manifest(manifest: Manifest) -> Result<(), ExecutionError> { .with(git::git); globals.set("os", std::env::consts::OS); globals.set("arch", std::env::consts::ARCH); + globals.set( + "version", + version.map_or(starlark::values::none::NoneOr::None, |version| { + starlark::values::none::NoneOr::Other(version) + }), + ); let globals = globals.build(); let module: Module = Module::new(); let mut eval: Evaluator = Evaluator::new(&module);