// oxygen-vscode's pipeline (OxygenFlow, docs in the oxygenflow repository):
// typecheck, bundle, tests against a real oxy, and packaging, offline in a
// Firecracker microVM on Earth for every push.
schema-version 1

// The OxygenFlow build image (oxygenflow/images/rust): Node, Rust, an npm
// cache of this repository's package-lock.json, and the crates oxy needs.
// Rebuild and re-pin it when package-lock.json changes.
sandbox "node" {
    runtime "microvm"
    rootfs "cas://blob/836461b613019f62399a960c61a25c482eb74e30054ff2cd44d5594c3305872b"
    memory-limit "6GiB"
    cpu-limit 4
    network "loopback"
}

// The tests drive the real oxy, built here from the pinned oxygen in deps/.
job "check" {
    sandbox "node"
    mount {
        source "ephemeral://disk"
        target "/src/deps/oxygen/target"
        size "16GiB"
    }
    env {
        CARGO_INCREMENTAL "0"
    }
    exec "sh" "-euc" "cargo build --locked --manifest-path deps/oxygen/Cargo.toml -p oxy && npm ci --offline --cache /opt/npm-cache --no-audit --no-fund && npm run typecheck && npm run build && OXY_BIN=/src/deps/oxygen/target/debug/oxy npm run test:ci"
    // A JUnit report (kept whether or not the tests pass) and line coverage
    // of src/ through esbuild's source maps, for the hub's Tests and
    // Coverage tabs.
    output {
        artifact "junit" {
            path "/src/out/junit.xml"
            when "always"
        }
        artifact "coverage" {
            path "/src/out/lcov.info"
        }
    }
}

job "package" {
    sandbox "node"
    depends-on "check"
    // A fresh workspace: nothing from check carries over, so build first.
    exec "sh" "-euc" "npm ci --offline --cache /opt/npm-cache --no-audit --no-fund && npm run build && npm run package"
}
