// 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/d2d24c2211f00d6ccf89fbee63095ad2a81d0cc9af92d7a0ede9129e18d46e91"
    memory-limit "8GiB"
    cpu-limit 4
    // Tests serve and connect on 127.0.0.1; nothing leaves the guest.
    network "loopback"
}

sandbox "rust-small" {
    runtime "microvm"
    rootfs "cas://blob/d2d24c2211f00d6ccf89fbee63095ad2a81d0cc9af92d7a0ede9129e18d46e91"
    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"
}

job "clippy" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
<<<<<<< oxy conflict 1 of 2, side 1 of 2: change 6532b323 "oxygen and oxygenflow as pinned subrepos in deps/ (make pins moves them), and an OxygenFlow pipeline: fmt of this workspace, then clippy, tests and a release build against the pins"
    env {
        CARGO_INCREMENTAL "0"
    }
======= oxy conflict 1 of 2, side 2 of 2: change bce3997c "CI starts from the build image's prebuilt dependencies"
    exec "sh" ".flow/warm-target.sh" "cargo" "clippy" "--workspace" "--all-targets" "--locked" "--" "-D" "warnings"
>>>>>>> oxy conflict 1 of 2 end
}

job "test" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
<<<<<<< oxy conflict 2 of 2, side 1 of 2: change 6532b323 "oxygen and oxygenflow as pinned subrepos in deps/ (make pins moves them), and an OxygenFlow pipeline: fmt of this workspace, then clippy, tests and a release build against the pins"
    env {
        CARGO_INCREMENTAL "0"
    }
======= oxy conflict 2 of 2, side 2 of 2: change bce3997c "CI starts from the build image's prebuilt dependencies"
    exec "sh" ".flow/warm-target.sh" "cargo" "test" "--workspace" "--locked"
>>>>>>> oxy conflict 2 of 2 end
}

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

// Release files for every platform (oxygen#59): scripts/dist.sh in the
// build image's cross toolchains. A push runs it only when it touches
// these paths (a release moves Cargo.toml's version); "Run pipeline" and
// reruns always do. The files are kept as this run's artifacts, named by
// its signed receipt, and attached to the release from there, so the
// release's trust page shows each as built here.
job "dist" {
    sandbox "rust"
    depends-on "fmt"
    scope "Cargo.toml" "scripts/dist.sh" "packaging/**"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
    env {
        DIST_FLAT "/src/target/dist-flat"
        ZIG_GLOBAL_CACHE_DIR "/src/target/zig-cache"
    }
    exec "bash" "scripts/dist.sh"
    output {
        artifact "oh-linux-x86_64.tar.gz" {
            path "/src/target/dist-flat/oh-linux-x86_64.tar.gz"
        }
        artifact "oh-linux-arm64.tar.gz" {
            path "/src/target/dist-flat/oh-linux-arm64.tar.gz"
        }
        artifact "oh-linux-riscv64.tar.gz" {
            path "/src/target/dist-flat/oh-linux-riscv64.tar.gz"
        }
        artifact "oh-macos-x86_64.tar.gz" {
            path "/src/target/dist-flat/oh-macos-x86_64.tar.gz"
        }
        artifact "oh-macos-arm64.tar.gz" {
            path "/src/target/dist-flat/oh-macos-arm64.tar.gz"
        }
        artifact "oh-windows-x86_64.zip" {
            path "/src/target/dist-flat/oh-windows-x86_64.zip"
        }
        artifact "oh_amd64.deb" {
            path "/src/target/dist-flat/oh_amd64.deb"
        }
        artifact "oh_arm64.deb" {
            path "/src/target/dist-flat/oh_arm64.deb"
        }
        artifact "oh_riscv64.deb" {
            path "/src/target/dist-flat/oh_riscv64.deb"
        }
        artifact "oxygenhub-server-linux-x86_64.tar.gz" {
            path "/src/target/dist-flat/oxygenhub-server-linux-x86_64.tar.gz"
        }
        artifact "SHA256SUMS" {
            path "/src/target/dist-flat/SHA256SUMS"
        }
    }
}
