chore: Cleanup workflows to be run from just (#238)

This commit is contained in:
Gerald Pinder 2024-10-07 16:34:36 -04:00 committed by GitHub
parent 7c5578994e
commit 32092195d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 298 additions and 265 deletions

View file

@ -3,14 +3,17 @@ use std::{
path::{Path, PathBuf},
};
use blue_build_process_management::drivers::{types::Platform, CiDriver, Driver, DriverArgs};
use blue_build_process_management::drivers::{
opts::GetMetadataOpts, types::Platform, CiDriver, Driver, DriverArgs, InspectDriver,
};
use blue_build_recipe::Recipe;
use blue_build_template::{ContainerFileTemplate, Template};
use blue_build_utils::{
constants::{CONFIG_PATH, RECIPE_FILE, RECIPE_PATH},
constants::{BUILD_SCRIPTS_IMAGE_REF, CONFIG_PATH, RECIPE_FILE, RECIPE_PATH},
syntax_highlighting::{self, DefaultThemes},
};
use bon::Builder;
use cached::proc_macro::cached;
use clap::{crate_version, Args};
use log::{debug, info, trace, warn};
use miette::{IntoDiagnostic, Result};
@ -132,17 +135,7 @@ impl GenerateCommand {
.recipe_path(recipe_path.as_path())
.registry(registry)
.repo(Driver::get_repo_url()?)
.exports_tag({
#[allow(clippy::const_is_empty)]
if shadow::COMMIT_HASH.is_empty() {
// This is done for users who install via
// cargo. Cargo installs do not carry git
// information via shadow
format!("v{}", crate_version!())
} else {
shadow::COMMIT_HASH.to_string()
}
})
.build_scripts_image(determine_scripts_tag(self.platform)?)
.build();
let output_str = template.render().into_diagnostic()?;
@ -159,3 +152,31 @@ impl GenerateCommand {
Ok(())
}
}
#[cached(
result = true,
key = "Platform",
convert = r#"{ platform }"#,
sync_writes = true
)]
fn determine_scripts_tag(platform: Platform) -> Result<String> {
let version = format!("v{}", crate_version!());
let opts = GetMetadataOpts::builder()
.image(BUILD_SCRIPTS_IMAGE_REF)
.platform(platform);
Driver::get_metadata(&opts.clone().tag(shadow::COMMIT_HASH).build())
.inspect_err(|e| trace!("{e:?}"))
.map(|_| format!("{BUILD_SCRIPTS_IMAGE_REF}:{}", shadow::COMMIT_HASH))
.or_else(|_| {
Driver::get_metadata(&opts.clone().tag(shadow::BRANCH).build())
.inspect_err(|e| trace!("{e:?}"))
.map(|_| format!("{BUILD_SCRIPTS_IMAGE_REF}:{}", shadow::BRANCH))
})
.or_else(|_| {
Driver::get_metadata(&opts.tag(&version).build())
.inspect_err(|e| trace!("{e:?}"))
.map(|_| format!("{BUILD_SCRIPTS_IMAGE_REF}:{version}"))
})
.inspect(|image| debug!("Using build scripts image: {image}"))
}