// OxygenFlow's own pipeline (docs/m0.md). Runs in Firecracker microVMs on
// Earth for every push to a bookmark; see the Flow tab on OxygenHub.
schema-version 1

sandbox "alpine" {
    runtime "microvm"
    // Alpine 3.24.2 minirootfs, imported on Earth with `flow rootfs import`.
    rootfs "cas://blob/e95d22fb2380b67193f2640a12c2f8c7bae485f6fd14330bdb0c7157faa588dc"
    memory-limit "256MiB"
    cpu-limit 1
    network "isolated"
}

job "layout" {
    sandbox "alpine"
    exec "sh" "-eu" ".flow/jobs/layout.sh"
}

job "todos" {
    sandbox "alpine"
    scope "crates/**"
    exec "sh" "-eu" ".flow/jobs/todos.sh"
}

job "size" {
    sandbox "alpine"
    scope "crates/**"
    exec "sh" "-eu" ".flow/jobs/size.sh"
}

job "isolation" {
    sandbox "alpine"
    exec "sh" "-eu" ".flow/jobs/isolation.sh"
}

// The build image (images/rust): Rust with rustfmt and clippy, Node, and the
// vendored crates. oxygen comes from the pinned subrepo in deps/.
sandbox "rust" {
    runtime "microvm"
    rootfs "cas://blob/3ba0779a55b1d66fce10adf5a01585624c9aab089f590d228368c38fd3e65a46"
    memory-limit "8GiB"
    cpu-limit 4
    network "loopback"
    // CI builds are thrown away: no incremental state and no debug info,
    // so less to compile, link and write (as in oxygenhub's pipeline).
    env {
        CARGO_INCREMENTAL "0"
        CARGO_PROFILE_DEV_DEBUG "0"
        CARGO_PROFILE_TEST_DEBUG "0"
        CARGO_PROFILE_RELEASE_DEBUG "0"
    }
}

sandbox "rust-small" {
    runtime "microvm"
    rootfs "cas://blob/3ba0779a55b1d66fce10adf5a01585624c9aab089f590d228368c38fd3e65a46"
    memory-limit "1GiB"
    cpu-limit 1
    network "isolated"
}

job "fmt" {
    sandbox "rust-small"
    // This workspace only: --all would reach the pinned oxygen in deps/.
    exec "cargo" "fmt" "--check" "-p" "flow" "-p" "flow-core" "-p" "flow-init"
}

job "clippy" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "16GiB"
    }
    exec "cargo" "clippy" "--workspace" "--all-targets" "--locked" "--" "-D" "warnings"
}

job "test" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "16GiB"
    }
    exec "cargo" "test" "--workspace" "--locked"
}

job "summary" {
    sandbox "alpine"
    depends-on "layout" "todos" "size" "isolation" "clippy" "test"
    env {
        PROJECT "OxygenFlow"
    }
    exec "sh" "-eu" ".flow/jobs/summary.sh"
}
