Skip to content

Commit

Permalink
Let packages be parameterized by version
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpdp7 committed Oct 13, 2024
1 parent 6f97b47 commit f3fc957
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ fn repo_methods(builder: &mut MethodsBuilder) {
tag: last_version,
})
}

fn release(
#[starlark(this)] receiver: Value,
version: String,
) -> anyhow::Result<GitHubRelease> {
let repo = receiver.downcast_ref::<GitHubRepo>().unwrap();
Ok(GitHubRelease {
github_repo: repo.clone(),
tag: version,
})
}
}

#[starlark_value(type = "github_repo")]
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use ubpkg::{repo, runner};
#[derive(Parser)]
#[command()]
struct Args {
#[arg(short, long)]
version: Option<String>,
packages: Vec<String>,
}

Expand All @@ -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(())
}
8 changes: 7 additions & 1 deletion src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Result<(), ExecutionError> {
let ast: AstModule = AstModule::parse(&manifest.name, manifest.content, &Dialect::Extended)
.map_err(ExecutionError::ParsingError)?;

Expand All @@ -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);
Expand Down

0 comments on commit f3fc957

Please sign in to comment.