// OxygenHub's pipeline (OxygenFlow, docs in the oxygenflow repository).
// Every push to a bookmark on OxygenHub runs it in Firecracker microVMs on
// Earth; the jobs appear as checks on the change. oxygen and oxygenflow come
// from the pinned subrepos in deps/, which the runner puts in the workspace.
schema-version 1

// The OxygenFlow build image: Rust with rustfmt and clippy, Node, every
// crate of Cargo.lock vendored, and this workspace's dependencies prebuilt
// in /opt/warm/oxygenhub, which .flow/warm-target.sh copies onto a job's
// target disk (oxygenflow/images/rust). Rebuild and re-pin it when
// Cargo.lock changes; until then only the changed crates are compiled.
sandbox "rust" {
    runtime "microvm"
    rootfs "cas://blob/9d76e1aef3ab096c57dfdab6ed2cfb4de1dc70e67ca0e7f299e087f7abb7e61a"
    memory-limit "8GiB"
    cpu-limit 4
    // Tests serve and connect on 127.0.0.1; nothing leaves the guest.
    network "loopback"
    // CI builds are thrown away: no incremental state, and no debug info
    // (the release profile keeps line tables for the binary Earth runs,
    // which is built outside CI), so less to compile, link and write.
    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/9d76e1aef3ab096c57dfdab6ed2cfb4de1dc70e67ca0e7f299e087f7abb7e61a"
    memory-limit "1GiB"
    cpu-limit 1
    network "isolated"
}

job "fmt" {
    sandbox "rust-small"
    // Only this workspace's packages: --all would also check the path
    // dependencies in deps/, which follow their own formatting.
    exec "cargo" "fmt" "--check" "-p" "oxygenhub" "-p" "hub-api" "-p" "oh"
}

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

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

job "build" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
    exec "sh" ".flow/warm-target.sh" "cargo" "build" "--release" "--locked"
}
