Add repo deployment execution runbook
This commit is contained in:
parent
6a031c209e
commit
8074e6d1dd
6 changed files with 245 additions and 4 deletions
|
|
@ -211,6 +211,16 @@ fn run_smoke(args: Args) -> Result<Value> {
|
|||
&["deployment-config-audit", "--workspace", path_str(&repo)?],
|
||||
&root,
|
||||
)?;
|
||||
let runbook = cargo_json(
|
||||
&manifest,
|
||||
"epiphany-work",
|
||||
&[
|
||||
"deployment-execution-runbook",
|
||||
"--workspace",
|
||||
path_str(&repo)?,
|
||||
],
|
||||
&root,
|
||||
)?;
|
||||
|
||||
require_eq(
|
||||
&plan,
|
||||
|
|
@ -299,6 +309,40 @@ fn run_smoke(args: Args) -> Result<Value> {
|
|||
require_bool(&audit, &["mergeAuthorized"], false)?;
|
||||
require_bool(&audit, &["daemonOwnsExecution"], true)?;
|
||||
require_bool(&audit, &["privateStateExposed"], false)?;
|
||||
require_eq(
|
||||
&runbook,
|
||||
&["schemaVersion"],
|
||||
"epiphany.repo_deployment_execution_runbook.v0",
|
||||
)?;
|
||||
require_eq(&runbook, &["status"], "ready-for-operator-git-push")?;
|
||||
require_bool(&runbook, &["runbookWritten"], true)?;
|
||||
require_bool(&runbook, &["requiresExplicitOperatorAuthority"], true)?;
|
||||
require_bool(&runbook, &["mutatesRemoteWhenRun"], true)?;
|
||||
require_bool(&runbook, &["executionAuthorized"], false)?;
|
||||
require_bool(&runbook, &["deploymentAuthority"], false)?;
|
||||
require_bool(&runbook, &["sshAuthority"], false)?;
|
||||
require_bool(&runbook, &["gitPushAuthority"], false)?;
|
||||
require_bool(&runbook, &["serviceLifecycleAuthority"], false)?;
|
||||
require_bool(&runbook, &["handsAuthority"], false)?;
|
||||
require_bool(&runbook, &["publicationAuthorized"], false)?;
|
||||
require_bool(&runbook, &["mergeAuthorized"], false)?;
|
||||
require_bool(&runbook, &["daemonOwnsExecution"], true)?;
|
||||
require_bool(&runbook, &["privateStateExposed"], false)?;
|
||||
require_eq(&runbook, &["watchedRef"], "refs/heads/main")?;
|
||||
let runbook_path = value_at_path(&runbook, &["runbookPath"])
|
||||
.and_then(Value::as_str)
|
||||
.ok_or_else(|| anyhow!("missing runbook path"))?;
|
||||
let runbook_text = fs::read_to_string(runbook_path)
|
||||
.with_context(|| format!("failed to read runbook {runbook_path}"))?;
|
||||
require_text(
|
||||
&runbook_text,
|
||||
"schema_version = \"epiphany.repo_deployment_execution_runbook.v0\"",
|
||||
)?;
|
||||
require_text(&runbook_text, "git push $Remote HEAD:refs/heads/main")?;
|
||||
require_text(
|
||||
&runbook_text,
|
||||
"gamecult.idunn.deployment_aftercare_audit.v0",
|
||||
)?;
|
||||
|
||||
let summary = json!({
|
||||
"schemaVersion": "epiphany.repo_deployment_config_family_smoke.v0",
|
||||
|
|
@ -317,6 +361,11 @@ fn run_smoke(args: Args) -> Result<Value> {
|
|||
"deploymentConfigAuditStatus": audit["status"],
|
||||
"deploymentConfigAuditReceiptPath": audit["receiptPath"],
|
||||
"readyForIdunnReview": audit["readyForIdunnReview"],
|
||||
"deploymentExecutionRunbookStatus": runbook["status"],
|
||||
"deploymentExecutionRunbookPath": runbook["runbookPath"],
|
||||
"deploymentExecutionRunbookSha256": runbook["runbookSha256"],
|
||||
"requiresExplicitOperatorAuthority": runbook["requiresExplicitOperatorAuthority"],
|
||||
"mutatesRemoteWhenRun": runbook["mutatesRemoteWhenRun"],
|
||||
"deploymentTrigger": "git-push-observed-by-idunn",
|
||||
"deploymentOwner": "Idunn",
|
||||
"daemonOwnsExecution": true,
|
||||
|
|
|
|||
|
|
@ -123,6 +123,9 @@ fn main() -> Result<()> {
|
|||
"deployment-config-audit" | "audit-deployment-config" | "idunn-deployment-audit" => {
|
||||
run_deployment_config_audit(parse_deployment_config_audit_args(args)?)
|
||||
}
|
||||
"deployment-execution-runbook" | "idunn-deployment-runbook" | "deployment-push-runbook" => {
|
||||
run_deployment_execution_runbook(parse_deployment_execution_runbook_args(args)?)
|
||||
}
|
||||
"export-proof" | "public-proof" => run_export_proof(parse_export_proof_args(args)?),
|
||||
"tick" | "pulse" | "schedule" => run_tick(parse_tick_args(args)?),
|
||||
"queue-run" | "run-queue" | "queue-tick" | "scheduler-run" => {
|
||||
|
|
@ -330,6 +333,14 @@ struct DeploymentConfigAuditArgs {
|
|||
write_receipt: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct DeploymentExecutionRunbookArgs {
|
||||
workspace: PathBuf,
|
||||
artifact_dir: Option<PathBuf>,
|
||||
remote: String,
|
||||
write_receipt: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct ExportProofArgs {
|
||||
workspace: PathBuf,
|
||||
|
|
@ -1125,6 +1136,36 @@ fn parse_deployment_config_audit_args(
|
|||
})
|
||||
}
|
||||
|
||||
fn parse_deployment_execution_runbook_args(
|
||||
args: impl Iterator<Item = String>,
|
||||
) -> Result<DeploymentExecutionRunbookArgs> {
|
||||
let mut workspace = None;
|
||||
let mut artifact_dir = None;
|
||||
let mut remote = "origin".to_string();
|
||||
let mut write_receipt = true;
|
||||
|
||||
let mut args = args.peekable();
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--workspace" => workspace = Some(take_path(&mut args, "--workspace")?),
|
||||
"--artifact-dir" => artifact_dir = Some(take_path(&mut args, "--artifact-dir")?),
|
||||
"--remote" => remote = take_string(&mut args, "--remote")?,
|
||||
"--no-write" | "--read-only" => write_receipt = false,
|
||||
other => {
|
||||
return Err(anyhow!(
|
||||
"unexpected deployment-execution-runbook argument {other:?}"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(DeploymentExecutionRunbookArgs {
|
||||
workspace: workspace.context("missing --workspace")?,
|
||||
artifact_dir,
|
||||
remote,
|
||||
write_receipt,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_export_proof_args(args: impl Iterator<Item = String>) -> Result<ExportProofArgs> {
|
||||
let mut workspace = None;
|
||||
let mut item = None;
|
||||
|
|
@ -10405,6 +10446,128 @@ fn run_deployment_config_audit(args: DeploymentConfigAuditArgs) -> Result<Value>
|
|||
Ok(receipt)
|
||||
}
|
||||
|
||||
fn run_deployment_execution_runbook(args: DeploymentExecutionRunbookArgs) -> Result<Value> {
|
||||
let workspace = args
|
||||
.workspace
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to resolve {}", args.workspace.display()))?;
|
||||
ensure_git_repo(&workspace)?;
|
||||
let artifact_dir = args
|
||||
.artifact_dir
|
||||
.unwrap_or_else(|| workspace.join(".epiphany").join("work"));
|
||||
fs::create_dir_all(&artifact_dir)
|
||||
.with_context(|| format!("failed to create {}", artifact_dir.display()))?;
|
||||
|
||||
let config_path = workspace.join(".epiphany").join("deployment.toml");
|
||||
let config_text = if config_path.exists() {
|
||||
fs::read_to_string(&config_path)
|
||||
.with_context(|| format!("failed to read {}", config_path.display()))?
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
let watched_ref = deployment_config_string_value(&config_text, "watched_ref")
|
||||
.unwrap_or_else(|| "refs/heads/main".to_string());
|
||||
let deployment_script_ref =
|
||||
deployment_config_string_value(&config_text, "deployment_script_ref")
|
||||
.unwrap_or_else(|| "deploy/idunn-deploy.ps1".to_string());
|
||||
let current_branch = git_output(&workspace, &["rev-parse", "--abbrev-ref", "HEAD"])?;
|
||||
let current_commit = git_output(&workspace, &["rev-parse", "HEAD"])?;
|
||||
let generated_at = Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true);
|
||||
let receipt_path = artifact_dir.join("deployment-execution-runbook.json");
|
||||
let runbook_dir = artifact_dir.join("idunn-deployment");
|
||||
let runbook_path = runbook_dir.join("idunn-git-push-runbook.ps1");
|
||||
let audit = run_deployment_config_audit(DeploymentConfigAuditArgs {
|
||||
workspace: workspace.clone(),
|
||||
artifact_dir: Some(artifact_dir.clone()),
|
||||
write_receipt: args.write_receipt,
|
||||
})?;
|
||||
let ready_for_idunn = audit.get("readyForIdunnReview").and_then(Value::as_bool) == Some(true);
|
||||
let push_command = format!("git push {} HEAD:{watched_ref}", args.remote);
|
||||
let operator_execution_command = format!(
|
||||
"powershell -ExecutionPolicy Bypass -File {} -Remote {}",
|
||||
powershell_single_quoted(&runbook_path.display().to_string()),
|
||||
powershell_single_quoted(&args.remote)
|
||||
);
|
||||
let mut runbook_written = false;
|
||||
let mut runbook_sha256 = Value::Null;
|
||||
|
||||
if ready_for_idunn && args.write_receipt {
|
||||
fs::create_dir_all(&runbook_dir)
|
||||
.with_context(|| format!("failed to create {}", runbook_dir.display()))?;
|
||||
let runbook = [
|
||||
"# schema_version = \"epiphany.repo_deployment_execution_runbook.v0\"".to_string(),
|
||||
"# owner = \"Idunn\"".to_string(),
|
||||
"# authority = \"explicit-operator-git-push\"".to_string(),
|
||||
"# generated_by = \"epiphany-work deployment-execution-runbook\"".to_string(),
|
||||
"param([string]$Remote = 'origin')".to_string(),
|
||||
"$ErrorActionPreference = 'Stop'".to_string(),
|
||||
format!("Set-Location -LiteralPath {}", powershell_single_quoted(&workspace.display().to_string())),
|
||||
"Write-Host 'Epiphany Idunn deployment handoff: operator-owned git push.'".to_string(),
|
||||
"Write-Host 'This runbook mutates the remote ref; run only with explicit operator authority.'".to_string(),
|
||||
"git status --short".to_string(),
|
||||
format!("git push $Remote HEAD:{watched_ref}"),
|
||||
"Write-Host 'Aftercare: wait for Idunn deployment receipt and aftercare audit on CultMesh.'".to_string(),
|
||||
"Write-Host 'Required receipts: gamecult.idunn.deployment_receipt.v0 and gamecult.idunn.deployment_aftercare_audit.v0.'".to_string(),
|
||||
]
|
||||
.join("\n");
|
||||
fs::write(&runbook_path, runbook)
|
||||
.with_context(|| format!("failed to write {}", runbook_path.display()))?;
|
||||
runbook_written = true;
|
||||
runbook_sha256 = json!(file_sha256(&runbook_path)?);
|
||||
}
|
||||
|
||||
let status = if ready_for_idunn {
|
||||
"ready-for-operator-git-push"
|
||||
} else {
|
||||
"blocked-config-not-ready"
|
||||
};
|
||||
let receipt = json!({
|
||||
"schemaVersion": "epiphany.repo_deployment_execution_runbook.v0",
|
||||
"runbookId": "repo-idunn-git-push-runbook",
|
||||
"generatedAt": generated_at,
|
||||
"status": status,
|
||||
"workspace": workspace,
|
||||
"configPath": config_path,
|
||||
"configAudit": audit,
|
||||
"receiptPath": receipt_path,
|
||||
"runbookPath": if runbook_written { json!(runbook_path) } else { Value::Null },
|
||||
"runbookSha256": runbook_sha256,
|
||||
"runbookWritten": runbook_written,
|
||||
"operatorExecutionCommand": if runbook_written {
|
||||
json!(operator_execution_command)
|
||||
} else {
|
||||
Value::Null
|
||||
},
|
||||
"gitPushCommand": push_command,
|
||||
"remote": args.remote,
|
||||
"watchedRef": watched_ref,
|
||||
"currentBranch": current_branch,
|
||||
"currentCommit": current_commit,
|
||||
"deploymentScriptRef": deployment_script_ref,
|
||||
"requiredIdunnReceipts": [
|
||||
"gamecult.idunn.deployment_receipt.v0",
|
||||
"gamecult.idunn.deployment_aftercare_audit.v0"
|
||||
],
|
||||
"requiresExplicitOperatorAuthority": true,
|
||||
"mutatesRemoteWhenRun": true,
|
||||
"executionAuthorized": false,
|
||||
"deploymentAuthority": false,
|
||||
"sshAuthority": false,
|
||||
"gitPushAuthority": false,
|
||||
"serviceLifecycleAuthority": false,
|
||||
"handsAuthority": false,
|
||||
"publicationAuthorized": false,
|
||||
"mergeAuthorized": false,
|
||||
"crossBodyMutationAuthorized": false,
|
||||
"daemonOwnsExecution": true,
|
||||
"privateStateExposed": false
|
||||
});
|
||||
if args.write_receipt {
|
||||
write_json(&receipt_path, &receipt)?;
|
||||
}
|
||||
Ok(receipt)
|
||||
}
|
||||
|
||||
fn run_export_proof(args: ExportProofArgs) -> Result<Value> {
|
||||
let workspace = args
|
||||
.workspace
|
||||
|
|
@ -12449,6 +12612,18 @@ fn compact_text(text: &str, limit: usize) -> String {
|
|||
truncated
|
||||
}
|
||||
|
||||
fn deployment_config_string_value(text: &str, key: &str) -> Option<String> {
|
||||
let prefix = format!("{key} = ");
|
||||
for line in text.lines() {
|
||||
let trimmed = line.trim();
|
||||
if let Some(value) = trimmed.strip_prefix(&prefix) {
|
||||
let value = value.strip_prefix('"')?.strip_suffix('"')?;
|
||||
return Some(value.to_string());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn read_json(path: &Path) -> Result<Value> {
|
||||
let raw =
|
||||
fs::read_to_string(path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
|
|
@ -12549,7 +12724,7 @@ fn sanitize(value: &str) -> String {
|
|||
|
||||
fn print_usage() {
|
||||
eprintln!(
|
||||
"usage: epiphany-work <persona-intake|accept|derive-plan|plan|run|adopt|execute|close|publish|sync|overview|deployment-config-audit|export-proof|tick|queue-run|serve> ...\n\
|
||||
"usage: epiphany-work <persona-intake|accept|derive-plan|plan|run|adopt|execute|close|publish|sync|overview|deployment-config-audit|deployment-execution-runbook|export-proof|tick|queue-run|serve> ...\n\
|
||||
persona-intake --workspace <repo> --item <id> --message <text> [--topic <topic>] [--store <local-verse.ccmp>] [--runtime-id <id>]\n\
|
||||
accept --workspace <repo> --from <persona|bifrost|persona-or-bifrost> --item <id> [--summary <text>] [--topic <topic>] [--store <local-verse.ccmp>] [--runtime-id <id>] [--online-receipt <path>] [--public-discussion-ref <ref>] [--candidate-action-ref <ref>]\n\
|
||||
derive-plan --workspace <repo> [--item <id>] [--accept-receipt <path>] [--action-family append-worklog|planning-note|checklist-note|section-note|repo-status-section|task-card|repo-manifest|repo-tool-capabilities|repo-tool-request|repo-eve-surface|repo-collaboration-policy|repo-collaboration-topic|repo-consensus-brief|repo-objective-draft|repo-adoption-request|repo-scheduling-request|repo-work-order|repo-verification-request|repo-publication-request|repo-sync-request|repo-maintainer-review-request|repo-pr-request|repo-credit-request|repo-artifact-acceptance-request|repo-metrics-request|repo-doctrine-update-request|repo-secret-policy-request|repo-deployment-config|repo-deployment-request] [--target-path <path>] [--model-ref <ref>] [--model-authored] [--action-summary <text>] [--verification-ask <text>] [--stop-condition <text>] [--escalation-reason <text>] [--assumption <text>] [--constraint <text>] [--non-goal <text>] [--open-question <text>] [--decision-point <text>] [--evidence-need <text>]\n\
|
||||
|
|
@ -12562,6 +12737,7 @@ fn print_usage() {
|
|||
sync --workspace <repo> [--item <id>] [--publish-receipt <path>] [--upstream-ref origin/main] --merge-receipt <ref>\n\
|
||||
overview --workspace <repo> [--item <id>] [--accept-receipt <path>] [--no-write]\n\
|
||||
deployment-config-audit --workspace <repo> [--artifact-dir <path>] [--no-write]\n\
|
||||
deployment-execution-runbook --workspace <repo> [--artifact-dir <path>] [--remote origin] [--no-write]\n\
|
||||
export-proof --workspace <repo> [--item <id>] [--accept-receipt <path>] [--output <path>] [--local-verse-store <path>] [--runtime-id repo-swarm-local]\n\
|
||||
tick --workspace <repo> [--item <id>] [--local-verse-store <path>] [--runtime-store <path>] [--dry-run]\n\
|
||||
queue-run --workspace <repo> [--local-verse-store <path>] [--runtime-id repo-swarm-local] [--max-items 1] [--dry-run]"
|
||||
|
|
|
|||
Reference in a new issue