vdev/commands/build/
publish_metadata.rs

1use anyhow::Result;
2use chrono::prelude::*;
3
4use crate::{app, utils::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        // Use `app::version()` so the emitted `vector_version` matches archive filenames
24        // (which include `.custom.<sha>` on custom-channel runs).
25        let version = app::version()?;
26
27        let git_sha = git::get_git_sha()?;
28        let current_date = Local::now().naive_local().to_string();
29        let build_desc = format!("{git_sha} {current_date}");
30
31        // Figure out what our release channel is.
32        let channel = git::get_channel();
33
34        let mut output_file: Box<dyn Write> = match env::var("GITHUB_OUTPUT") {
35            Ok(file_name) if !file_name.is_empty() => {
36                let file = OpenOptions::new()
37                    .append(true)
38                    .create(true)
39                    .open(file_name)?;
40                Box::new(file)
41            }
42            _ => Box::new(io::stdout()),
43        };
44        writeln!(output_file, "vector_version={version}")?;
45        writeln!(output_file, "vector_build_desc={build_desc}")?;
46        writeln!(output_file, "vector_release_channel={channel}")?;
47        Ok(())
48    }
49}