Log deployment data
All checks were successful
lint/clippy Checking for common mistakes and opportunities for code improvement
build/msvc Build for the target platform: msvc
build/linux Build for the target platform: linux
All checks were successful
lint/clippy Checking for common mistakes and opportunities for code improvement
build/msvc Build for the target platform: msvc
build/linux Build for the target platform: linux
Closes #168
This commit is contained in:
parent
1020efe53d
commit
a4e78f1c6b
2 changed files with 27 additions and 23 deletions
|
@ -12,6 +12,7 @@ local log = function(category, format, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
log("mod_main", "Initializing mods...")
|
log("mod_main", "Initializing mods...")
|
||||||
|
log("mod_main", "[DTMM] Deployment data:\n{{ deployment_info }}")
|
||||||
|
|
||||||
local require_store = {}
|
local require_store = {}
|
||||||
|
|
||||||
|
|
|
@ -453,7 +453,10 @@ async fn build_bundles(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn patch_boot_bundle(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
|
async fn patch_boot_bundle(
|
||||||
|
state: Arc<ActionState>,
|
||||||
|
deployment_info: &String,
|
||||||
|
) -> Result<Vec<Bundle>> {
|
||||||
let bundle_dir = Arc::new(state.game_dir.join("bundle"));
|
let bundle_dir = Arc::new(state.game_dir.join("bundle"));
|
||||||
let bundle_path = bundle_dir.join(format!("{:x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes())));
|
let bundle_path = bundle_dir.join(format!("{:x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes())));
|
||||||
|
|
||||||
|
@ -508,8 +511,9 @@ async fn patch_boot_bundle(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
|
||||||
.wrap_err("Failed to get template `mod_main.lua`")?;
|
.wrap_err("Failed to get template `mod_main.lua`")?;
|
||||||
|
|
||||||
let is_io_enabled = if state.is_io_enabled { "true" } else { "false" };
|
let is_io_enabled = if state.is_io_enabled { "true" } else { "false" };
|
||||||
|
let deployment_info = deployment_info.replace("\"", "\\\"").replace("\n", "\\n");
|
||||||
let lua = tmpl
|
let lua = tmpl
|
||||||
.render(minijinja::context!(is_io_enabled => is_io_enabled))
|
.render(minijinja::context!(is_io_enabled => is_io_enabled, deployment_info => deployment_info))
|
||||||
.wrap_err("Failed to render template `mod_main.lua`")?;
|
.wrap_err("Failed to render template `mod_main.lua`")?;
|
||||||
|
|
||||||
tracing::trace!("Main script rendered:\n===========\n{}\n=============", lua);
|
tracing::trace!("Main script rendered:\n===========\n{}\n=============", lua);
|
||||||
|
@ -574,14 +578,10 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(bundles = bundles.as_ref().len()))]
|
#[tracing::instrument(skip_all, fields(bundles = bundles.as_ref().len()))]
|
||||||
async fn write_deployment_data<B>(
|
fn build_deployment_data(
|
||||||
state: Arc<ActionState>,
|
bundles: impl AsRef<[Bundle]>,
|
||||||
bundles: B,
|
mod_folders: impl AsRef<[String]>,
|
||||||
mod_folders: Vec<String>,
|
) -> Result<String> {
|
||||||
) -> Result<()>
|
|
||||||
where
|
|
||||||
B: AsRef<[Bundle]>,
|
|
||||||
{
|
|
||||||
let info = DeploymentData {
|
let info = DeploymentData {
|
||||||
timestamp: OffsetDateTime::now_utc(),
|
timestamp: OffsetDateTime::now_utc(),
|
||||||
bundles: bundles
|
bundles: bundles
|
||||||
|
@ -590,16 +590,13 @@ where
|
||||||
.map(|bundle| format!("{:x}", bundle.name().to_murmur64()))
|
.map(|bundle| format!("{:x}", bundle.name().to_murmur64()))
|
||||||
.collect(),
|
.collect(),
|
||||||
// TODO:
|
// TODO:
|
||||||
mod_folders,
|
mod_folders: mod_folders
|
||||||
|
.as_ref()
|
||||||
|
.iter()
|
||||||
|
.map(|folder| folder.clone())
|
||||||
|
.collect(),
|
||||||
};
|
};
|
||||||
let path = state.game_dir.join(DEPLOYMENT_DATA_PATH);
|
serde_sjson::to_string(&info).wrap_err("Failed to serizalize deployment data")
|
||||||
let data = serde_sjson::to_string(&info).wrap_err("Failed to serizalie deployment data")?;
|
|
||||||
|
|
||||||
fs::write(&path, &data)
|
|
||||||
.await
|
|
||||||
.wrap_err_with(|| format!("Failed to write deployment data to '{}'", path.display()))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(
|
#[tracing::instrument(skip_all, fields(
|
||||||
|
@ -728,8 +725,11 @@ pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> {
|
||||||
.await
|
.await
|
||||||
.wrap_err("Failed to build mod bundles")?;
|
.wrap_err("Failed to build mod bundles")?;
|
||||||
|
|
||||||
|
let new_deployment_info = build_deployment_data(&bundles, &mod_folders)
|
||||||
|
.wrap_err("Failed to build new deployment data")?;
|
||||||
|
|
||||||
tracing::info!("Patch boot bundle");
|
tracing::info!("Patch boot bundle");
|
||||||
let mut boot_bundles = patch_boot_bundle(state.clone())
|
let mut boot_bundles = patch_boot_bundle(state.clone(), &new_deployment_info)
|
||||||
.await
|
.await
|
||||||
.wrap_err("Failed to patch boot bundle")?;
|
.wrap_err("Failed to patch boot bundle")?;
|
||||||
bundles.append(&mut boot_bundles);
|
bundles.append(&mut boot_bundles);
|
||||||
|
@ -804,9 +804,12 @@ pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> {
|
||||||
.wrap_err("Failed to patch bundle database")?;
|
.wrap_err("Failed to patch bundle database")?;
|
||||||
|
|
||||||
tracing::info!("Writing deployment data");
|
tracing::info!("Writing deployment data");
|
||||||
write_deployment_data(state.clone(), &bundles, mod_folders)
|
{
|
||||||
|
let path = state.game_dir.join(DEPLOYMENT_DATA_PATH);
|
||||||
|
fs::write(&path, &new_deployment_info)
|
||||||
.await
|
.await
|
||||||
.wrap_err("Failed to write deployment data")?;
|
.wrap_err_with(|| format!("Failed to write deployment data to '{}'", path.display()))?;
|
||||||
|
}
|
||||||
|
|
||||||
tracing::info!("Finished deploying mods");
|
tracing::info!("Finished deploying mods");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Reference in a new issue