ci: update config

This commit is contained in:
Willem Vanhulle committed 2026-10-25 15:13:54 +01:00
1 parent dbe39fb2b4
commit a10e205e9b
5 files changed
+121 -7

No files matched your search

+6
View File
@@ -1,4 +1,5 @@
mod record_screencasts;
mod sync_default_config;
mod task_error;
use std::{path::PathBuf, process::ExitCode};
@@ -19,6 +20,10 @@ enum Task {
recordings/"
)]
RecordScreencasts(RecordScreencastsOptions),
#[command(
about = "Rewrite the defaults block in docs/configuration.md from `bootvine defaults`"
)]
SyncDefaultConfig,
}
#[derive(Args)]
@@ -32,6 +37,7 @@ fn main() -> ExitCode {
Task::RecordScreencasts(options) => {
record_screencasts::record_screencasts(&options.passphrase_png)
}
Task::SyncDefaultConfig => sync_default_config::sync_default_config(),
};
match outcome {
Ok(()) => ExitCode::SUCCESS,
+41
View File
@@ -0,0 +1,41 @@
use std::{fs, path::Path};
use xshell::{Shell, cmd};
use crate::task_error::TaskError;
const CONFIGURATION_DOC: &str = "docs/configuration.md";
const DEFAULTS_HEADING: &str = "## Defaults\n";
const TOML_FENCE_OPEN: &str = "```toml\n";
const FENCE_CLOSE: &str = "```\n";
pub fn sync_default_config() -> Result<(), TaskError> {
let doc_path = Path::new(CONFIGURATION_DOC);
let doc_file_error = |source| TaskError::File {
path: doc_path.to_path_buf(),
source,
};
let doc_text = fs::read_to_string(doc_path).map_err(doc_file_error)?;
let shell = Shell::new()?;
let printed_defaults =
cmd!(shell, "cargo run --quiet --package bootvine -- defaults").read()?;
let synced_text = replace_defaults_block(&doc_text, &printed_defaults)
.ok_or(TaskError::DefaultsBlockMissing(CONFIGURATION_DOC))?;
if synced_text != doc_text {
fs::write(doc_path, synced_text).map_err(doc_file_error)?;
}
Ok(())
}
fn replace_defaults_block(doc_text: &str, printed_defaults: &str) -> Option<String> {
let section_start = doc_text.find(DEFAULTS_HEADING)?;
let block_start =
section_start + doc_text[section_start..].find(TOML_FENCE_OPEN)? + TOML_FENCE_OPEN.len();
let block_end = block_start + doc_text[block_start..].find(FENCE_CLOSE)?;
Some(format!(
"{}{}\n{}",
&doc_text[..block_start],
printed_defaults.trim_end(),
&doc_text[block_end..]
))
}
+2
View File
@@ -10,4 +10,6 @@ pub enum TaskError {
File { path: PathBuf, source: io::Error },
#[error("no recordings directory here; run from the repository root")]
NotInRepositoryRoot,
#[error("{0} has no ```toml block under its Defaults heading")]
DefaultsBlockMissing(&'static str),
}