#!/usr/bin/env rust-script
use std::env;
use std::fs;
use std::process::exit;
#[path = "rust-paths.rs"]
mod rust_paths;
fn set_output(key: &str, value: &str) {
if let Ok(output_file) = env::var("GITHUB_OUTPUT") {
if let Err(e) = fs::OpenOptions::new()
.create(true)
.append(true)
.open(&output_file)
.and_then(|mut f| {
use std::io::Write;
writeln!(f, "{}={}", key, value)
})
{
eprintln!("Warning: Could not write to GITHUB_OUTPUT: {}", e);
}
}
println!("Output: {}={}", key, value);
}
fn main() {
let rust_root = match rust_paths::get_rust_root(None, true) {
Ok(root) => root,
Err(e) => {
eprintln!("Error: {}", e);
exit(1);
}
};
let cargo_toml = rust_paths::get_cargo_toml_path(&rust_root);
let package_manifest = match rust_paths::get_package_manifest_path(&cargo_toml) {
Ok(path) => path,
Err(e) => {
eprintln!("Error: {}", e);
exit(1);
}
};
match rust_paths::read_package_info(&package_manifest) {
Ok(info) => {
println!("Current version: {}", info.version);
set_output("version", &info.version);
}
Err(e) => {
eprintln!("Error: {}", e);
exit(1);
}
}
}