vdev/commands/build/
publish_metadata.rs

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