vdev/commands/build/
publish_metadata.rs

1use anyhow::Result;
2use chrono::prelude::*;
3
4use crate::utils::{cargo, git};
5use std::{
6    env,
7    fs::OpenOptions,
8    io::{self, Write},
9};
10
11/// Setting necessary metadata for our publish workflow in CI.
12///
13/// Responsible for setting necessary metadata for our publish workflow in CI. Computes the Vector
14/// version (from Cargo.toml), the release channel (nightly vs release), and more. All of this
15/// information is emitted in a way that sets native outputs on the GitHub Actions workflow step
16/// running the script, which can be passed on to subsequent jobs/steps.
17#[derive(clap::Args, Debug)]
18#[command()]
19pub struct Cli {}
20
21impl Cli {
22    pub fn exec(self) -> Result<()> {
23        // Generate the Vector version and build description.
24        let version = cargo::get_version()?;
25
26        let git_sha = git::get_git_sha()?;
27        let current_date = Local::now().naive_local().to_string();
28        let build_desc = format!("{git_sha} {current_date}");
29
30        // Figure out what our release channel is.
31        let channel = git::get_channel();
32
33        let mut output_file: Box<dyn Write> = match env::var("GITHUB_OUTPUT") {
34            Ok(file_name) if !file_name.is_empty() => {
35                let file = OpenOptions::new()
36                    .append(true)
37                    .create(true)
38                    .open(file_name)?;
39                Box::new(file)
40            }
41            _ => Box::new(io::stdout()),
42        };
43        writeln!(output_file, "vector_version={version}")?;
44        writeln!(output_file, "vector_build_desc={build_desc}")?;
45        writeln!(output_file, "vector_release_channel={channel}")?;
46        Ok(())
47    }
48}