# self-deploy: the recursive demo.
#
# A workflow that compiles its own binary, runs the trivial smoke
# workflow against the freshly-built binary, and reports the result.
# Stays in TOML — no out-of-band scripts.
#
# Run from the repo root:
#   r8r run examples/self-deploy.toml
#
# What this proves: the binary that's executing this workflow can
# rebuild itself from source and verify the rebuilt artifact, all
# expressed as nodes. The whole pipeline is the artifact.

[workflow]
name = "self-deploy"
version = 1

[[nodes]]
name = "Build"
type = "execute_command"
[nodes.parameters]
program = "cargo"
args = ["build", "--release", "--bin", "r8r"]

[[nodes]]
name = "BuildOk"
type = "if"
[nodes.parameters]
left = "{{ $json.success }}"
right = true
op = "eq"

[[nodes]]
name = "Smoke"
type = "execute_command"
[nodes.parameters]
program = "./target/release/r8r"
args = ["run", "examples/trivial.toml"]

[[nodes]]
name = "SmokeOk"
type = "if"
[nodes.parameters]
left = "{{ $json.success }}"
right = true
op = "eq"

[[nodes]]
name = "Report"
type = "set"
[nodes.parameters]
fields = { status = "self-deploy: PASS", build_stdout = "{{ $node.Build.json.stdout }}", smoke_stdout = "{{ $node.Smoke.json.stdout }}" }

[[nodes]]
name = "BuildFail"
type = "stop_and_error"
[nodes.parameters]
message = "self-deploy: cargo build failed"

[[nodes]]
name = "SmokeFail"
type = "stop_and_error"
[nodes.parameters]
message = "self-deploy: smoke workflow failed against rebuilt binary"

[[edges]]
from = "Build"
to = "BuildOk"

[[edges]]
from = "BuildOk"
to = "Smoke"
from_index = 0

[[edges]]
from = "BuildOk"
to = "BuildFail"
from_index = 1

[[edges]]
from = "Smoke"
to = "SmokeOk"

[[edges]]
from = "SmokeOk"
to = "Report"
from_index = 0

[[edges]]
from = "SmokeOk"
to = "SmokeFail"
from_index = 1
